terminal-shop 0.1.0.pre.alpha.15 → 1.0.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/lib/terminal-shop/base_client.rb +35 -55
- data/lib/terminal-shop/base_model.rb +9 -0
- data/lib/terminal-shop/base_page.rb +2 -2
- data/lib/terminal-shop/client.rb +1 -1
- data/lib/terminal-shop/errors.rb +3 -2
- data/lib/terminal-shop/models/address_get_params.rb +18 -0
- data/lib/terminal-shop/models/address_get_response.rb +20 -0
- data/lib/terminal-shop/models/app_create_params.rb +14 -2
- data/lib/terminal-shop/models/card_get_params.rb +18 -0
- data/lib/terminal-shop/models/card_get_response.rb +20 -0
- data/lib/terminal-shop/models/product.rb +63 -42
- data/lib/terminal-shop/models/product_get_params.rb +18 -0
- data/lib/terminal-shop/models/product_get_response.rb +20 -0
- data/lib/terminal-shop/models/profile_update_params.rb +7 -9
- data/lib/terminal-shop/models/subscription.rb +0 -10
- data/lib/terminal-shop/models/subscription_get_params.rb +18 -0
- data/lib/terminal-shop/models/subscription_get_response.rb +20 -0
- data/lib/terminal-shop/pooled_net_requester.rb +14 -9
- data/lib/terminal-shop/resources/address.rb +19 -0
- data/lib/terminal-shop/resources/app.rb +2 -6
- data/lib/terminal-shop/resources/card.rb +19 -0
- data/lib/terminal-shop/resources/product.rb +19 -0
- data/lib/terminal-shop/resources/profile.rb +3 -3
- data/lib/terminal-shop/resources/subscription.rb +19 -0
- data/lib/terminal-shop/util.rb +135 -1
- data/lib/terminal-shop/version.rb +1 -1
- data/lib/terminal-shop.rb +9 -1
- data/rbi/lib/terminal-shop/base_client.rbi +6 -14
- data/rbi/lib/terminal-shop/base_page.rbi +2 -2
- data/rbi/lib/terminal-shop/errors.rbi +3 -2
- data/rbi/lib/terminal-shop/models/address_get_params.rbi +18 -0
- data/rbi/lib/terminal-shop/models/address_get_response.rbi +23 -0
- data/rbi/lib/terminal-shop/models/app_create_params.rbi +29 -4
- data/rbi/lib/terminal-shop/models/card_get_params.rbi +18 -0
- data/rbi/lib/terminal-shop/models/card_get_response.rbi +23 -0
- data/rbi/lib/terminal-shop/models/product.rbi +70 -24
- data/rbi/lib/terminal-shop/models/product_get_params.rbi +18 -0
- data/rbi/lib/terminal-shop/models/product_get_response.rbi +23 -0
- data/rbi/lib/terminal-shop/models/profile_update_params.rbi +8 -13
- data/rbi/lib/terminal-shop/models/subscription_get_params.rbi +18 -0
- data/rbi/lib/terminal-shop/models/subscription_get_response.rbi +23 -0
- data/rbi/lib/terminal-shop/resources/address.rbi +10 -0
- data/rbi/lib/terminal-shop/resources/app.rbi +1 -3
- data/rbi/lib/terminal-shop/resources/card.rbi +10 -0
- data/rbi/lib/terminal-shop/resources/product.rbi +10 -0
- data/rbi/lib/terminal-shop/resources/profile.rbi +3 -3
- data/rbi/lib/terminal-shop/resources/subscription.rbi +10 -0
- data/rbi/lib/terminal-shop/util.rbi +29 -0
- data/rbi/lib/terminal-shop/version.rbi +1 -1
- data/sig/terminal-shop/base_client.rbs +3 -7
- data/sig/terminal-shop/base_page.rbs +1 -1
- data/sig/terminal-shop/errors.rbs +2 -1
- data/sig/terminal-shop/models/address_get_params.rbs +19 -0
- data/sig/terminal-shop/models/address_get_response.rbs +18 -0
- data/sig/terminal-shop/models/app_create_params.rbs +12 -3
- data/sig/terminal-shop/models/card_get_params.rbs +18 -0
- data/sig/terminal-shop/models/card_get_response.rbs +18 -0
- data/sig/terminal-shop/models/product.rbs +52 -17
- data/sig/terminal-shop/models/product_get_params.rbs +19 -0
- data/sig/terminal-shop/models/product_get_response.rbs +18 -0
- data/sig/terminal-shop/models/profile_update_params.rbs +5 -5
- data/sig/terminal-shop/models/subscription_get_params.rbs +19 -0
- data/sig/terminal-shop/models/subscription_get_response.rbs +19 -0
- data/sig/terminal-shop/resources/address.rbs +10 -0
- data/sig/terminal-shop/resources/app.rbs +0 -2
- data/sig/terminal-shop/resources/card.rbs +10 -0
- data/sig/terminal-shop/resources/product.rbs +10 -0
- data/sig/terminal-shop/resources/profile.rbs +3 -4
- data/sig/terminal-shop/resources/subscription.rbs +11 -0
- data/sig/terminal-shop/util.rbs +19 -0
- data/sig/terminal-shop/version.rbs +1 -1
- metadata +28 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd3056ca007a3676c2e4252263dc95c4dd9be5f7d3ab71d38d103b1f3aaa7959
|
4
|
+
data.tar.gz: a691229e58ecdd3d431ccd2fcd1b3c4b18a19d4d16384f849b18778667913e96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac245487879b8e27da712e0c72574951d025f9ecd0f79973fce79062932dcae12abc5a9fce374d33556d013ae555751277737ee700825b79e9aea896b9ac392a
|
7
|
+
data.tar.gz: 457fcb73956a5e4091fa6f4fbd25b78c1e06b6dcf770e4a6df3667d51e328b010eed9f1260a4c44bf4501c30725cf8d72ae5fe739e733d8740ba9a90a321a9ba
|
@@ -28,7 +28,7 @@ module TerminalShop
|
|
28
28
|
# @raise [ArgumentError]
|
29
29
|
#
|
30
30
|
def validate!(req)
|
31
|
-
keys = [:method, :path, :query, :headers, :body, :unwrap, :page, :model, :options]
|
31
|
+
keys = [:method, :path, :query, :headers, :body, :unwrap, :page, :stream, :model, :options]
|
32
32
|
case req
|
33
33
|
in Hash
|
34
34
|
req.each_key do |k|
|
@@ -201,6 +201,8 @@ module TerminalShop
|
|
201
201
|
#
|
202
202
|
# @option req [Class, nil] :page
|
203
203
|
#
|
204
|
+
# @option req [Class, nil] :stream
|
205
|
+
#
|
204
206
|
# @option req [TerminalShop::Converter, Class, nil] :model
|
205
207
|
#
|
206
208
|
# @param opts [Hash{Symbol=>Object}] .
|
@@ -244,8 +246,8 @@ module TerminalShop
|
|
244
246
|
end
|
245
247
|
|
246
248
|
timeout = opts.fetch(:timeout, @timeout).to_f.clamp((0..))
|
247
|
-
unless headers.key?("x-stainless-
|
248
|
-
headers["x-stainless-
|
249
|
+
unless headers.key?("x-stainless-timeout") || timeout.zero?
|
250
|
+
headers["x-stainless-timeout"] = timeout.to_s
|
249
251
|
end
|
250
252
|
|
251
253
|
headers.reject! { |_, v| v.to_s.empty? }
|
@@ -319,7 +321,7 @@ module TerminalShop
|
|
319
321
|
# @param send_retry_header [Boolean]
|
320
322
|
#
|
321
323
|
# @raise [TerminalShop::APIError]
|
322
|
-
# @return [Array(Net::HTTPResponse, Enumerable)]
|
324
|
+
# @return [Array(Integer, Net::HTTPResponse, Enumerable)]
|
323
325
|
#
|
324
326
|
private def send_request(request, redirect_count:, retry_count:, send_retry_header:)
|
325
327
|
url, headers, max_retries, timeout = request.fetch_values(:url, :headers, :max_retries, :timeout)
|
@@ -342,7 +344,7 @@ module TerminalShop
|
|
342
344
|
|
343
345
|
case status
|
344
346
|
in ..299
|
345
|
-
[response, stream]
|
347
|
+
[status, response, stream]
|
346
348
|
in 300..399 if redirect_count >= self.class::MAX_REDIRECTS
|
347
349
|
message = "Failed to complete the request within #{self.class::MAX_REDIRECTS} redirects."
|
348
350
|
|
@@ -360,13 +362,15 @@ module TerminalShop
|
|
360
362
|
)
|
361
363
|
in TerminalShop::APIConnectionError if retry_count >= max_retries
|
362
364
|
raise status
|
363
|
-
in (400..) if retry_count >= max_retries ||
|
364
|
-
status,
|
365
|
-
headers: response
|
366
|
-
))
|
365
|
+
in (400..) if retry_count >= max_retries || !self.class.should_retry?(status, headers: response)
|
367
366
|
decoded = TerminalShop::Util.decode_content(response, stream: stream, suppress_error: true)
|
368
367
|
|
369
|
-
|
368
|
+
if srv_fault
|
369
|
+
TerminalShop::Util.close_fused!(stream)
|
370
|
+
else
|
371
|
+
stream.each { next }
|
372
|
+
end
|
373
|
+
|
370
374
|
raise TerminalShop::APIStatusError.for(
|
371
375
|
url: url,
|
372
376
|
status: status,
|
@@ -377,7 +381,11 @@ module TerminalShop
|
|
377
381
|
in (400..) | TerminalShop::APIConnectionError
|
378
382
|
delay = retry_delay(response, retry_count: retry_count)
|
379
383
|
|
380
|
-
|
384
|
+
if srv_fault
|
385
|
+
TerminalShop::Util.close_fused!(stream)
|
386
|
+
else
|
387
|
+
stream&.each { next }
|
388
|
+
end
|
381
389
|
sleep(delay)
|
382
390
|
|
383
391
|
send_request(
|
@@ -389,48 +397,6 @@ module TerminalShop
|
|
389
397
|
end
|
390
398
|
end
|
391
399
|
|
392
|
-
# @private
|
393
|
-
#
|
394
|
-
# @param req [Hash{Symbol=>Object}] .
|
395
|
-
#
|
396
|
-
# @option req [Symbol] :method
|
397
|
-
#
|
398
|
-
# @option req [String, Array<String>] :path
|
399
|
-
#
|
400
|
-
# @option req [Hash{String=>Array<String>, String, nil}, nil] :query
|
401
|
-
#
|
402
|
-
# @option req [Hash{String=>String, Integer, Array<String, Integer, nil>, nil}, nil] :headers
|
403
|
-
#
|
404
|
-
# @option req [Object, nil] :body
|
405
|
-
#
|
406
|
-
# @option req [Symbol, nil] :unwrap
|
407
|
-
#
|
408
|
-
# @option req [Class, nil] :page
|
409
|
-
#
|
410
|
-
# @option req [TerminalShop::Converter, Class, nil] :model
|
411
|
-
#
|
412
|
-
# @option req [TerminalShop::RequestOptions, Hash{Symbol=>Object}, nil] :options
|
413
|
-
#
|
414
|
-
# @param headers [Hash{String=>String}, Net::HTTPHeader]
|
415
|
-
#
|
416
|
-
# @param stream [Enumerable]
|
417
|
-
#
|
418
|
-
# @return [Object]
|
419
|
-
#
|
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])
|
423
|
-
|
424
|
-
case [req[:page], req.fetch(:model, TerminalShop::Unknown)]
|
425
|
-
in [Class => page, _]
|
426
|
-
page.new(client: self, req: req, headers: headers, unwrapped: unwrapped)
|
427
|
-
in [nil, Class | TerminalShop::Converter => model]
|
428
|
-
TerminalShop::Converter.coerce(model, unwrapped)
|
429
|
-
in [nil, nil]
|
430
|
-
unwrapped
|
431
|
-
end
|
432
|
-
end
|
433
|
-
|
434
400
|
# Execute the request specified by `req`. This is the method that all resource
|
435
401
|
# methods call into.
|
436
402
|
#
|
@@ -450,6 +416,8 @@ module TerminalShop
|
|
450
416
|
#
|
451
417
|
# @option req [Class, nil] :page
|
452
418
|
#
|
419
|
+
# @option req [Class, nil] :stream
|
420
|
+
#
|
453
421
|
# @option req [TerminalShop::Converter, Class, nil] :model
|
454
422
|
#
|
455
423
|
# @option req [TerminalShop::RequestOptions, Hash{Symbol=>Object}, nil] :options
|
@@ -459,19 +427,31 @@ module TerminalShop
|
|
459
427
|
#
|
460
428
|
def request(req)
|
461
429
|
self.class.validate!(req)
|
430
|
+
model = req.fetch(:model) { TerminalShop::Unknown }
|
462
431
|
opts = req[:options].to_h
|
463
432
|
TerminalShop::RequestOptions.validate!(opts)
|
464
433
|
request = build_request(req.except(:options), opts)
|
434
|
+
url = request.fetch(:url)
|
465
435
|
|
466
436
|
# Don't send the current retry count in the headers if the caller modified the header defaults.
|
467
437
|
send_retry_header = request.fetch(:headers)["x-stainless-retry-count"] == "0"
|
468
|
-
response, stream = send_request(
|
438
|
+
status, response, stream = send_request(
|
469
439
|
request,
|
470
440
|
redirect_count: 0,
|
471
441
|
retry_count: 0,
|
472
442
|
send_retry_header: send_retry_header
|
473
443
|
)
|
474
|
-
|
444
|
+
|
445
|
+
decoded = TerminalShop::Util.decode_content(response, stream: stream)
|
446
|
+
case req
|
447
|
+
in { stream: Class => st }
|
448
|
+
st.new(model: model, url: url, status: status, response: response, messages: decoded)
|
449
|
+
in { page: Class => page }
|
450
|
+
page.new(client: self, req: req, headers: response, page_data: decoded)
|
451
|
+
else
|
452
|
+
unwrapped = TerminalShop::Util.dig(decoded, req[:unwrap])
|
453
|
+
TerminalShop::Converter.coerce(model, unwrapped)
|
454
|
+
end
|
475
455
|
end
|
476
456
|
|
477
457
|
# @return [String]
|
@@ -839,6 +839,15 @@ module TerminalShop
|
|
839
839
|
#
|
840
840
|
# @abstract
|
841
841
|
#
|
842
|
+
# @example
|
843
|
+
# ```ruby
|
844
|
+
# # `product_api` is a `TerminalShop::Models::ProductAPI`
|
845
|
+
# product_api => {
|
846
|
+
# id: id,
|
847
|
+
# description: description,
|
848
|
+
# name: name
|
849
|
+
# }
|
850
|
+
# ```
|
842
851
|
class BaseModel
|
843
852
|
extend TerminalShop::Converter
|
844
853
|
|
@@ -33,8 +33,8 @@ module TerminalShop
|
|
33
33
|
# # @param client [TerminalShop::BaseClient]
|
34
34
|
# # @param req [Hash{Symbol=>Object}]
|
35
35
|
# # @param headers [Hash{String=>String}, Net::HTTPHeader]
|
36
|
-
# # @param
|
36
|
+
# # @param page_data [Object]
|
37
37
|
# #
|
38
|
-
# def initialize(client:, req:, headers:,
|
38
|
+
# def initialize(client:, req:, headers:, page_data:); end
|
39
39
|
end
|
40
40
|
end
|
data/lib/terminal-shop/client.rb
CHANGED
@@ -65,7 +65,7 @@ module TerminalShop
|
|
65
65
|
private def auth_headers
|
66
66
|
return {} if @bearer_token.nil?
|
67
67
|
|
68
|
-
{"
|
68
|
+
{"authorization" => "Bearer #{@bearer_token}"}
|
69
69
|
end
|
70
70
|
|
71
71
|
# Creates and returns a new client for interacting with the API.
|
data/lib/terminal-shop/errors.rb
CHANGED
@@ -99,11 +99,12 @@ module TerminalShop
|
|
99
99
|
# @param body [Object, nil]
|
100
100
|
# @param request [nil]
|
101
101
|
# @param response [nil]
|
102
|
+
# @param message [String, nil]
|
102
103
|
#
|
103
104
|
# @return [TerminalShop::APIStatusError]
|
104
105
|
#
|
105
|
-
def self.for(url:, status:, body:, request:, response:)
|
106
|
-
kwargs = {url: url, status: status, body: body, request: request, response: response}
|
106
|
+
def self.for(url:, status:, body:, request:, response:, message: nil)
|
107
|
+
kwargs = {url: url, status: status, body: body, request: request, response: response, message: message}
|
107
108
|
|
108
109
|
case status
|
109
110
|
in 400
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TerminalShop
|
4
|
+
module Models
|
5
|
+
class AddressGetParams < TerminalShop::BaseModel
|
6
|
+
# @!parse
|
7
|
+
# extend TerminalShop::RequestParameters::Converter
|
8
|
+
include TerminalShop::RequestParameters
|
9
|
+
|
10
|
+
# @!parse
|
11
|
+
# # @param request_options [TerminalShop::RequestOptions, Hash{Symbol=>Object}]
|
12
|
+
# #
|
13
|
+
# def initialize(request_options: {}, **) = super
|
14
|
+
|
15
|
+
# def initialize: (Hash | TerminalShop::BaseModel) -> void
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TerminalShop
|
4
|
+
module Models
|
5
|
+
class AddressGetResponse < TerminalShop::BaseModel
|
6
|
+
# @!attribute data
|
7
|
+
# Physical address associated with a Terminal shop user.
|
8
|
+
#
|
9
|
+
# @return [TerminalShop::Models::AddressAPI]
|
10
|
+
required :data, -> { TerminalShop::Models::AddressAPI }
|
11
|
+
|
12
|
+
# @!parse
|
13
|
+
# # @param data [TerminalShop::Models::AddressAPI]
|
14
|
+
# #
|
15
|
+
# def initialize(data:, **) = super
|
16
|
+
|
17
|
+
# def initialize: (Hash | TerminalShop::BaseModel) -> void
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -2,15 +2,27 @@
|
|
2
2
|
|
3
3
|
module TerminalShop
|
4
4
|
module Models
|
5
|
-
class AppCreateParams < TerminalShop::
|
5
|
+
class AppCreateParams < TerminalShop::BaseModel
|
6
6
|
# @!parse
|
7
7
|
# extend TerminalShop::RequestParameters::Converter
|
8
8
|
include TerminalShop::RequestParameters
|
9
9
|
|
10
|
+
# @!attribute name
|
11
|
+
#
|
12
|
+
# @return [String]
|
13
|
+
required :name, String
|
14
|
+
|
15
|
+
# @!attribute redirect_uri
|
16
|
+
#
|
17
|
+
# @return [String]
|
18
|
+
required :redirect_uri, String, api_name: :redirectURI
|
19
|
+
|
10
20
|
# @!parse
|
21
|
+
# # @param name [String]
|
22
|
+
# # @param redirect_uri [String]
|
11
23
|
# # @param request_options [TerminalShop::RequestOptions, Hash{Symbol=>Object}]
|
12
24
|
# #
|
13
|
-
# def initialize(request_options: {}, **) = super
|
25
|
+
# def initialize(name:, redirect_uri:, request_options: {}, **) = super
|
14
26
|
|
15
27
|
# def initialize: (Hash | TerminalShop::BaseModel) -> void
|
16
28
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TerminalShop
|
4
|
+
module Models
|
5
|
+
class CardGetParams < TerminalShop::BaseModel
|
6
|
+
# @!parse
|
7
|
+
# extend TerminalShop::RequestParameters::Converter
|
8
|
+
include TerminalShop::RequestParameters
|
9
|
+
|
10
|
+
# @!parse
|
11
|
+
# # @param request_options [TerminalShop::RequestOptions, Hash{Symbol=>Object}]
|
12
|
+
# #
|
13
|
+
# def initialize(request_options: {}, **) = super
|
14
|
+
|
15
|
+
# def initialize: (Hash | TerminalShop::BaseModel) -> void
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TerminalShop
|
4
|
+
module Models
|
5
|
+
class CardGetResponse < TerminalShop::BaseModel
|
6
|
+
# @!attribute data
|
7
|
+
# Credit card used for payments in the Terminal shop.
|
8
|
+
#
|
9
|
+
# @return [TerminalShop::Models::CardAPI]
|
10
|
+
required :data, -> { TerminalShop::Models::CardAPI }
|
11
|
+
|
12
|
+
# @!parse
|
13
|
+
# # @param data [TerminalShop::Models::CardAPI]
|
14
|
+
# #
|
15
|
+
# def initialize(data:, **) = super
|
16
|
+
|
17
|
+
# def initialize: (Hash | TerminalShop::BaseModel) -> void
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -15,11 +15,6 @@ module TerminalShop
|
|
15
15
|
# @return [String]
|
16
16
|
required :description, String
|
17
17
|
|
18
|
-
# @!attribute filters
|
19
|
-
#
|
20
|
-
# @return [Array<Symbol, TerminalShop::Models::ProductAPI::Filter>]
|
21
|
-
required :filters, -> { TerminalShop::ArrayOf[enum: TerminalShop::Models::ProductAPI::Filter] }
|
22
|
-
|
23
18
|
# @!attribute name
|
24
19
|
# Name of the product.
|
25
20
|
#
|
@@ -55,11 +50,11 @@ module TerminalShop
|
|
55
50
|
# @!attribute [r] tags
|
56
51
|
# Tags for the product.
|
57
52
|
#
|
58
|
-
# @return [
|
59
|
-
optional :tags, TerminalShop::
|
53
|
+
# @return [TerminalShop::Models::ProductAPI::Tags, nil]
|
54
|
+
optional :tags, -> { TerminalShop::Models::ProductAPI::Tags }
|
60
55
|
|
61
56
|
# @!parse
|
62
|
-
# # @return [
|
57
|
+
# # @return [TerminalShop::Models::ProductAPI::Tags]
|
63
58
|
# attr_writer :tags
|
64
59
|
|
65
60
|
# @!parse
|
@@ -67,31 +62,22 @@ module TerminalShop
|
|
67
62
|
# #
|
68
63
|
# # @param id [String]
|
69
64
|
# # @param description [String]
|
70
|
-
# # @param filters [Array<Symbol, TerminalShop::Models::ProductAPI::Filter>]
|
71
65
|
# # @param name [String]
|
72
66
|
# # @param variants [Array<TerminalShop::Models::ProductVariant>]
|
73
67
|
# # @param order [Integer]
|
74
68
|
# # @param subscription [Symbol, TerminalShop::Models::ProductAPI::Subscription]
|
75
|
-
# # @param tags [
|
69
|
+
# # @param tags [TerminalShop::Models::ProductAPI::Tags]
|
76
70
|
# #
|
77
|
-
# def initialize(id:, description:,
|
71
|
+
# def initialize(id:, description:, name:, variants:, order: nil, subscription: nil, tags: nil, **) = super
|
78
72
|
|
79
73
|
# def initialize: (Hash | TerminalShop::BaseModel) -> void
|
80
74
|
|
81
75
|
# @abstract
|
82
76
|
#
|
83
|
-
#
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
# # ...
|
88
|
-
# in :na
|
89
|
-
# # ...
|
90
|
-
# end
|
91
|
-
# ```
|
92
|
-
class Filter < TerminalShop::Enum
|
93
|
-
EU = :eu
|
94
|
-
NA = :na
|
77
|
+
# Whether the product must be or can be subscribed to.
|
78
|
+
class Subscription < TerminalShop::Enum
|
79
|
+
ALLOWED = :allowed
|
80
|
+
REQUIRED = :required
|
95
81
|
|
96
82
|
finalize!
|
97
83
|
|
@@ -101,29 +87,64 @@ module TerminalShop
|
|
101
87
|
# def self.values; end
|
102
88
|
end
|
103
89
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
# ```ruby
|
110
|
-
# case subscription
|
111
|
-
# in :allowed
|
112
|
-
# # ...
|
113
|
-
# in :required
|
114
|
-
# # ...
|
115
|
-
# end
|
116
|
-
# ```
|
117
|
-
class Subscription < TerminalShop::Enum
|
118
|
-
ALLOWED = :allowed
|
119
|
-
REQUIRED = :required
|
90
|
+
class Tags < TerminalShop::BaseModel
|
91
|
+
# @!attribute [r] app
|
92
|
+
#
|
93
|
+
# @return [String, nil]
|
94
|
+
optional :app, String
|
120
95
|
|
121
|
-
|
96
|
+
# @!parse
|
97
|
+
# # @return [String]
|
98
|
+
# attr_writer :app
|
99
|
+
|
100
|
+
# @!attribute [r] color
|
101
|
+
#
|
102
|
+
# @return [String, nil]
|
103
|
+
optional :color, String
|
122
104
|
|
123
105
|
# @!parse
|
124
|
-
# # @return [
|
106
|
+
# # @return [String]
|
107
|
+
# attr_writer :color
|
108
|
+
|
109
|
+
# @!attribute [r] featured
|
110
|
+
#
|
111
|
+
# @return [Boolean, nil]
|
112
|
+
optional :featured, TerminalShop::BooleanModel
|
113
|
+
|
114
|
+
# @!parse
|
115
|
+
# # @return [Boolean]
|
116
|
+
# attr_writer :featured
|
117
|
+
|
118
|
+
# @!attribute [r] market_eu
|
119
|
+
#
|
120
|
+
# @return [Boolean, nil]
|
121
|
+
optional :market_eu, TerminalShop::BooleanModel
|
122
|
+
|
123
|
+
# @!parse
|
124
|
+
# # @return [Boolean]
|
125
|
+
# attr_writer :market_eu
|
126
|
+
|
127
|
+
# @!attribute [r] market_na
|
128
|
+
#
|
129
|
+
# @return [Boolean, nil]
|
130
|
+
optional :market_na, TerminalShop::BooleanModel
|
131
|
+
|
132
|
+
# @!parse
|
133
|
+
# # @return [Boolean]
|
134
|
+
# attr_writer :market_na
|
135
|
+
|
136
|
+
# @!parse
|
137
|
+
# # Tags for the product.
|
125
138
|
# #
|
126
|
-
#
|
139
|
+
# # @param app [String]
|
140
|
+
# # @param color [String]
|
141
|
+
# # @param featured [Boolean]
|
142
|
+
# # @param market_eu [Boolean]
|
143
|
+
# # @param market_na [Boolean]
|
144
|
+
# #
|
145
|
+
# def initialize(app: nil, color: nil, featured: nil, market_eu: nil, market_na: nil, **) = super
|
146
|
+
|
147
|
+
# def initialize: (Hash | TerminalShop::BaseModel) -> void
|
127
148
|
end
|
128
149
|
end
|
129
150
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TerminalShop
|
4
|
+
module Models
|
5
|
+
class ProductGetParams < TerminalShop::BaseModel
|
6
|
+
# @!parse
|
7
|
+
# extend TerminalShop::RequestParameters::Converter
|
8
|
+
include TerminalShop::RequestParameters
|
9
|
+
|
10
|
+
# @!parse
|
11
|
+
# # @param request_options [TerminalShop::RequestOptions, Hash{Symbol=>Object}]
|
12
|
+
# #
|
13
|
+
# def initialize(request_options: {}, **) = super
|
14
|
+
|
15
|
+
# def initialize: (Hash | TerminalShop::BaseModel) -> void
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TerminalShop
|
4
|
+
module Models
|
5
|
+
class ProductGetResponse < TerminalShop::BaseModel
|
6
|
+
# @!attribute data
|
7
|
+
# Product sold in the Terminal shop.
|
8
|
+
#
|
9
|
+
# @return [TerminalShop::Models::ProductAPI]
|
10
|
+
required :data, -> { TerminalShop::Models::ProductAPI }
|
11
|
+
|
12
|
+
# @!parse
|
13
|
+
# # @param data [TerminalShop::Models::ProductAPI]
|
14
|
+
# #
|
15
|
+
# def initialize(data:, **) = super
|
16
|
+
|
17
|
+
# def initialize: (Hash | TerminalShop::BaseModel) -> void
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -8,23 +8,21 @@ module TerminalShop
|
|
8
8
|
include TerminalShop::RequestParameters
|
9
9
|
|
10
10
|
# @!attribute email
|
11
|
-
# Email address of the user.
|
12
11
|
#
|
13
|
-
# @return [String
|
14
|
-
|
12
|
+
# @return [String]
|
13
|
+
required :email, String
|
15
14
|
|
16
15
|
# @!attribute name
|
17
|
-
# Name of the user.
|
18
16
|
#
|
19
|
-
# @return [String
|
20
|
-
|
17
|
+
# @return [String]
|
18
|
+
required :name, String
|
21
19
|
|
22
20
|
# @!parse
|
23
|
-
# # @param email [String
|
24
|
-
# # @param name [String
|
21
|
+
# # @param email [String]
|
22
|
+
# # @param name [String]
|
25
23
|
# # @param request_options [TerminalShop::RequestOptions, Hash{Symbol=>Object}]
|
26
24
|
# #
|
27
|
-
# def initialize(email
|
25
|
+
# def initialize(email:, name:, request_options: {}, **) = super
|
28
26
|
|
29
27
|
# def initialize: (Hash | TerminalShop::BaseModel) -> void
|
30
28
|
end
|
@@ -71,16 +71,6 @@ module TerminalShop
|
|
71
71
|
# @abstract
|
72
72
|
#
|
73
73
|
# Schedule of the subscription.
|
74
|
-
#
|
75
|
-
# @example
|
76
|
-
# ```ruby
|
77
|
-
# case schedule
|
78
|
-
# in TerminalShop::Models::SubscriptionAPI::Schedule::Fixed
|
79
|
-
# # ...
|
80
|
-
# in TerminalShop::Models::SubscriptionAPI::Schedule::Weekly
|
81
|
-
# # ...
|
82
|
-
# end
|
83
|
-
# ```
|
84
74
|
class Schedule < TerminalShop::Union
|
85
75
|
variant -> { TerminalShop::Models::SubscriptionAPI::Schedule::Fixed }
|
86
76
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TerminalShop
|
4
|
+
module Models
|
5
|
+
class SubscriptionGetParams < TerminalShop::BaseModel
|
6
|
+
# @!parse
|
7
|
+
# extend TerminalShop::RequestParameters::Converter
|
8
|
+
include TerminalShop::RequestParameters
|
9
|
+
|
10
|
+
# @!parse
|
11
|
+
# # @param request_options [TerminalShop::RequestOptions, Hash{Symbol=>Object}]
|
12
|
+
# #
|
13
|
+
# def initialize(request_options: {}, **) = super
|
14
|
+
|
15
|
+
# def initialize: (Hash | TerminalShop::BaseModel) -> void
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TerminalShop
|
4
|
+
module Models
|
5
|
+
class SubscriptionGetResponse < TerminalShop::BaseModel
|
6
|
+
# @!attribute data
|
7
|
+
# Subscription to a Terminal shop product.
|
8
|
+
#
|
9
|
+
# @return [TerminalShop::Models::SubscriptionAPI]
|
10
|
+
required :data, -> { TerminalShop::Models::SubscriptionAPI }
|
11
|
+
|
12
|
+
# @!parse
|
13
|
+
# # @param data [TerminalShop::Models::SubscriptionAPI]
|
14
|
+
# #
|
15
|
+
# def initialize(data:, **) = super
|
16
|
+
|
17
|
+
# def initialize: (Hash | TerminalShop::BaseModel) -> void
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -131,16 +131,23 @@ module TerminalShop
|
|
131
131
|
req = self.class.build_request(request)
|
132
132
|
|
133
133
|
eof = false
|
134
|
+
finished = false
|
134
135
|
enum = Enumerator.new do |y|
|
135
136
|
with_pool(url) do |conn|
|
137
|
+
next if finished
|
138
|
+
|
136
139
|
self.class.calibrate_socket_timeout(conn, deadline)
|
137
140
|
conn.start unless conn.started?
|
138
141
|
|
139
142
|
self.class.calibrate_socket_timeout(conn, deadline)
|
140
143
|
conn.request(req) do |rsp|
|
141
144
|
y << [conn, rsp]
|
145
|
+
break if finished
|
146
|
+
|
142
147
|
rsp.read_body do |bytes|
|
143
148
|
y << bytes
|
149
|
+
break if finished
|
150
|
+
|
144
151
|
self.class.calibrate_socket_timeout(conn, deadline)
|
145
152
|
end
|
146
153
|
eof = true
|
@@ -148,16 +155,14 @@ module TerminalShop
|
|
148
155
|
end
|
149
156
|
end
|
150
157
|
|
151
|
-
# need to protect the `Enumerator` against `#.rewind`
|
152
|
-
fused = false
|
153
158
|
conn, response = enum.next
|
154
|
-
body =
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
conn.finish if !eof && conn
|
159
|
+
body = TerminalShop::Util.fused_enum(enum) do
|
160
|
+
finished = true
|
161
|
+
tap do
|
162
|
+
enum.next
|
163
|
+
rescue StopIteration
|
164
|
+
end
|
165
|
+
conn.finish if !eof && conn&.started?
|
161
166
|
end
|
162
167
|
[response, (response.body = body)]
|
163
168
|
end
|