Skip to content

Commit abb7cc2

Browse files
authored
fix: remove default base_url fallback in clients and forward request_options to API requests (#220)
* fix: remove default base_url fallback in clients Stop defaulting request base_url to Square::Environment::PRODUCTION in inventory and transfer_orders clients. The Request construction now uses request_options[:base_url] directly (no || fallback), requiring callers or a higher-level config to provide a base_url and avoiding implicit production assumptions. Files changed: lib/square/inventory/client.rb, lib/square/transfer_orders/client.rb. * Forward request_options to API requests Add request_options to Square::Internal::JSON::Request calls in lib/square/inventory/client.rb and lib/square/transfer_orders/client.rb so per-request options (e.g. base_url, headers) are properly forwarded. Updated request constructors for various GET/POST/PUT/DELETE endpoints to include request_options and adjusted argument formatting; no other business logic changes.
1 parent c6c3db3 commit abb7cc2

File tree

2 files changed

+63
-42
lines changed

2 files changed

+63
-42
lines changed

lib/square/inventory/client.rb

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ def initialize(client:)
1414
# @return [Square::Types::GetInventoryAdjustmentResponse]
1515
def deprecated_get_adjustment(request_options: {}, **params)
1616
_request = Square::Internal::JSON::Request.new(
17-
base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
17+
base_url: request_options[:base_url],
1818
method: "GET",
19-
path: "v2/inventory/adjustment/#{params[:adjustment_id]}"
19+
path: "v2/inventory/adjustment/#{params[:adjustment_id]}",
20+
request_options: request_options
2021
)
2122
begin
2223
_response = @client.send(_request)
@@ -38,9 +39,10 @@ def deprecated_get_adjustment(request_options: {}, **params)
3839
# @return [Square::Types::GetInventoryAdjustmentResponse]
3940
def get_adjustment(request_options: {}, **params)
4041
_request = Square::Internal::JSON::Request.new(
41-
base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
42+
base_url: request_options[:base_url],
4243
method: "GET",
43-
path: "v2/inventory/adjustments/#{params[:adjustment_id]}"
44+
path: "v2/inventory/adjustments/#{params[:adjustment_id]}",
45+
request_options: request_options
4446
)
4547
begin
4648
_response = @client.send(_request)
@@ -62,10 +64,11 @@ def get_adjustment(request_options: {}, **params)
6264
# @return [Square::Types::BatchChangeInventoryResponse]
6365
def deprecated_batch_change(request_options: {}, **params)
6466
_request = Square::Internal::JSON::Request.new(
65-
base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
67+
base_url: request_options[:base_url],
6668
method: "POST",
6769
path: "v2/inventory/batch-change",
68-
body: Square::Types::BatchChangeInventoryRequest.new(params).to_h
70+
body: Square::Types::BatchChangeInventoryRequest.new(params).to_h,
71+
request_options: request_options
6972
)
7073
begin
7174
_response = @client.send(_request)
@@ -87,10 +90,11 @@ def deprecated_batch_change(request_options: {}, **params)
8790
# @return [Square::Types::BatchGetInventoryChangesResponse]
8891
def deprecated_batch_get_changes(request_options: {}, **params)
8992
_request = Square::Internal::JSON::Request.new(
90-
base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
93+
base_url: request_options[:base_url],
9194
method: "POST",
9295
path: "v2/inventory/batch-retrieve-changes",
93-
body: Square::Types::BatchRetrieveInventoryChangesRequest.new(params).to_h
96+
body: Square::Types::BatchRetrieveInventoryChangesRequest.new(params).to_h,
97+
request_options: request_options
9498
)
9599
begin
96100
_response = @client.send(_request)
@@ -112,10 +116,11 @@ def deprecated_batch_get_changes(request_options: {}, **params)
112116
# @return [Square::Types::BatchGetInventoryCountsResponse]
113117
def deprecated_batch_get_counts(request_options: {}, **params)
114118
_request = Square::Internal::JSON::Request.new(
115-
base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
119+
base_url: request_options[:base_url],
116120
method: "POST",
117121
path: "v2/inventory/batch-retrieve-counts",
118-
body: Square::Types::BatchGetInventoryCountsRequest.new(params).to_h
122+
body: Square::Types::BatchGetInventoryCountsRequest.new(params).to_h,
123+
request_options: request_options
119124
)
120125
begin
121126
_response = @client.send(_request)
@@ -140,10 +145,11 @@ def deprecated_batch_get_counts(request_options: {}, **params)
140145
# @return [Square::Types::BatchChangeInventoryResponse]
141146
def batch_create_changes(request_options: {}, **params)
142147
_request = Square::Internal::JSON::Request.new(
143-
base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
148+
base_url: request_options[:base_url],
144149
method: "POST",
145150
path: "v2/inventory/changes/batch-create",
146-
body: Square::Types::BatchChangeInventoryRequest.new(params).to_h
151+
body: Square::Types::BatchChangeInventoryRequest.new(params).to_h,
152+
request_options: request_options
147153
)
148154
begin
149155
_response = @client.send(_request)
@@ -177,10 +183,11 @@ def batch_get_changes(request_options: {}, **params)
177183
) do |next_cursor|
178184
params[:cursor] = next_cursor
179185
_request = Square::Internal::JSON::Request.new(
180-
base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
186+
base_url: request_options[:base_url],
181187
method: "POST",
182188
path: "v2/inventory/changes/batch-retrieve",
183-
body: Square::Types::BatchRetrieveInventoryChangesRequest.new(params).to_h
189+
body: Square::Types::BatchRetrieveInventoryChangesRequest.new(params).to_h,
190+
request_options: request_options
184191
)
185192
begin
186193
_response = @client.send(_request)
@@ -218,10 +225,11 @@ def batch_get_counts(request_options: {}, **params)
218225
) do |next_cursor|
219226
params[:cursor] = next_cursor
220227
_request = Square::Internal::JSON::Request.new(
221-
base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
228+
base_url: request_options[:base_url],
222229
method: "POST",
223230
path: "v2/inventory/counts/batch-retrieve",
224-
body: Square::Types::BatchGetInventoryCountsRequest.new(params).to_h
231+
body: Square::Types::BatchGetInventoryCountsRequest.new(params).to_h,
232+
request_options: request_options
225233
)
226234
begin
227235
_response = @client.send(_request)
@@ -244,9 +252,10 @@ def batch_get_counts(request_options: {}, **params)
244252
# @return [Square::Types::GetInventoryPhysicalCountResponse]
245253
def deprecated_get_physical_count(request_options: {}, **params)
246254
_request = Square::Internal::JSON::Request.new(
247-
base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
255+
base_url: request_options[:base_url],
248256
method: "GET",
249-
path: "v2/inventory/physical-count/#{params[:physical_count_id]}"
257+
path: "v2/inventory/physical-count/#{params[:physical_count_id]}",
258+
request_options: request_options
250259
)
251260
begin
252261
_response = @client.send(_request)
@@ -268,9 +277,10 @@ def deprecated_get_physical_count(request_options: {}, **params)
268277
# @return [Square::Types::GetInventoryPhysicalCountResponse]
269278
def get_physical_count(request_options: {}, **params)
270279
_request = Square::Internal::JSON::Request.new(
271-
base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
280+
base_url: request_options[:base_url],
272281
method: "GET",
273-
path: "v2/inventory/physical-counts/#{params[:physical_count_id]}"
282+
path: "v2/inventory/physical-counts/#{params[:physical_count_id]}",
283+
request_options: request_options
274284
)
275285
begin
276286
_response = @client.send(_request)
@@ -292,9 +302,10 @@ def get_physical_count(request_options: {}, **params)
292302
# @return [Square::Types::GetInventoryTransferResponse]
293303
def get_transfer(request_options: {}, **params)
294304
_request = Square::Internal::JSON::Request.new(
295-
base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
305+
base_url: request_options[:base_url],
296306
method: "GET",
297-
path: "v2/inventory/transfers/#{params[:transfer_id]}"
307+
path: "v2/inventory/transfers/#{params[:transfer_id]}",
308+
request_options: request_options
298309
)
299310
begin
300311
_response = @client.send(_request)
@@ -329,10 +340,11 @@ def get(request_options: {}, **params)
329340
) do |next_cursor|
330341
_query[:cursor] = next_cursor
331342
_request = Square::Internal::JSON::Request.new(
332-
base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
343+
base_url: request_options[:base_url],
333344
method: "GET",
334345
path: "v2/inventory/#{params[:catalog_object_id]}",
335-
query: _query
346+
query: _query,
347+
request_options: request_options
336348
)
337349
begin
338350
_response = @client.send(_request)
@@ -377,10 +389,11 @@ def changes(request_options: {}, **params)
377389
) do |next_cursor|
378390
_query[:cursor] = next_cursor
379391
_request = Square::Internal::JSON::Request.new(
380-
base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
392+
base_url: request_options[:base_url],
381393
method: "GET",
382394
path: "v2/inventory/#{params[:catalog_object_id]}/changes",
383-
query: _query
395+
query: _query,
396+
request_options: request_options
384397
)
385398
begin
386399
_response = @client.send(_request)

lib/square/transfer_orders/client.rb

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ def initialize(client:)
3232
# @return [Square::Types::CreateTransferOrderResponse]
3333
def create(request_options: {}, **params)
3434
_request = Square::Internal::JSON::Request.new(
35-
base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
35+
base_url: request_options[:base_url],
3636
method: "POST",
3737
path: "v2/transfer-orders",
38-
body: params
38+
body: params,
39+
request_options: request_options
3940
)
4041
begin
4142
_response = @client.send(_request)
@@ -68,10 +69,11 @@ def search(request_options: {}, **params)
6869
) do |next_cursor|
6970
params[:cursor] = next_cursor
7071
_request = Square::Internal::JSON::Request.new(
71-
base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
72+
base_url: request_options[:base_url],
7273
method: "POST",
7374
path: "v2/transfer-orders/search",
74-
body: params
75+
body: params,
76+
request_options: request_options
7577
)
7678
begin
7779
_response = @client.send(_request)
@@ -99,9 +101,10 @@ def search(request_options: {}, **params)
99101
# @return [Square::Types::RetrieveTransferOrderResponse]
100102
def get(request_options: {}, **params)
101103
_request = Square::Internal::JSON::Request.new(
102-
base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
104+
base_url: request_options[:base_url],
103105
method: "GET",
104-
path: "v2/transfer-orders/#{params[:transfer_order_id]}"
106+
path: "v2/transfer-orders/#{params[:transfer_order_id]}",
107+
request_options: request_options
105108
)
106109
begin
107110
_response = @client.send(_request)
@@ -127,10 +130,11 @@ def update(request_options: {}, **params)
127130
_path_param_names = ["transfer_order_id"]
128131

129132
_request = Square::Internal::JSON::Request.new(
130-
base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
133+
base_url: request_options[:base_url],
131134
method: "PUT",
132135
path: "v2/transfer-orders/#{params[:transfer_order_id]}",
133-
body: params.except(*_path_param_names)
136+
body: params.except(*_path_param_names),
137+
request_options: request_options
134138
)
135139
begin
136140
_response = @client.send(_request)
@@ -160,10 +164,11 @@ def delete(request_options: {}, **params)
160164
params = params.except(*_query_param_names)
161165

162166
_request = Square::Internal::JSON::Request.new(
163-
base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
167+
base_url: request_options[:base_url],
164168
method: "DELETE",
165169
path: "v2/transfer-orders/#{params[:transfer_order_id]}",
166-
query: _query
170+
query: _query,
171+
request_options: request_options
167172
)
168173
begin
169174
_response = @client.send(_request)
@@ -195,10 +200,11 @@ def cancel(request_options: {}, **params)
195200
_path_param_names = ["transfer_order_id"]
196201

197202
_request = Square::Internal::JSON::Request.new(
198-
base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
203+
base_url: request_options[:base_url],
199204
method: "POST",
200205
path: "v2/transfer-orders/#{params[:transfer_order_id]}/cancel",
201-
body: params.except(*_path_param_names)
206+
body: params.except(*_path_param_names),
207+
request_options: request_options
202208
)
203209
begin
204210
_response = @client.send(_request)
@@ -236,10 +242,11 @@ def receive(request_options: {}, **params)
236242
_path_param_names = ["transfer_order_id"]
237243

238244
_request = Square::Internal::JSON::Request.new(
239-
base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
245+
base_url: request_options[:base_url],
240246
method: "POST",
241247
path: "v2/transfer-orders/#{params[:transfer_order_id]}/receive",
242-
body: params.except(*_path_param_names)
248+
body: params.except(*_path_param_names),
249+
request_options: request_options
243250
)
244251
begin
245252
_response = @client.send(_request)
@@ -269,10 +276,11 @@ def start(request_options: {}, **params)
269276
_path_param_names = ["transfer_order_id"]
270277

271278
_request = Square::Internal::JSON::Request.new(
272-
base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
279+
base_url: request_options[:base_url],
273280
method: "POST",
274281
path: "v2/transfer-orders/#{params[:transfer_order_id]}/start",
275-
body: params.except(*_path_param_names)
282+
body: params.except(*_path_param_names),
283+
request_options: request_options
276284
)
277285
begin
278286
_response = @client.send(_request)

0 commit comments

Comments
 (0)