Skip to content

Commit 003ab4e

Browse files
fix(client): serialize query parameters properly
1 parent c8c588e commit 003ab4e

29 files changed

+138
-40
lines changed

lib/orb/internal/util.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,37 @@ def writable_enum(&blk)
490490
JSONL_CONTENT = %r{^application/(:?x-(?:n|l)djson)|(:?(?:x-)?jsonl)}
491491

492492
class << self
493+
# @api private
494+
#
495+
# @param query [Hash{Symbol=>Object}]
496+
#
497+
# @return [Hash{Symbol=>Object}]
498+
def encode_query_params(query)
499+
out = {}
500+
query.each { write_query_param_element!(out, _1, _2) }
501+
out
502+
end
503+
504+
# @api private
505+
#
506+
# @param collection [Hash{Symbol=>Object}]
507+
# @param key [String]
508+
# @param element [Object]
509+
#
510+
# @return [nil]
511+
private def write_query_param_element!(collection, key, element)
512+
case element
513+
in Hash
514+
element.each do |name, value|
515+
write_query_param_element!(collection, "#{key}[#{name}]", value)
516+
end
517+
in Array
518+
collection["#{key}[]"] = element.map(&:to_s)
519+
else
520+
collection[key] = element.to_s
521+
end
522+
end
523+
493524
# @api private
494525
#
495526
# @param y [Enumerator::Yielder]

lib/orb/resources/alerts.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,11 @@ def update(alert_configuration_id, params)
8888
# @see Orb::Models::AlertListParams
8989
def list(params = {})
9090
parsed, options = Orb::AlertListParams.dump_request(params)
91+
query = Orb::Internal::Util.encode_query_params(parsed)
9192
@client.request(
9293
method: :get,
9394
path: "alerts",
94-
query: parsed.transform_keys(
95+
query: query.transform_keys(
9596
created_at_gt: "created_at[gt]",
9697
created_at_gte: "created_at[gte]",
9798
created_at_lt: "created_at[lt]",
@@ -228,10 +229,11 @@ def create_for_subscription(subscription_id, params)
228229
# @see Orb::Models::AlertDisableParams
229230
def disable(alert_configuration_id, params = {})
230231
parsed, options = Orb::AlertDisableParams.dump_request(params)
232+
query = Orb::Internal::Util.encode_query_params(parsed)
231233
@client.request(
232234
method: :post,
233235
path: ["alerts/%1$s/disable", alert_configuration_id],
234-
query: parsed,
236+
query: query,
235237
model: Orb::Alert,
236238
options: options
237239
)
@@ -254,10 +256,11 @@ def disable(alert_configuration_id, params = {})
254256
# @see Orb::Models::AlertEnableParams
255257
def enable(alert_configuration_id, params = {})
256258
parsed, options = Orb::AlertEnableParams.dump_request(params)
259+
query = Orb::Internal::Util.encode_query_params(parsed)
257260
@client.request(
258261
method: :post,
259262
path: ["alerts/%1$s/enable", alert_configuration_id],
260-
query: parsed,
263+
query: query,
261264
model: Orb::Alert,
262265
options: options
263266
)

lib/orb/resources/coupons.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ def create(params)
5959
# @see Orb::Models::CouponListParams
6060
def list(params = {})
6161
parsed, options = Orb::CouponListParams.dump_request(params)
62+
query = Orb::Internal::Util.encode_query_params(parsed)
6263
@client.request(
6364
method: :get,
6465
path: "coupons",
65-
query: parsed,
66+
query: query,
6667
page: Orb::Internal::Page,
6768
model: Orb::Coupon,
6869
options: options

lib/orb/resources/coupons/subscriptions.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ class Subscriptions
2727
# @see Orb::Models::Coupons::SubscriptionListParams
2828
def list(coupon_id, params = {})
2929
parsed, options = Orb::Coupons::SubscriptionListParams.dump_request(params)
30+
query = Orb::Internal::Util.encode_query_params(parsed)
3031
@client.request(
3132
method: :get,
3233
path: ["coupons/%1$s/subscriptions", coupon_id],
33-
query: parsed,
34+
query: query,
3435
page: Orb::Internal::Page,
3536
model: Orb::Subscription,
3637
options: options

lib/orb/resources/credit_notes.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,11 @@ def create(params)
9090
# @see Orb::Models::CreditNoteListParams
9191
def list(params = {})
9292
parsed, options = Orb::CreditNoteListParams.dump_request(params)
93+
query = Orb::Internal::Util.encode_query_params(parsed)
9394
@client.request(
9495
method: :get,
9596
path: "credit_notes",
96-
query: parsed.transform_keys(
97+
query: query.transform_keys(
9798
created_at_gt: "created_at[gt]",
9899
created_at_gte: "created_at[gte]",
99100
created_at_lt: "created_at[lt]",

lib/orb/resources/customers.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,11 @@ def update(customer_id, params = {})
184184
# @see Orb::Models::CustomerListParams
185185
def list(params = {})
186186
parsed, options = Orb::CustomerListParams.dump_request(params)
187+
query = Orb::Internal::Util.encode_query_params(parsed)
187188
@client.request(
188189
method: :get,
189190
path: "customers",
190-
query: parsed.transform_keys(
191+
query: query.transform_keys(
191192
created_at_gt: "created_at[gt]",
192193
created_at_gte: "created_at[gte]",
193194
created_at_lt: "created_at[lt]",

lib/orb/resources/customers/balance_transactions.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,11 @@ def create(customer_id, params)
8181
# @see Orb::Models::Customers::BalanceTransactionListParams
8282
def list(customer_id, params = {})
8383
parsed, options = Orb::Customers::BalanceTransactionListParams.dump_request(params)
84+
query = Orb::Internal::Util.encode_query_params(parsed)
8485
@client.request(
8586
method: :get,
8687
path: ["customers/%1$s/balance_transactions", customer_id],
87-
query: parsed.transform_keys(
88+
query: query.transform_keys(
8889
operation_time_gt: "operation_time[gt]",
8990
operation_time_gte: "operation_time[gte]",
9091
operation_time_lt: "operation_time[lt]",

lib/orb/resources/customers/costs.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,11 @@ class Costs
144144
# @see Orb::Models::Customers::CostListParams
145145
def list(customer_id, params = {})
146146
parsed, options = Orb::Customers::CostListParams.dump_request(params)
147+
query = Orb::Internal::Util.encode_query_params(parsed)
147148
@client.request(
148149
method: :get,
149150
path: ["customers/%1$s/costs", customer_id],
150-
query: parsed,
151+
query: query,
151152
model: Orb::Models::Customers::CostListResponse,
152153
options: options
153154
)
@@ -293,10 +294,11 @@ def list(customer_id, params = {})
293294
# @see Orb::Models::Customers::CostListByExternalIDParams
294295
def list_by_external_id(external_customer_id, params = {})
295296
parsed, options = Orb::Customers::CostListByExternalIDParams.dump_request(params)
297+
query = Orb::Internal::Util.encode_query_params(parsed)
296298
@client.request(
297299
method: :get,
298300
path: ["customers/external_customer_id/%1$s/costs", external_customer_id],
299-
query: parsed,
301+
query: query,
300302
model: Orb::Models::Customers::CostListByExternalIDResponse,
301303
options: options
302304
)

lib/orb/resources/customers/credits.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ class Credits
5353
# @see Orb::Models::Customers::CreditListParams
5454
def list(customer_id, params = {})
5555
parsed, options = Orb::Customers::CreditListParams.dump_request(params)
56+
query = Orb::Internal::Util.encode_query_params(parsed)
5657
@client.request(
5758
method: :get,
5859
path: ["customers/%1$s/credits", customer_id],
59-
query: parsed.transform_keys(
60+
query: query.transform_keys(
6061
effective_date_gt: "effective_date[gt]",
6162
effective_date_gte: "effective_date[gte]",
6263
effective_date_lt: "effective_date[lt]",
@@ -111,10 +112,11 @@ def list(customer_id, params = {})
111112
# @see Orb::Models::Customers::CreditListByExternalIDParams
112113
def list_by_external_id(external_customer_id, params = {})
113114
parsed, options = Orb::Customers::CreditListByExternalIDParams.dump_request(params)
115+
query = Orb::Internal::Util.encode_query_params(parsed)
114116
@client.request(
115117
method: :get,
116118
path: ["customers/external_customer_id/%1$s/credits", external_customer_id],
117-
query: parsed.transform_keys(
119+
query: query.transform_keys(
118120
effective_date_gt: "effective_date[gt]",
119121
effective_date_gte: "effective_date[gte]",
120122
effective_date_lt: "effective_date[lt]",

lib/orb/resources/customers/credits/ledger.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,11 @@ class Ledger
119119
# @see Orb::Models::Customers::Credits::LedgerListParams
120120
def list(customer_id, params = {})
121121
parsed, options = Orb::Customers::Credits::LedgerListParams.dump_request(params)
122+
query = Orb::Internal::Util.encode_query_params(parsed)
122123
@client.request(
123124
method: :get,
124125
path: ["customers/%1$s/credits/ledger", customer_id],
125-
query: parsed.transform_keys(
126+
query: query.transform_keys(
126127
created_at_gt: "created_at[gt]",
127128
created_at_gte: "created_at[gte]",
128129
created_at_lt: "created_at[lt]",
@@ -580,10 +581,11 @@ def create_entry_by_external_id(external_customer_id, params)
580581
# @see Orb::Models::Customers::Credits::LedgerListByExternalIDParams
581582
def list_by_external_id(external_customer_id, params = {})
582583
parsed, options = Orb::Customers::Credits::LedgerListByExternalIDParams.dump_request(params)
584+
query = Orb::Internal::Util.encode_query_params(parsed)
583585
@client.request(
584586
method: :get,
585587
path: ["customers/external_customer_id/%1$s/credits/ledger", external_customer_id],
586-
query: parsed.transform_keys(
588+
query: query.transform_keys(
587589
created_at_gt: "created_at[gt]",
588590
created_at_gte: "created_at[gte]",
589591
created_at_lt: "created_at[lt]",

0 commit comments

Comments
 (0)