Skip to content

Commit

Permalink
fix: better support header parameters (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-ci-bot committed Feb 28, 2025
1 parent dfae756 commit ea3f187
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 49 deletions.
8 changes: 4 additions & 4 deletions lib/modern_treasury/base_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def follow_redirect(request, status:, response_headers:)
# @param max_retries [Integer]
# @param initial_retry_delay [Float]
# @param max_retry_delay [Float]
# @param headers [Hash{String=>String, nil}]
# @param headers [Hash{String=>String, Integer, Array<String, Integer, nil>, nil}]
# @param idempotency_header [String, nil]
#
def initialize(
Expand Down Expand Up @@ -193,7 +193,7 @@ def initialize(
#
# @option req [Hash{String=>Array<String>, String, nil}, nil] :query
#
# @option req [Hash{String=>String, nil}, nil] :headers
# @option req [Hash{String=>String, Integer, Array<String, Integer, nil>, nil}, nil] :headers
#
# @option req [Object, nil] :body
#
Expand Down Expand Up @@ -399,7 +399,7 @@ def initialize(
#
# @option req [Hash{String=>Array<String>, String, nil}, nil] :query
#
# @option req [Hash{String=>String, nil}, nil] :headers
# @option req [Hash{String=>String, Integer, Array<String, Integer, nil>, nil}, nil] :headers
#
# @option req [Object, nil] :body
#
Expand Down Expand Up @@ -442,7 +442,7 @@ def initialize(
#
# @option req [Hash{String=>Array<String>, String, nil}, nil] :query
#
# @option req [Hash{String=>String, nil}, nil] :headers
# @option req [Hash{String=>String, Integer, Array<String, Integer, nil>, nil}, nil] :headers
#
# @option req [Object, nil] :body
#
Expand Down
16 changes: 8 additions & 8 deletions lib/modern_treasury/resources/account_details.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ class AccountDetails
#
def create(account_id, params)
parsed, options = ModernTreasury::Models::AccountDetailCreateParams.dump_request(params)
accounts_type = parsed.fetch(:accounts_type) do
accounts_type = parsed.delete(:accounts_type) do
raise ArgumentError.new("missing required path argument #{_1}")
end
@client.request(
method: :post,
path: ["api/%0s/%1s/account_details", accounts_type, account_id],
body: parsed.except(:accounts_type),
body: parsed,
model: ModernTreasury::Models::AccountDetail,
options: options
)
Expand All @@ -50,10 +50,10 @@ def create(account_id, params)
#
def retrieve(id, params)
parsed, options = ModernTreasury::Models::AccountDetailRetrieveParams.dump_request(params)
accounts_type = parsed.fetch(:accounts_type) do
accounts_type = parsed.delete(:accounts_type) do
raise ArgumentError.new("missing required path argument #{_1}")
end
account_id = parsed.fetch(:account_id) do
account_id = parsed.delete(:account_id) do
raise ArgumentError.new("missing required path argument #{_1}")
end
@client.request(
Expand Down Expand Up @@ -82,13 +82,13 @@ def retrieve(id, params)
#
def list(account_id, params)
parsed, options = ModernTreasury::Models::AccountDetailListParams.dump_request(params)
accounts_type = parsed.fetch(:accounts_type) do
accounts_type = parsed.delete(:accounts_type) do
raise ArgumentError.new("missing required path argument #{_1}")
end
@client.request(
method: :get,
path: ["api/%0s/%1s/account_details", accounts_type, account_id],
query: parsed.except(:accounts_type),
query: parsed,
page: ModernTreasury::Page,
model: ModernTreasury::Models::AccountDetail,
options: options
Expand All @@ -111,10 +111,10 @@ def list(account_id, params)
#
def delete(id, params)
parsed, options = ModernTreasury::Models::AccountDetailDeleteParams.dump_request(params)
accounts_type = parsed.fetch(:accounts_type) do
accounts_type = parsed.delete(:accounts_type) do
raise ArgumentError.new("missing required path argument #{_1}")
end
account_id = parsed.fetch(:account_id) do
account_id = parsed.delete(:account_id) do
raise ArgumentError.new("missing required path argument #{_1}")
end
@client.request(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def create(internal_account_id, params)
#
def retrieve(id, params)
parsed, options = ModernTreasury::Models::InternalAccounts::BalanceReportRetrieveParams.dump_request(params)
internal_account_id = parsed.fetch(:internal_account_id) do
internal_account_id = parsed.delete(:internal_account_id) do
raise ArgumentError.new("missing required path argument #{_1}")
end
@client.request(
Expand Down Expand Up @@ -106,7 +106,7 @@ def list(internal_account_id, params = {})
#
def delete(id, params)
parsed, options = ModernTreasury::Models::InternalAccounts::BalanceReportDeleteParams.dump_request(params)
internal_account_id = parsed.fetch(:internal_account_id) do
internal_account_id = parsed.delete(:internal_account_id) do
raise ArgumentError.new("missing required path argument #{_1}")
end
@client.request(
Expand Down
2 changes: 1 addition & 1 deletion lib/modern_treasury/resources/invoices.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def list(params = {})
#
def add_payment_order(payment_order_id, params)
parsed, options = ModernTreasury::Models::InvoiceAddPaymentOrderParams.dump_request(params)
id = parsed.fetch(:id) do
id = parsed.delete(:id) do
raise ArgumentError.new("missing required path argument #{_1}")
end
@client.request(
Expand Down
8 changes: 4 additions & 4 deletions lib/modern_treasury/resources/invoices/line_items.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def create(invoice_id, params)
#
def retrieve(id, params)
parsed, options = ModernTreasury::Models::Invoices::LineItemRetrieveParams.dump_request(params)
invoice_id = parsed.fetch(:invoice_id) do
invoice_id = parsed.delete(:invoice_id) do
raise ArgumentError.new("missing required path argument #{_1}")
end
@client.request(
Expand Down Expand Up @@ -106,13 +106,13 @@ def retrieve(id, params)
#
def update(id, params)
parsed, options = ModernTreasury::Models::Invoices::LineItemUpdateParams.dump_request(params)
invoice_id = parsed.fetch(:invoice_id) do
invoice_id = parsed.delete(:invoice_id) do
raise ArgumentError.new("missing required path argument #{_1}")
end
@client.request(
method: :patch,
path: ["api/invoices/%0s/invoice_line_items/%1s", invoice_id, id],
body: parsed.except(:invoice_id),
body: parsed,
model: ModernTreasury::Models::Invoices::InvoiceLineItem,
options: options
)
Expand Down Expand Up @@ -158,7 +158,7 @@ def list(invoice_id, params = {})
#
def delete(id, params)
parsed, options = ModernTreasury::Models::Invoices::LineItemDeleteParams.dump_request(params)
invoice_id = parsed.fetch(:invoice_id) do
invoice_id = parsed.delete(:invoice_id) do
raise ArgumentError.new("missing required path argument #{_1}")
end
@client.request(
Expand Down
8 changes: 4 additions & 4 deletions lib/modern_treasury/resources/ledger_account_categories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def delete(id, params = {})
#
def add_ledger_account(ledger_account_id, params)
parsed, options = ModernTreasury::Models::LedgerAccountCategoryAddLedgerAccountParams.dump_request(params)
id = parsed.fetch(:id) do
id = parsed.delete(:id) do
raise ArgumentError.new("missing required path argument #{_1}")
end
@client.request(
Expand All @@ -197,7 +197,7 @@ def add_ledger_account(ledger_account_id, params)
#
def add_nested_category(sub_category_id, params)
parsed, options = ModernTreasury::Models::LedgerAccountCategoryAddNestedCategoryParams.dump_request(params)
id = parsed.fetch(:id) do
id = parsed.delete(:id) do
raise ArgumentError.new("missing required path argument #{_1}")
end
@client.request(
Expand All @@ -222,7 +222,7 @@ def add_nested_category(sub_category_id, params)
#
def remove_ledger_account(ledger_account_id, params)
parsed, options = ModernTreasury::Models::LedgerAccountCategoryRemoveLedgerAccountParams.dump_request(params)
id = parsed.fetch(:id) do
id = parsed.delete(:id) do
raise ArgumentError.new("missing required path argument #{_1}")
end
@client.request(
Expand All @@ -247,7 +247,7 @@ def remove_ledger_account(ledger_account_id, params)
#
def remove_nested_category(sub_category_id, params)
parsed, options = ModernTreasury::Models::LedgerAccountCategoryRemoveNestedCategoryParams.dump_request(params)
id = parsed.fetch(:id) do
id = parsed.delete(:id) do
raise ArgumentError.new("missing required path argument #{_1}")
end
@client.request(
Expand Down
14 changes: 7 additions & 7 deletions lib/modern_treasury/resources/line_items.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class LineItems
#
def retrieve(id, params)
parsed, options = ModernTreasury::Models::LineItemRetrieveParams.dump_request(params)
itemizable_type = parsed.fetch(:itemizable_type) do
itemizable_type = parsed.delete(:itemizable_type) do
raise ArgumentError.new("missing required path argument #{_1}")
end
itemizable_id = parsed.fetch(:itemizable_id) do
itemizable_id = parsed.delete(:itemizable_id) do
raise ArgumentError.new("missing required path argument #{_1}")
end
@client.request(
Expand Down Expand Up @@ -52,16 +52,16 @@ def retrieve(id, params)
#
def update(id, params)
parsed, options = ModernTreasury::Models::LineItemUpdateParams.dump_request(params)
itemizable_type = parsed.fetch(:itemizable_type) do
itemizable_type = parsed.delete(:itemizable_type) do
raise ArgumentError.new("missing required path argument #{_1}")
end
itemizable_id = parsed.fetch(:itemizable_id) do
itemizable_id = parsed.delete(:itemizable_id) do
raise ArgumentError.new("missing required path argument #{_1}")
end
@client.request(
method: :patch,
path: ["api/%0s/%1s/line_items/%2s", itemizable_type, itemizable_id, id],
body: parsed.except(:itemizable_type, :itemizable_id),
body: parsed,
model: ModernTreasury::Models::LineItem,
options: options
)
Expand All @@ -85,13 +85,13 @@ def update(id, params)
#
def list(itemizable_id, params)
parsed, options = ModernTreasury::Models::LineItemListParams.dump_request(params)
itemizable_type = parsed.fetch(:itemizable_type) do
itemizable_type = parsed.delete(:itemizable_type) do
raise ArgumentError.new("missing required path argument #{_1}")
end
@client.request(
method: :get,
path: ["api/%0s/%1s/line_items", itemizable_type, itemizable_id],
query: parsed.except(:itemizable_type),
query: parsed,
page: ModernTreasury::Page,
model: ModernTreasury::Models::LineItem,
options: options
Expand Down
2 changes: 1 addition & 1 deletion lib/modern_treasury/resources/payment_orders/reversals.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def create(payment_order_id, params)
#
def retrieve(reversal_id, params)
parsed, options = ModernTreasury::Models::PaymentOrders::ReversalRetrieveParams.dump_request(params)
payment_order_id = parsed.fetch(:payment_order_id) do
payment_order_id = parsed.delete(:payment_order_id) do
raise ArgumentError.new("missing required path argument #{_1}")
end
@client.request(
Expand Down
16 changes: 8 additions & 8 deletions lib/modern_treasury/resources/routing_details.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ class RoutingDetails
#
def create(account_id, params)
parsed, options = ModernTreasury::Models::RoutingDetailCreateParams.dump_request(params)
accounts_type = parsed.fetch(:accounts_type) do
accounts_type = parsed.delete(:accounts_type) do
raise ArgumentError.new("missing required path argument #{_1}")
end
@client.request(
method: :post,
path: ["api/%0s/%1s/routing_details", accounts_type, account_id],
body: parsed.except(:accounts_type),
body: parsed,
model: ModernTreasury::Models::RoutingDetail,
options: options
)
Expand All @@ -54,10 +54,10 @@ def create(account_id, params)
#
def retrieve(id, params)
parsed, options = ModernTreasury::Models::RoutingDetailRetrieveParams.dump_request(params)
accounts_type = parsed.fetch(:accounts_type) do
accounts_type = parsed.delete(:accounts_type) do
raise ArgumentError.new("missing required path argument #{_1}")
end
account_id = parsed.fetch(:account_id) do
account_id = parsed.delete(:account_id) do
raise ArgumentError.new("missing required path argument #{_1}")
end
@client.request(
Expand Down Expand Up @@ -86,13 +86,13 @@ def retrieve(id, params)
#
def list(account_id, params)
parsed, options = ModernTreasury::Models::RoutingDetailListParams.dump_request(params)
accounts_type = parsed.fetch(:accounts_type) do
accounts_type = parsed.delete(:accounts_type) do
raise ArgumentError.new("missing required path argument #{_1}")
end
@client.request(
method: :get,
path: ["api/%0s/%1s/routing_details", accounts_type, account_id],
query: parsed.except(:accounts_type),
query: parsed,
page: ModernTreasury::Page,
model: ModernTreasury::Models::RoutingDetail,
options: options
Expand All @@ -115,10 +115,10 @@ def list(account_id, params)
#
def delete(id, params)
parsed, options = ModernTreasury::Models::RoutingDetailDeleteParams.dump_request(params)
accounts_type = parsed.fetch(:accounts_type) do
accounts_type = parsed.delete(:accounts_type) do
raise ArgumentError.new("missing required path argument #{_1}")
end
account_id = parsed.fetch(:account_id) do
account_id = parsed.delete(:account_id) do
raise ArgumentError.new("missing required path argument #{_1}")
end
@client.request(
Expand Down
10 changes: 8 additions & 2 deletions lib/modern_treasury/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,19 @@ def join_parsed_uri(lhs, rhs)
class << self
# @private
#
# @param headers [Array<Hash{String=>String, Integer, nil}>]
# @param headers [Hash{String=>String, Integer, Array<String, Integer, nil>, nil}]
#
# @return [Hash{String=>String}]
#
def normalized_headers(*headers)
{}.merge(*headers.compact).to_h do |key, val|
[key.downcase, val&.to_s&.strip]
case val
in Array
val.map { _1.to_s.strip }.join(", ")
else
val&.to_s&.strip
end
[key.downcase, val]
end
end
end
Expand Down
25 changes: 22 additions & 3 deletions rbi/lib/modern_treasury/base_client.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@ module ModernTreasury
method: Symbol,
path: T.any(String, T::Array[String]),
query: T.nilable(T::Hash[String, T.nilable(T.any(T::Array[String], String))]),
headers: T.nilable(T::Hash[String, T.nilable(String)]),
headers: T.nilable(
T::Hash[String,
T.nilable(
T.any(
String,
Integer,
T::Array[T.nilable(T.any(String, Integer))]
)
)]
),
body: T.nilable(T.anything),
unwrap: T.nilable(Symbol),
page: T.nilable(T::Class[ModernTreasury::BaseModel]),
Expand Down Expand Up @@ -69,7 +78,8 @@ module ModernTreasury
max_retries: Integer,
initial_retry_delay: Float,
max_retry_delay: Float,
headers: T::Hash[String, T.nilable(String)],
headers: T::Hash[String,
T.nilable(T.any(String, Integer, T::Array[T.nilable(T.any(String, Integer))]))],
idempotency_header: T.nilable(String)
)
.void
Expand Down Expand Up @@ -133,7 +143,16 @@ module ModernTreasury
method: Symbol,
path: T.any(String, T::Array[String]),
query: T.nilable(T::Hash[String, T.nilable(T.any(T::Array[String], String))]),
headers: T.nilable(T::Hash[String, T.nilable(String)]),
headers: T.nilable(
T::Hash[String,
T.nilable(
T.any(
String,
Integer,
T::Array[T.nilable(T.any(String, Integer))]
)
)]
),
body: T.nilable(T.anything),
unwrap: T.nilable(Symbol),
page: T.nilable(T::Class[ModernTreasury::BaseModel]),
Expand Down
5 changes: 4 additions & 1 deletion rbi/lib/modern_treasury/util.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ module ModernTreasury
end

sig do
params(headers: T::Array[T::Hash[String, T.nilable(T.any(String, Integer))]])
params(
headers: T::Hash[String,
T.nilable(T.any(String, Integer, T::Array[T.nilable(T.any(String, Integer))]))]
)
.returns(T::Hash[String, String])
end
def self.normalized_headers(*headers)
Expand Down
Loading

0 comments on commit ea3f187

Please sign in to comment.