terminal-shop 1.7.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/lib/terminal-shop/base_client.rb +36 -46
- data/lib/terminal-shop/base_model.rb +65 -130
- data/lib/terminal-shop/base_page.rb +18 -18
- data/lib/terminal-shop/client.rb +1 -3
- data/lib/terminal-shop/errors.rb +12 -17
- data/lib/terminal-shop/extern.rb +1 -4
- data/lib/terminal-shop/models/subscription.rb +6 -0
- data/lib/terminal-shop/pooled_net_requester.rb +19 -21
- data/lib/terminal-shop/request_options.rb +4 -11
- data/lib/terminal-shop/resources/address.rb +0 -5
- data/lib/terminal-shop/resources/app.rb +0 -5
- data/lib/terminal-shop/resources/card.rb +0 -6
- data/lib/terminal-shop/resources/cart.rb +0 -7
- data/lib/terminal-shop/resources/email.rb +0 -2
- data/lib/terminal-shop/resources/order.rb +0 -4
- data/lib/terminal-shop/resources/product.rb +0 -3
- data/lib/terminal-shop/resources/profile.rb +0 -3
- data/lib/terminal-shop/resources/subscription.rb +0 -5
- data/lib/terminal-shop/resources/token.rb +0 -5
- data/lib/terminal-shop/resources/view.rb +0 -2
- data/lib/terminal-shop/util.rb +44 -71
- data/lib/terminal-shop/version.rb +1 -1
- data/lib/terminal-shop.rb +1 -0
- data/manifest.yaml +1 -0
- data/rbi/lib/terminal-shop/base_client.rbi +23 -0
- data/rbi/lib/terminal-shop/base_model.rbi +178 -52
- data/rbi/lib/terminal-shop/base_page.rbi +1 -2
- data/rbi/lib/terminal-shop/client.rbi +11 -0
- data/rbi/lib/terminal-shop/errors.rbi +33 -0
- data/rbi/lib/terminal-shop/extern.rbi +1 -1
- data/rbi/lib/terminal-shop/models/address.rbi +10 -0
- data/rbi/lib/terminal-shop/models/address_create_params.rbi +8 -0
- data/rbi/lib/terminal-shop/models/address_create_response.rbi +1 -0
- data/rbi/lib/terminal-shop/models/address_get_response.rbi +1 -0
- data/rbi/lib/terminal-shop/models/address_list_response.rbi +1 -0
- data/rbi/lib/terminal-shop/models/app.rbi +5 -0
- data/rbi/lib/terminal-shop/models/app_create_response.rbi +2 -0
- data/rbi/lib/terminal-shop/models/app_get_response.rbi +1 -0
- data/rbi/lib/terminal-shop/models/app_list_response.rbi +1 -0
- data/rbi/lib/terminal-shop/models/card.rbi +8 -0
- data/rbi/lib/terminal-shop/models/card_collect_response.rbi +4 -0
- data/rbi/lib/terminal-shop/models/card_create_params.rbi +2 -0
- data/rbi/lib/terminal-shop/models/card_create_response.rbi +1 -0
- data/rbi/lib/terminal-shop/models/card_get_response.rbi +1 -0
- data/rbi/lib/terminal-shop/models/card_list_response.rbi +1 -0
- data/rbi/lib/terminal-shop/models/cart.rbi +19 -0
- data/rbi/lib/terminal-shop/models/cart_convert_response.rbi +1 -0
- data/rbi/lib/terminal-shop/models/cart_get_response.rbi +1 -0
- data/rbi/lib/terminal-shop/models/cart_set_address_params.rbi +1 -0
- data/rbi/lib/terminal-shop/models/cart_set_card_params.rbi +1 -0
- data/rbi/lib/terminal-shop/models/cart_set_item_params.rbi +2 -0
- data/rbi/lib/terminal-shop/models/cart_set_item_response.rbi +1 -0
- data/rbi/lib/terminal-shop/models/email_create_params.rbi +1 -0
- data/rbi/lib/terminal-shop/models/order.rbi +28 -0
- data/rbi/lib/terminal-shop/models/order_create_params.rbi +3 -0
- data/rbi/lib/terminal-shop/models/order_create_response.rbi +1 -0
- data/rbi/lib/terminal-shop/models/order_get_response.rbi +1 -0
- data/rbi/lib/terminal-shop/models/order_list_response.rbi +1 -0
- data/rbi/lib/terminal-shop/models/product.rbi +12 -6
- data/rbi/lib/terminal-shop/models/product_get_response.rbi +1 -0
- data/rbi/lib/terminal-shop/models/product_list_response.rbi +1 -0
- data/rbi/lib/terminal-shop/models/product_variant.rbi +4 -0
- data/rbi/lib/terminal-shop/models/profile.rbi +8 -0
- data/rbi/lib/terminal-shop/models/profile_me_response.rbi +1 -0
- data/rbi/lib/terminal-shop/models/profile_update_response.rbi +1 -0
- data/rbi/lib/terminal-shop/models/region.rbi +3 -6
- data/rbi/lib/terminal-shop/models/subscription.rbi +18 -11
- data/rbi/lib/terminal-shop/models/subscription_get_response.rbi +1 -0
- data/rbi/lib/terminal-shop/models/subscription_list_response.rbi +1 -0
- data/rbi/lib/terminal-shop/models/token.rbi +5 -0
- data/rbi/lib/terminal-shop/models/token_create_response.rbi +3 -0
- data/rbi/lib/terminal-shop/models/token_get_response.rbi +2 -0
- data/rbi/lib/terminal-shop/models/token_list_response.rbi +1 -0
- data/rbi/lib/terminal-shop/models/view_init_response.rbi +5 -0
- data/rbi/lib/terminal-shop/pooled_net_requester.rbi +10 -3
- data/rbi/lib/terminal-shop/request_options.rbi +21 -2
- data/rbi/lib/terminal-shop/resources/address.rbi +22 -2
- data/rbi/lib/terminal-shop/resources/app.rbi +14 -2
- data/rbi/lib/terminal-shop/resources/card.rbi +22 -3
- data/rbi/lib/terminal-shop/resources/cart.rbi +23 -3
- data/rbi/lib/terminal-shop/resources/email.rbi +6 -1
- data/rbi/lib/terminal-shop/resources/order.rbi +17 -2
- data/rbi/lib/terminal-shop/resources/product.rbi +7 -1
- data/rbi/lib/terminal-shop/resources/profile.rbi +2 -0
- data/rbi/lib/terminal-shop/resources/subscription.rbi +21 -2
- data/rbi/lib/terminal-shop/resources/token.rbi +14 -2
- data/rbi/lib/terminal-shop/resources/view.rbi +2 -0
- data/rbi/lib/terminal-shop/util.rbi +55 -8
- data/rbi/lib/terminal-shop/version.rbi +1 -1
- data/sig/terminal-shop/base_client.rbs +6 -1
- data/sig/terminal-shop/base_model.rbs +8 -6
- data/sig/terminal-shop/errors.rbs +4 -4
- data/sig/terminal-shop/models/subscription.rbs +1 -1
- data/sig/terminal-shop/pooled_net_requester.rbs +7 -2
- data/sig/terminal-shop/util.rbs +4 -4
- data/sig/terminal-shop/version.rbs +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 606d2ca50e2cc108dcbc274b0cc1ce406225f2b58b99c38ab143a3123bbd8108
|
4
|
+
data.tar.gz: e6905a7f6cc83c547df50855ce3fe79ffbf372c4ce7c038e960e0751e5c9df26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 260c58e58cbe1f73ed1aef212cca96d125c740e5ab40b1152f3d1ba5798404ba1093b5f46b1412d3a05a5ea34d7bdd41fa39d72940495380c2232ef1b3af3e5f
|
7
|
+
data.tar.gz: 2a7887b08b9703fd060d71a70a41be8fcf3408d83da436d68a1e0e1910a75e8041e80f5aaed27f00e00472691cb4908309b80d438fb4993ebd47de5cd6c6a07d
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@ It is generated with [Stainless](https://www.stainless.com/).
|
|
6
6
|
|
7
7
|
## Documentation
|
8
8
|
|
9
|
-
Documentation for
|
9
|
+
Documentation for released of this gem can be found [on RubyDoc](https://gemdocs.org/gems/terminal-shop).
|
10
10
|
|
11
11
|
The underlying REST API documentation can be found on [terminal.shop](https://terminal.shop/docs).
|
12
12
|
|
@@ -118,6 +118,8 @@ What this means is that while you can use Sorbet to type check your code statica
|
|
118
118
|
|
119
119
|
Due to limitations with the Sorbet type system, where a method otherwise can take an instance of `TerminalShop::BaseModel` class, you will need to use the `**` splat operator to pass the arguments:
|
120
120
|
|
121
|
+
Please follow Sorbet's [setup guides](https://sorbet.org/docs/adopting) for best experience.
|
122
|
+
|
121
123
|
```ruby
|
122
124
|
model = ProductListParams.new
|
123
125
|
|
@@ -1,10 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module TerminalShop
|
4
|
-
# @private
|
4
|
+
# @api private
|
5
5
|
#
|
6
6
|
# @abstract
|
7
|
-
#
|
8
7
|
class BaseClient
|
9
8
|
# from whatwg fetch spec
|
10
9
|
MAX_REDIRECTS = 20
|
@@ -21,12 +20,11 @@ module TerminalShop
|
|
21
20
|
# rubocop:enable Style/MutableConstant
|
22
21
|
|
23
22
|
class << self
|
24
|
-
# @private
|
23
|
+
# @api private
|
25
24
|
#
|
26
25
|
# @param req [Hash{Symbol=>Object}]
|
27
26
|
#
|
28
27
|
# @raise [ArgumentError]
|
29
|
-
#
|
30
28
|
def validate!(req)
|
31
29
|
keys = [:method, :path, :query, :headers, :body, :unwrap, :page, :stream, :model, :options]
|
32
30
|
case req
|
@@ -41,13 +39,12 @@ module TerminalShop
|
|
41
39
|
end
|
42
40
|
end
|
43
41
|
|
44
|
-
# @private
|
42
|
+
# @api private
|
45
43
|
#
|
46
44
|
# @param status [Integer]
|
47
45
|
# @param headers [Hash{String=>String}, Net::HTTPHeader]
|
48
46
|
#
|
49
47
|
# @return [Boolean]
|
50
|
-
#
|
51
48
|
def should_retry?(status, headers:)
|
52
49
|
coerced = TerminalShop::Util.coerce_boolean(headers["x-should-retry"])
|
53
50
|
case [coerced, status]
|
@@ -65,7 +62,7 @@ module TerminalShop
|
|
65
62
|
end
|
66
63
|
end
|
67
64
|
|
68
|
-
# @private
|
65
|
+
# @api private
|
69
66
|
#
|
70
67
|
# @param request [Hash{Symbol=>Object}] .
|
71
68
|
#
|
@@ -86,7 +83,6 @@ module TerminalShop
|
|
86
83
|
# @param response_headers [Hash{String=>String}, Net::HTTPHeader]
|
87
84
|
#
|
88
85
|
# @return [Hash{Symbol=>Object}]
|
89
|
-
#
|
90
86
|
def follow_redirect(request, status:, response_headers:)
|
91
87
|
method, url, headers = request.fetch_values(:method, :url, :headers)
|
92
88
|
location =
|
@@ -128,14 +124,27 @@ module TerminalShop
|
|
128
124
|
|
129
125
|
request
|
130
126
|
end
|
127
|
+
|
128
|
+
# @api private
|
129
|
+
#
|
130
|
+
# @param status [Integer, TerminalShop::APIConnectionError]
|
131
|
+
# @param stream [Enumerable, nil]
|
132
|
+
def reap_connection!(status, stream:)
|
133
|
+
case status
|
134
|
+
in (..199) | (300..499)
|
135
|
+
stream&.each { next }
|
136
|
+
in TerminalShop::APIConnectionError | (500..)
|
137
|
+
TerminalShop::Util.close_fused!(stream)
|
138
|
+
else
|
139
|
+
end
|
140
|
+
end
|
131
141
|
end
|
132
142
|
|
133
|
-
# @private
|
134
|
-
#
|
143
|
+
# @api private
|
135
144
|
# @return [TerminalShop::PooledNetRequester]
|
136
145
|
attr_accessor :requester
|
137
146
|
|
138
|
-
# @private
|
147
|
+
# @api private
|
139
148
|
#
|
140
149
|
# @param base_url [String]
|
141
150
|
# @param timeout [Float]
|
@@ -144,7 +153,6 @@ module TerminalShop
|
|
144
153
|
# @param max_retry_delay [Float]
|
145
154
|
# @param headers [Hash{String=>String, Integer, Array<String, Integer, nil>, nil}]
|
146
155
|
# @param idempotency_header [String, nil]
|
147
|
-
#
|
148
156
|
def initialize(
|
149
157
|
base_url:,
|
150
158
|
timeout: 0.0,
|
@@ -171,19 +179,17 @@ module TerminalShop
|
|
171
179
|
@max_retry_delay = max_retry_delay
|
172
180
|
end
|
173
181
|
|
174
|
-
# @private
|
182
|
+
# @api private
|
175
183
|
#
|
176
184
|
# @return [Hash{String=>String}]
|
177
|
-
#
|
178
185
|
private def auth_headers = {}
|
179
186
|
|
180
|
-
# @private
|
187
|
+
# @api private
|
181
188
|
#
|
182
189
|
# @return [String]
|
183
|
-
#
|
184
190
|
private def generate_idempotency_key = "stainless-ruby-retry-#{SecureRandom.uuid}"
|
185
191
|
|
186
|
-
# @private
|
192
|
+
# @api private
|
187
193
|
#
|
188
194
|
# @param req [Hash{Symbol=>Object}] .
|
189
195
|
#
|
@@ -220,7 +226,6 @@ module TerminalShop
|
|
220
226
|
# @option opts [Float, nil] :timeout
|
221
227
|
#
|
222
228
|
# @return [Hash{Symbol=>Object}]
|
223
|
-
#
|
224
229
|
private def build_request(req, opts)
|
225
230
|
method, uninterpolated_path = req.fetch_values(:method, :path)
|
226
231
|
|
@@ -271,13 +276,12 @@ module TerminalShop
|
|
271
276
|
}
|
272
277
|
end
|
273
278
|
|
274
|
-
# @private
|
279
|
+
# @api private
|
275
280
|
#
|
276
281
|
# @param headers [Hash{String=>String}]
|
277
282
|
# @param retry_count [Integer]
|
278
283
|
#
|
279
284
|
# @return [Float]
|
280
|
-
#
|
281
285
|
private def retry_delay(headers, retry_count:)
|
282
286
|
# Non-standard extension
|
283
287
|
span = Float(headers["retry-after-ms"], exception: false)&.then { _1 / 1000 }
|
@@ -298,7 +302,7 @@ module TerminalShop
|
|
298
302
|
(@initial_retry_delay * scale * jitter).clamp(0, @max_retry_delay)
|
299
303
|
end
|
300
304
|
|
301
|
-
# @private
|
305
|
+
# @api private
|
302
306
|
#
|
303
307
|
# @param request [Hash{Symbol=>Object}] .
|
304
308
|
#
|
@@ -322,7 +326,6 @@ module TerminalShop
|
|
322
326
|
#
|
323
327
|
# @raise [TerminalShop::APIError]
|
324
328
|
# @return [Array(Integer, Net::HTTPResponse, Enumerable)]
|
325
|
-
#
|
326
329
|
private def send_request(request, redirect_count:, retry_count:, send_retry_header:)
|
327
330
|
url, headers, max_retries, timeout = request.fetch_values(:url, :headers, :max_retries, :timeout)
|
328
331
|
input = {**request.except(:timeout), deadline: TerminalShop::Util.monotonic_secs + timeout}
|
@@ -332,28 +335,23 @@ module TerminalShop
|
|
332
335
|
end
|
333
336
|
|
334
337
|
begin
|
335
|
-
response, stream = @requester.execute(input)
|
336
|
-
status = Integer(response.code)
|
338
|
+
status, response, stream = @requester.execute(input)
|
337
339
|
rescue TerminalShop::APIConnectionError => e
|
338
340
|
status = e
|
339
341
|
end
|
340
342
|
|
341
|
-
# normally we want to drain the response body and reuse the HTTP session by clearing the socket buffers
|
342
|
-
# unless we hit a server error
|
343
|
-
srv_fault = (500...).include?(status)
|
344
|
-
|
345
343
|
case status
|
346
344
|
in ..299
|
347
345
|
[status, response, stream]
|
348
346
|
in 300..399 if redirect_count >= self.class::MAX_REDIRECTS
|
349
|
-
|
347
|
+
self.class.reap_connection!(status, stream: stream)
|
350
348
|
|
351
|
-
|
349
|
+
message = "Failed to complete the request within #{self.class::MAX_REDIRECTS} redirects."
|
352
350
|
raise TerminalShop::APIConnectionError.new(url: url, message: message)
|
353
351
|
in 300..399
|
354
|
-
|
352
|
+
self.class.reap_connection!(status, stream: stream)
|
355
353
|
|
356
|
-
|
354
|
+
request = self.class.follow_redirect(request, status: status, response_headers: response)
|
357
355
|
send_request(
|
358
356
|
request,
|
359
357
|
redirect_count: redirect_count + 1,
|
@@ -363,12 +361,10 @@ module TerminalShop
|
|
363
361
|
in TerminalShop::APIConnectionError if retry_count >= max_retries
|
364
362
|
raise status
|
365
363
|
in (400..) if retry_count >= max_retries || !self.class.should_retry?(status, headers: response)
|
366
|
-
decoded =
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
else
|
371
|
-
stream.each { next }
|
364
|
+
decoded = Kernel.then do
|
365
|
+
TerminalShop::Util.decode_content(response, stream: stream, suppress_error: true)
|
366
|
+
ensure
|
367
|
+
self.class.reap_connection!(status, stream: stream)
|
372
368
|
end
|
373
369
|
|
374
370
|
raise TerminalShop::APIStatusError.for(
|
@@ -379,13 +375,9 @@ module TerminalShop
|
|
379
375
|
response: response
|
380
376
|
)
|
381
377
|
in (400..) | TerminalShop::APIConnectionError
|
382
|
-
|
378
|
+
self.class.reap_connection!(status, stream: stream)
|
383
379
|
|
384
|
-
|
385
|
-
TerminalShop::Util.close_fused!(stream)
|
386
|
-
else
|
387
|
-
stream&.each { next }
|
388
|
-
end
|
380
|
+
delay = retry_delay(response, retry_count: retry_count)
|
389
381
|
sleep(delay)
|
390
382
|
|
391
383
|
send_request(
|
@@ -424,7 +416,6 @@ module TerminalShop
|
|
424
416
|
#
|
425
417
|
# @raise [TerminalShop::APIError]
|
426
418
|
# @return [Object]
|
427
|
-
#
|
428
419
|
def request(req)
|
429
420
|
self.class.validate!(req)
|
430
421
|
model = req.fetch(:model) { TerminalShop::Unknown }
|
@@ -455,7 +446,6 @@ module TerminalShop
|
|
455
446
|
end
|
456
447
|
|
457
448
|
# @return [String]
|
458
|
-
#
|
459
449
|
def inspect
|
460
450
|
# rubocop:disable Layout/LineLength
|
461
451
|
base_url = TerminalShop::Util.unparse_uri(@base_url)
|