terminal-shop 0.1.0.pre.alpha.10 → 0.1.0.pre.alpha.12
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 +1 -1
- data/lib/terminal-shop/base_client.rb +165 -137
- data/lib/terminal-shop/base_model.rb +2 -4
- data/lib/terminal-shop/base_page.rb +2 -6
- data/lib/terminal-shop/client.rb +0 -1
- data/lib/terminal-shop/models/address.rb +0 -11
- data/lib/terminal-shop/models/address_create_response.rb +0 -6
- data/lib/terminal-shop/models/address_delete_response.rb +0 -6
- data/lib/terminal-shop/models/address_list_response.rb +0 -6
- data/lib/terminal-shop/models/app.rb +8 -9
- data/lib/terminal-shop/models/app_create_response.rb +0 -13
- data/lib/terminal-shop/models/app_delete_response.rb +0 -6
- data/lib/terminal-shop/models/app_get_response.rb +0 -6
- data/lib/terminal-shop/models/app_list_response.rb +0 -6
- data/lib/terminal-shop/models/card.rb +0 -16
- data/lib/terminal-shop/models/card_collect_response.rb +0 -12
- data/lib/terminal-shop/models/card_create_response.rb +0 -6
- data/lib/terminal-shop/models/card_delete_response.rb +0 -6
- data/lib/terminal-shop/models/card_list_response.rb +0 -6
- data/lib/terminal-shop/models/cart.rb +0 -33
- data/lib/terminal-shop/models/cart_convert_response.rb +0 -6
- data/lib/terminal-shop/models/cart_get_response.rb +0 -6
- data/lib/terminal-shop/models/cart_set_address_response.rb +0 -6
- data/lib/terminal-shop/models/cart_set_card_response.rb +0 -6
- data/lib/terminal-shop/models/cart_set_item_response.rb +0 -6
- data/lib/terminal-shop/models/email_create_response.rb +0 -6
- data/lib/terminal-shop/models/order.rb +0 -46
- data/lib/terminal-shop/models/order_get_response.rb +0 -6
- data/lib/terminal-shop/models/order_list_response.rb +0 -6
- data/lib/terminal-shop/models/product.rb +0 -11
- data/lib/terminal-shop/models/product_list_response.rb +0 -6
- data/lib/terminal-shop/models/product_variant.rb +0 -8
- data/lib/terminal-shop/models/profile.rb +0 -16
- data/lib/terminal-shop/models/profile_me_response.rb +0 -6
- data/lib/terminal-shop/models/profile_update_response.rb +0 -6
- data/lib/terminal-shop/models/subscription.rb +1 -66
- data/lib/terminal-shop/models/subscription_create_response.rb +0 -6
- data/lib/terminal-shop/models/subscription_delete_response.rb +0 -6
- data/lib/terminal-shop/models/subscription_list_response.rb +0 -6
- data/lib/terminal-shop/models/token.rb +6 -37
- data/lib/terminal-shop/models/token_create_response.rb +0 -13
- data/lib/terminal-shop/models/token_delete_response.rb +0 -6
- data/lib/terminal-shop/models/token_get_response.rb +0 -6
- data/lib/terminal-shop/models/token_list_response.rb +0 -6
- data/lib/terminal-shop/models/view_init_response.rb +0 -17
- data/lib/terminal-shop/pooled_net_requester.rb +127 -82
- data/lib/terminal-shop/resources/app.rb +2 -0
- data/lib/terminal-shop/resources/subscription.rb +0 -2
- data/lib/terminal-shop/util.rb +64 -7
- data/lib/terminal-shop/version.rb +1 -1
- data/lib/terminal-shop.rb +56 -55
- data/manifest.yaml +1 -0
- data/rbi/lib/terminal-shop/base_client.rbi +41 -27
- data/rbi/lib/terminal-shop/base_model.rbi +63 -99
- data/rbi/lib/terminal-shop/base_page.rbi +4 -3
- data/rbi/lib/terminal-shop/client.rbi +2 -1
- data/rbi/lib/terminal-shop/errors.rbi +10 -5
- data/rbi/lib/terminal-shop/models/address.rbi +16 -14
- data/rbi/lib/terminal-shop/models/address_create_params.rbi +16 -14
- data/rbi/lib/terminal-shop/models/address_list_response.rbi +1 -3
- data/rbi/lib/terminal-shop/models/app.rbi +11 -3
- data/rbi/lib/terminal-shop/models/app_create_response.rbi +2 -1
- data/rbi/lib/terminal-shop/models/app_list_response.rbi +1 -3
- data/rbi/lib/terminal-shop/models/card.rbi +5 -17
- data/rbi/lib/terminal-shop/models/card_collect_response.rbi +2 -1
- data/rbi/lib/terminal-shop/models/card_create_params.rbi +6 -2
- data/rbi/lib/terminal-shop/models/card_list_response.rbi +1 -3
- data/rbi/lib/terminal-shop/models/cart.rbi +16 -15
- data/rbi/lib/terminal-shop/models/cart_set_address_params.rbi +2 -1
- data/rbi/lib/terminal-shop/models/cart_set_card_params.rbi +6 -2
- data/rbi/lib/terminal-shop/models/cart_set_item_params.rbi +8 -8
- data/rbi/lib/terminal-shop/models/email_create_params.rbi +6 -2
- data/rbi/lib/terminal-shop/models/order.rbi +43 -44
- data/rbi/lib/terminal-shop/models/order_list_response.rbi +1 -3
- data/rbi/lib/terminal-shop/models/product.rbi +17 -14
- data/rbi/lib/terminal-shop/models/product_list_response.rbi +1 -3
- data/rbi/lib/terminal-shop/models/profile.rbi +13 -13
- data/rbi/lib/terminal-shop/models/profile_update_params.rbi +6 -8
- data/rbi/lib/terminal-shop/models/subscription.rbi +29 -59
- data/rbi/lib/terminal-shop/models/subscription_list_response.rbi +2 -1
- data/rbi/lib/terminal-shop/models/token.rbi +7 -25
- data/rbi/lib/terminal-shop/models/token_create_response.rbi +2 -1
- data/rbi/lib/terminal-shop/models/token_list_response.rbi +1 -3
- data/rbi/lib/terminal-shop/models/view_init_response.rbi +26 -34
- data/rbi/lib/terminal-shop/pooled_net_requester.rbi +38 -0
- data/rbi/lib/terminal-shop/request_options.rbi +6 -24
- data/rbi/lib/terminal-shop/resources/address.rbi +6 -11
- data/rbi/lib/terminal-shop/resources/app.rbi +10 -13
- data/rbi/lib/terminal-shop/resources/card.rbi +8 -20
- data/rbi/lib/terminal-shop/resources/cart.rbi +10 -21
- data/rbi/lib/terminal-shop/resources/email.rbi +2 -1
- data/rbi/lib/terminal-shop/resources/order.rbi +4 -10
- data/rbi/lib/terminal-shop/resources/product.rbi +2 -9
- data/rbi/lib/terminal-shop/resources/profile.rbi +4 -10
- data/rbi/lib/terminal-shop/resources/subscription.rbi +6 -13
- data/rbi/lib/terminal-shop/resources/token.rbi +8 -20
- data/rbi/lib/terminal-shop/resources/view.rbi +2 -9
- data/rbi/lib/terminal-shop/util.rbi +33 -23
- data/rbi/lib/terminal-shop/version.rbi +1 -1
- data/sig/terminal-shop/base_client.rbs +28 -27
- data/sig/terminal-shop/base_model.rbs +0 -2
- data/sig/terminal-shop/base_page.rbs +1 -1
- data/sig/terminal-shop/models/app.rbs +5 -2
- data/sig/terminal-shop/models/subscription.rbs +0 -16
- data/sig/terminal-shop/models/token.rbs +3 -22
- data/sig/terminal-shop/pooled_net_requester.rbs +32 -0
- data/sig/terminal-shop/resources/app.rbs +1 -0
- data/sig/terminal-shop/resources/subscription.rbs +0 -1
- data/sig/terminal-shop/util.rbs +11 -1
- data/sig/terminal-shop/version.rbs +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0faffe9f60961c28b6fbab9b959d5b65da1595d913bd1b74d6f41da0eb449c4c
|
4
|
+
data.tar.gz: c3d20e0578b8f1656fafa94ebc97b38c1726b1382ee9d5c4cdfafcdaef9d92b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b80e5fa7efbdeed121f88a0e435b3d37c62f2c0cd0d0da49f69fe164b22a04eedca3b4682b8731e8181e80362ba4d8c596bd7eafd350e8973cab0e5ac88c2ab
|
7
|
+
data.tar.gz: 884a37c3363ebad19f5455de196ba2723710f04014947bf36eb1db8f67fdbbe03dc8073f3af47cafe5a9adb61a6db6804c38c8983be5cffee30b1a54a6534757
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Terminal Ruby API library
|
2
2
|
|
3
|
-
The Terminal Ruby library provides convenient access to the Terminal REST API from any Ruby 3.0+
|
3
|
+
The Terminal Ruby library provides convenient access to the Terminal REST API from any Ruby 3.0.0+
|
4
4
|
application.
|
5
5
|
|
6
6
|
It is generated with [Stainless](https://www.stainlessapi.com/).
|
@@ -9,23 +9,126 @@ module TerminalShop
|
|
9
9
|
# from whatwg fetch spec
|
10
10
|
MAX_REDIRECTS = 20
|
11
11
|
|
12
|
-
#
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
12
|
+
# rubocop:disable Style/MutableConstant
|
13
|
+
PLATFORM_HEADERS = {
|
14
|
+
"x-stainless-arch" => TerminalShop::Util.arch,
|
15
|
+
"x-stainless-lang" => "ruby",
|
16
|
+
"x-stainless-os" => TerminalShop::Util.os,
|
17
|
+
"x-stainless-package-version" => TerminalShop::VERSION,
|
18
|
+
"x-stainless-runtime" => ::RUBY_ENGINE,
|
19
|
+
"x-stainless-runtime-version" => ::RUBY_ENGINE_VERSION
|
20
|
+
}
|
21
|
+
# rubocop:enable Style/MutableConstant
|
22
|
+
|
23
|
+
class << self
|
24
|
+
# @private
|
25
|
+
#
|
26
|
+
# @param req [Hash{Symbol=>Object}]
|
27
|
+
#
|
28
|
+
# @raise [ArgumentError]
|
29
|
+
#
|
30
|
+
def validate!(req)
|
31
|
+
keys = [:method, :path, :query, :headers, :body, :unwrap, :page, :model, :options]
|
32
|
+
case req
|
33
|
+
in Hash
|
34
|
+
req.each_key do |k|
|
35
|
+
unless keys.include?(k)
|
36
|
+
raise ArgumentError.new("Request `req` keys must be one of #{keys}, got #{k.inspect}")
|
37
|
+
end
|
25
38
|
end
|
39
|
+
else
|
40
|
+
raise ArgumentError.new("Request `req` must be a Hash or RequestOptions, got #{req.inspect}")
|
26
41
|
end
|
27
|
-
|
28
|
-
|
42
|
+
end
|
43
|
+
|
44
|
+
# @private
|
45
|
+
#
|
46
|
+
# @param status [Integer]
|
47
|
+
# @param headers [Hash{String=>String}, Net::HTTPHeader]
|
48
|
+
#
|
49
|
+
# @return [Boolean]
|
50
|
+
#
|
51
|
+
def should_retry?(status, headers:)
|
52
|
+
coerced = TerminalShop::Util.coerce_boolean(headers["x-should-retry"])
|
53
|
+
case [coerced, status]
|
54
|
+
in [true | false, _]
|
55
|
+
coerced
|
56
|
+
in [_, 408 | 409 | 429 | (500..)]
|
57
|
+
# retry on:
|
58
|
+
# 408: timeouts
|
59
|
+
# 409: locks
|
60
|
+
# 429: rate limits
|
61
|
+
# 500+: unknown errors
|
62
|
+
true
|
63
|
+
else
|
64
|
+
false
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# @private
|
69
|
+
#
|
70
|
+
# @param request [Hash{Symbol=>Object}] .
|
71
|
+
#
|
72
|
+
# @option request [Symbol] :method
|
73
|
+
#
|
74
|
+
# @option request [URI::Generic] :url
|
75
|
+
#
|
76
|
+
# @option request [Hash{String=>String}] :headers
|
77
|
+
#
|
78
|
+
# @option request [Object] :body
|
79
|
+
#
|
80
|
+
# @option request [Integer] :max_retries
|
81
|
+
#
|
82
|
+
# @option request [Float] :timeout
|
83
|
+
#
|
84
|
+
# @param status [Integer]
|
85
|
+
#
|
86
|
+
# @param response_headers [Hash{String=>String}, Net::HTTPHeader]
|
87
|
+
#
|
88
|
+
# @return [Hash{Symbol=>Object}]
|
89
|
+
#
|
90
|
+
def follow_redirect(request, status:, response_headers:)
|
91
|
+
method, url, headers = request.fetch_values(:method, :url, :headers)
|
92
|
+
location =
|
93
|
+
TerminalShop::Util.suppress(ArgumentError) do
|
94
|
+
URI.join(url, response_headers["location"])
|
95
|
+
end
|
96
|
+
|
97
|
+
unless location
|
98
|
+
message = "Server responded with status #{status} but no valid location header."
|
99
|
+
raise TerminalShop::APIConnectionError.new(url: url, message: message)
|
100
|
+
end
|
101
|
+
|
102
|
+
request = {**request, url: location}
|
103
|
+
|
104
|
+
case [url.scheme, location.scheme]
|
105
|
+
in ["https", "http"]
|
106
|
+
message = "Tried to redirect to a insecure URL"
|
107
|
+
raise TerminalShop::APIConnectionError.new(url: url, message: message)
|
108
|
+
else
|
109
|
+
nil
|
110
|
+
end
|
111
|
+
|
112
|
+
# from whatwg fetch spec
|
113
|
+
case [status, method]
|
114
|
+
in [301 | 302, :post] | [303, _]
|
115
|
+
drop = %w[content-encoding content-language content-length content-location content-type]
|
116
|
+
request = {
|
117
|
+
**request,
|
118
|
+
method: method == :head ? :head : :get,
|
119
|
+
headers: headers.except(*drop),
|
120
|
+
body: nil
|
121
|
+
}
|
122
|
+
else
|
123
|
+
end
|
124
|
+
|
125
|
+
# from undici
|
126
|
+
if TerminalShop::Util.uri_origin(url) != TerminalShop::Util.uri_origin(location)
|
127
|
+
drop = %w[authorization cookie host proxy-authorization]
|
128
|
+
request = {**request, headers: request.fetch(:headers).except(*drop)}
|
129
|
+
end
|
130
|
+
|
131
|
+
request
|
29
132
|
end
|
30
133
|
end
|
31
134
|
|
@@ -55,13 +158,10 @@ module TerminalShop
|
|
55
158
|
)
|
56
159
|
@requester = TerminalShop::PooledNetRequester.new
|
57
160
|
@headers = TerminalShop::Util.normalized_headers(
|
161
|
+
self.class::PLATFORM_HEADERS,
|
58
162
|
{
|
59
|
-
"
|
60
|
-
"
|
61
|
-
"X-Stainless-Runtime" => RUBY_ENGINE,
|
62
|
-
"X-Stainless-Runtime-Version" => RUBY_ENGINE_VERSION,
|
63
|
-
"Content-Type" => "application/json",
|
64
|
-
"Accept" => "application/json"
|
163
|
+
"accept" => "application/json",
|
164
|
+
"content-type" => "application/json"
|
65
165
|
},
|
66
166
|
headers
|
67
167
|
)
|
@@ -126,10 +226,7 @@ module TerminalShop
|
|
126
226
|
|
127
227
|
path = TerminalShop::Util.interpolate_path(uninterpolated_path)
|
128
228
|
|
129
|
-
query = TerminalShop::Util.deep_merge(
|
130
|
-
req[:query].to_h,
|
131
|
-
opts[:extra_query].to_h
|
132
|
-
)
|
229
|
+
query = TerminalShop::Util.deep_merge(req[:query].to_h, opts[:extra_query].to_h)
|
133
230
|
|
134
231
|
headers = TerminalShop::Util.normalized_headers(
|
135
232
|
@headers,
|
@@ -163,34 +260,15 @@ module TerminalShop
|
|
163
260
|
TerminalShop::Util.deep_merge(*[req[:body], opts[:extra_body]].compact)
|
164
261
|
end
|
165
262
|
|
166
|
-
url = TerminalShop::Util.join_parsed_uri(@base_url, {**req, path: path, query: query})
|
167
263
|
headers, encoded = TerminalShop::Util.encode_content(headers, body)
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
#
|
177
|
-
# @return [Boolean]
|
178
|
-
#
|
179
|
-
private def should_retry?(status, headers:)
|
180
|
-
coerced = TerminalShop::Util.coerce_boolean(headers["x-should-retry"])
|
181
|
-
case [coerced, status]
|
182
|
-
in [true | false, _]
|
183
|
-
coerced
|
184
|
-
in [_, 408 | 409 | 429 | (500..)]
|
185
|
-
# retry on:
|
186
|
-
# 408: timeouts
|
187
|
-
# 409: locks
|
188
|
-
# 429: rate limits
|
189
|
-
# 500+: unknown errors
|
190
|
-
true
|
191
|
-
else
|
192
|
-
false
|
193
|
-
end
|
264
|
+
{
|
265
|
+
method: method,
|
266
|
+
url: TerminalShop::Util.join_parsed_uri(@base_url, {**req, path: path, query: query}),
|
267
|
+
headers: headers,
|
268
|
+
body: encoded,
|
269
|
+
max_retries: opts.fetch(:max_retries, @max_retries),
|
270
|
+
timeout: timeout
|
271
|
+
}
|
194
272
|
end
|
195
273
|
|
196
274
|
# @private
|
@@ -218,72 +296,6 @@ module TerminalShop
|
|
218
296
|
(@initial_retry_delay * scale * jitter).clamp(0, @max_retry_delay)
|
219
297
|
end
|
220
298
|
|
221
|
-
# @private
|
222
|
-
#
|
223
|
-
# @param request [Hash{Symbol=>Object}] .
|
224
|
-
#
|
225
|
-
# @option request [Symbol] :method
|
226
|
-
#
|
227
|
-
# @option request [URI::Generic] :url
|
228
|
-
#
|
229
|
-
# @option request [Hash{String=>String}] :headers
|
230
|
-
#
|
231
|
-
# @option request [Object] :body
|
232
|
-
#
|
233
|
-
# @option request [Integer] :max_retries
|
234
|
-
#
|
235
|
-
# @option request [Float] :timeout
|
236
|
-
#
|
237
|
-
# @param status [Integer]
|
238
|
-
#
|
239
|
-
# @param location_header [String]
|
240
|
-
#
|
241
|
-
# @return [Hash{Symbol=>Object}]
|
242
|
-
#
|
243
|
-
private def follow_redirect(request, status:, location_header:)
|
244
|
-
method, url, headers = request.fetch_values(:method, :url, :headers)
|
245
|
-
location =
|
246
|
-
TerminalShop::Util.suppress(ArgumentError) do
|
247
|
-
URI.join(url, location_header)
|
248
|
-
end
|
249
|
-
|
250
|
-
unless location
|
251
|
-
message = "Server responded with status #{status} but no valid location header."
|
252
|
-
raise TerminalShop::APIConnectionError.new(url: url, message: message)
|
253
|
-
end
|
254
|
-
|
255
|
-
request = {**request, url: location}
|
256
|
-
|
257
|
-
case [url.scheme, location.scheme]
|
258
|
-
in ["https", "http"]
|
259
|
-
message = "Tried to redirect to a insecure URL"
|
260
|
-
raise TerminalShop::APIConnectionError.new(url: url, message: message)
|
261
|
-
else
|
262
|
-
nil
|
263
|
-
end
|
264
|
-
|
265
|
-
# from whatwg fetch spec
|
266
|
-
case [status, method]
|
267
|
-
in [301 | 302, :post] | [303, _]
|
268
|
-
drop = %w[content-encoding content-language content-length content-location content-type]
|
269
|
-
request = {
|
270
|
-
**request,
|
271
|
-
method: method == :head ? :head : :get,
|
272
|
-
headers: headers.except(*drop),
|
273
|
-
body: nil
|
274
|
-
}
|
275
|
-
else
|
276
|
-
end
|
277
|
-
|
278
|
-
# from undici
|
279
|
-
if TerminalShop::Util.uri_origin(url) != TerminalShop::Util.uri_origin(location)
|
280
|
-
drop = %w[authorization cookie host proxy-authorization]
|
281
|
-
request = {**request, headers: request.fetch(:headers).except(*drop)}
|
282
|
-
end
|
283
|
-
|
284
|
-
request
|
285
|
-
end
|
286
|
-
|
287
299
|
# @private
|
288
300
|
#
|
289
301
|
# @param request [Hash{Symbol=>Object}] .
|
@@ -307,31 +319,39 @@ module TerminalShop
|
|
307
319
|
# @param send_retry_header [Boolean]
|
308
320
|
#
|
309
321
|
# @raise [TerminalShop::APIError]
|
310
|
-
# @return [Net::HTTPResponse]
|
322
|
+
# @return [Array(Net::HTTPResponse, Enumerable)]
|
311
323
|
#
|
312
324
|
private def send_request(request, redirect_count:, retry_count:, send_retry_header:)
|
313
|
-
url, headers,
|
314
|
-
|
325
|
+
url, headers, max_retries, timeout = request.fetch_values(:url, :headers, :max_retries, :timeout)
|
326
|
+
input = {**request.except(:timeout), deadline: TerminalShop::Util.monotonic_secs + timeout}
|
315
327
|
|
316
328
|
if send_retry_header
|
317
329
|
headers["x-stainless-retry-count"] = retry_count.to_s
|
318
330
|
end
|
319
331
|
|
320
332
|
begin
|
321
|
-
response = @requester.execute(
|
333
|
+
response, stream = @requester.execute(input)
|
322
334
|
status = Integer(response.code)
|
323
335
|
rescue TerminalShop::APIConnectionError => e
|
324
336
|
status = e
|
325
337
|
end
|
326
338
|
|
339
|
+
# normally we want to drain the response body and reuse the HTTP session by clearing the socket buffers
|
340
|
+
# unless we hit a server error
|
341
|
+
srv_fault = (500...).include?(status)
|
342
|
+
|
327
343
|
case status
|
328
344
|
in ..299
|
329
|
-
response
|
330
|
-
in 300..399 if redirect_count >= MAX_REDIRECTS
|
331
|
-
message = "Failed to complete the request within #{MAX_REDIRECTS} redirects."
|
345
|
+
[response, stream]
|
346
|
+
in 300..399 if redirect_count >= self.class::MAX_REDIRECTS
|
347
|
+
message = "Failed to complete the request within #{self.class::MAX_REDIRECTS} redirects."
|
348
|
+
|
349
|
+
stream.each { next }
|
332
350
|
raise TerminalShop::APIConnectionError.new(url: url, message: message)
|
333
351
|
in 300..399
|
334
|
-
request = follow_redirect(request, status: status,
|
352
|
+
request = self.class.follow_redirect(request, status: status, response_headers: response)
|
353
|
+
|
354
|
+
stream.each { next }
|
335
355
|
send_request(
|
336
356
|
request,
|
337
357
|
redirect_count: redirect_count + 1,
|
@@ -340,18 +360,24 @@ module TerminalShop
|
|
340
360
|
)
|
341
361
|
in TerminalShop::APIConnectionError if retry_count >= max_retries
|
342
362
|
raise status
|
343
|
-
in (400..) if
|
344
|
-
|
363
|
+
in (400..) if retry_count >= max_retries || (response && !self.class.should_retry?(
|
364
|
+
status,
|
365
|
+
headers: response
|
366
|
+
))
|
367
|
+
decoded = TerminalShop::Util.decode_content(response, stream: stream, suppress_error: true)
|
345
368
|
|
369
|
+
stream.each { srv_fault ? break : next }
|
346
370
|
raise TerminalShop::APIStatusError.for(
|
347
371
|
url: url,
|
348
372
|
status: status,
|
349
|
-
body:
|
373
|
+
body: decoded,
|
350
374
|
request: nil,
|
351
375
|
response: response
|
352
376
|
)
|
353
377
|
in (400..) | TerminalShop::APIConnectionError
|
354
378
|
delay = retry_delay(response, retry_count: retry_count)
|
379
|
+
|
380
|
+
stream&.each { srv_fault ? break : next }
|
355
381
|
sleep(delay)
|
356
382
|
|
357
383
|
send_request(
|
@@ -385,17 +411,19 @@ module TerminalShop
|
|
385
411
|
#
|
386
412
|
# @option req [TerminalShop::RequestOptions, Hash{Symbol=>Object}, nil] :options
|
387
413
|
#
|
388
|
-
# @param
|
414
|
+
# @param headers [Hash{String=>String}, Net::HTTPHeader]
|
415
|
+
#
|
416
|
+
# @param stream [Enumerable]
|
389
417
|
#
|
390
418
|
# @return [Object]
|
391
419
|
#
|
392
|
-
private def parse_response(req,
|
393
|
-
|
394
|
-
unwrapped = TerminalShop::Util.dig(
|
420
|
+
private def parse_response(req, headers:, stream:)
|
421
|
+
decoded = TerminalShop::Util.decode_content(headers, stream: stream)
|
422
|
+
unwrapped = TerminalShop::Util.dig(decoded, req[:unwrap])
|
395
423
|
|
396
424
|
case [req[:page], req.fetch(:model, TerminalShop::Unknown)]
|
397
425
|
in [Class => page, _]
|
398
|
-
page.new(client: self, req: req, headers:
|
426
|
+
page.new(client: self, req: req, headers: headers, unwrapped: unwrapped)
|
399
427
|
in [nil, Class | TerminalShop::Converter => model]
|
400
428
|
TerminalShop::Converter.coerce(model, unwrapped)
|
401
429
|
in [nil, nil]
|
@@ -433,17 +461,17 @@ module TerminalShop
|
|
433
461
|
self.class.validate!(req)
|
434
462
|
opts = req[:options].to_h
|
435
463
|
TerminalShop::RequestOptions.validate!(opts)
|
436
|
-
request = build_request(req, opts)
|
464
|
+
request = build_request(req.except(:options), opts)
|
437
465
|
|
438
466
|
# Don't send the current retry count in the headers if the caller modified the header defaults.
|
439
467
|
send_retry_header = request.fetch(:headers)["x-stainless-retry-count"] == "0"
|
440
|
-
response = send_request(
|
468
|
+
response, stream = send_request(
|
441
469
|
request,
|
442
470
|
redirect_count: 0,
|
443
471
|
retry_count: 0,
|
444
472
|
send_retry_header: send_retry_header
|
445
473
|
)
|
446
|
-
parse_response(req, response)
|
474
|
+
parse_response(req, headers: response, stream: stream)
|
447
475
|
end
|
448
476
|
|
449
477
|
# @return [String]
|
@@ -148,6 +148,8 @@ module TerminalShop
|
|
148
148
|
[true, Integer(value), 1]
|
149
149
|
in [-> { _1 <= Float }, Numeric]
|
150
150
|
[true, Float(value), 1]
|
151
|
+
in [-> { _1 <= Symbol }, String]
|
152
|
+
[true, value.to_sym, 1]
|
151
153
|
in [-> { _1 <= String }, Symbol]
|
152
154
|
[true, value.to_s, 1]
|
153
155
|
in [-> { _1 <= Date || _1 <= Time }, String]
|
@@ -367,7 +369,6 @@ module TerminalShop
|
|
367
369
|
# @abstract
|
368
370
|
#
|
369
371
|
class Union
|
370
|
-
extend TerminalShop::Extern
|
371
372
|
extend TerminalShop::Converter
|
372
373
|
|
373
374
|
# @private
|
@@ -502,9 +503,7 @@ module TerminalShop
|
|
502
503
|
end
|
503
504
|
end
|
504
505
|
|
505
|
-
# rubocop:disable Style/NumberedParametersLimit
|
506
506
|
_, variant = matches.sort! { _2.first <=> _1.first }.find { |score,| !score.zero? }
|
507
|
-
# rubocop:enable Style/NumberedParametersLimit
|
508
507
|
variant.nil? ? value : TerminalShop::Converter.coerce(variant, value)
|
509
508
|
end
|
510
509
|
|
@@ -840,7 +839,6 @@ module TerminalShop
|
|
840
839
|
# @abstract
|
841
840
|
#
|
842
841
|
class BaseModel
|
843
|
-
extend TerminalShop::Extern
|
844
842
|
extend TerminalShop::Converter
|
845
843
|
|
846
844
|
# @private
|
@@ -6,8 +6,6 @@ module TerminalShop
|
|
6
6
|
# @abstract
|
7
7
|
#
|
8
8
|
module BasePage
|
9
|
-
# rubocop:disable Lint/UnusedMethodArgument
|
10
|
-
|
11
9
|
# @return [Boolean]
|
12
10
|
#
|
13
11
|
def next_page? = (raise NotImplementedError)
|
@@ -21,7 +19,7 @@ module TerminalShop
|
|
21
19
|
#
|
22
20
|
# @return [void]
|
23
21
|
#
|
24
|
-
def auto_paging_each(&
|
22
|
+
def auto_paging_each(&) = (raise NotImplementedError)
|
25
23
|
|
26
24
|
# @return [Enumerable]
|
27
25
|
#
|
@@ -34,11 +32,9 @@ module TerminalShop
|
|
34
32
|
# #
|
35
33
|
# # @param client [TerminalShop::BaseClient]
|
36
34
|
# # @param req [Hash{Symbol=>Object}]
|
37
|
-
# # @param headers [Hash{String=>String}]
|
35
|
+
# # @param headers [Hash{String=>String}, Net::HTTPHeader]
|
38
36
|
# # @param unwrapped [Object]
|
39
37
|
# #
|
40
38
|
# def initialize(client:, req:, headers:, unwrapped:); end
|
41
|
-
|
42
|
-
# rubocop:enable Lint/UnusedMethodArgument
|
43
39
|
end
|
44
40
|
end
|
data/lib/terminal-shop/client.rb
CHANGED
@@ -2,17 +2,6 @@
|
|
2
2
|
|
3
3
|
module TerminalShop
|
4
4
|
module Models
|
5
|
-
# @example
|
6
|
-
# ```ruby
|
7
|
-
# address_api => {
|
8
|
-
# id: String,
|
9
|
-
# city: String,
|
10
|
-
# country: String,
|
11
|
-
# name: String,
|
12
|
-
# street1: String,
|
13
|
-
# **_
|
14
|
-
# }
|
15
|
-
# ```
|
16
5
|
class AddressAPI < TerminalShop::BaseModel
|
17
6
|
# @!attribute id
|
18
7
|
# Unique object identifier. The format and length of IDs may change over time.
|
@@ -2,12 +2,6 @@
|
|
2
2
|
|
3
3
|
module TerminalShop
|
4
4
|
module Models
|
5
|
-
# @example
|
6
|
-
# ```ruby
|
7
|
-
# address_list_response => {
|
8
|
-
# data: -> { TerminalShop::ArrayOf[TerminalShop::Models::AddressAPI] === _1 }
|
9
|
-
# }
|
10
|
-
# ```
|
11
5
|
class AddressListResponse < TerminalShop::BaseModel
|
12
6
|
# @!attribute data
|
13
7
|
# Shipping addresses.
|
@@ -2,14 +2,6 @@
|
|
2
2
|
|
3
3
|
module TerminalShop
|
4
4
|
module Models
|
5
|
-
# @example
|
6
|
-
# ```ruby
|
7
|
-
# app_api => {
|
8
|
-
# id: String,
|
9
|
-
# name: String,
|
10
|
-
# redirect_uri: String
|
11
|
-
# }
|
12
|
-
# ```
|
13
5
|
class AppAPI < TerminalShop::BaseModel
|
14
6
|
# @!attribute id
|
15
7
|
# Unique object identifier. The format and length of IDs may change over time.
|
@@ -29,14 +21,21 @@ module TerminalShop
|
|
29
21
|
# @return [String]
|
30
22
|
required :redirect_uri, String, api_name: :redirectURI
|
31
23
|
|
24
|
+
# @!attribute secret
|
25
|
+
# OAuth 2.0 client secret of the app (obfuscated).
|
26
|
+
#
|
27
|
+
# @return [String]
|
28
|
+
required :secret, String
|
29
|
+
|
32
30
|
# @!parse
|
33
31
|
# # A Terminal App used for configuring an OAuth 2.0 client.
|
34
32
|
# #
|
35
33
|
# # @param id [String]
|
36
34
|
# # @param name [String]
|
37
35
|
# # @param redirect_uri [String]
|
36
|
+
# # @param secret [String]
|
38
37
|
# #
|
39
|
-
# def initialize(id:, name:, redirect_uri:, **) = super
|
38
|
+
# def initialize(id:, name:, redirect_uri:, secret:, **) = super
|
40
39
|
|
41
40
|
# def initialize: (Hash | TerminalShop::BaseModel) -> void
|
42
41
|
end
|
@@ -2,12 +2,6 @@
|
|
2
2
|
|
3
3
|
module TerminalShop
|
4
4
|
module Models
|
5
|
-
# @example
|
6
|
-
# ```ruby
|
7
|
-
# app_create_response => {
|
8
|
-
# data: TerminalShop::Models::AppCreateResponse::Data
|
9
|
-
# }
|
10
|
-
# ```
|
11
5
|
class AppCreateResponse < TerminalShop::BaseModel
|
12
6
|
# @!attribute data
|
13
7
|
#
|
@@ -21,13 +15,6 @@ module TerminalShop
|
|
21
15
|
|
22
16
|
# def initialize: (Hash | TerminalShop::BaseModel) -> void
|
23
17
|
|
24
|
-
# @example
|
25
|
-
# ```ruby
|
26
|
-
# data => {
|
27
|
-
# id: String,
|
28
|
-
# secret: String
|
29
|
-
# }
|
30
|
-
# ```
|
31
18
|
class Data < TerminalShop::BaseModel
|
32
19
|
# @!attribute id
|
33
20
|
# OAuth 2.0 client ID.
|
@@ -2,12 +2,6 @@
|
|
2
2
|
|
3
3
|
module TerminalShop
|
4
4
|
module Models
|
5
|
-
# @example
|
6
|
-
# ```ruby
|
7
|
-
# app_get_response => {
|
8
|
-
# data: TerminalShop::Models::AppAPI
|
9
|
-
# }
|
10
|
-
# ```
|
11
5
|
class AppGetResponse < TerminalShop::BaseModel
|
12
6
|
# @!attribute data
|
13
7
|
# A Terminal App used for configuring an OAuth 2.0 client.
|
@@ -2,12 +2,6 @@
|
|
2
2
|
|
3
3
|
module TerminalShop
|
4
4
|
module Models
|
5
|
-
# @example
|
6
|
-
# ```ruby
|
7
|
-
# app_list_response => {
|
8
|
-
# data: -> { TerminalShop::ArrayOf[TerminalShop::Models::AppAPI] === _1 }
|
9
|
-
# }
|
10
|
-
# ```
|
11
5
|
class AppListResponse < TerminalShop::BaseModel
|
12
6
|
# @!attribute data
|
13
7
|
# List of apps.
|