terminal-shop 0.1.0.pre.alpha.15 → 1.1.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 +27 -19
- data/lib/terminal-shop/base_client.rb +35 -55
- data/lib/terminal-shop/base_model.rb +457 -438
- 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/cart.rb +35 -2
- data/lib/terminal-shop/models/cart_convert_params.rb +11 -1
- data/lib/terminal-shop/models/cart_redeem_gift_card_params.rb +24 -0
- data/lib/terminal-shop/models/cart_redeem_gift_card_response.rb +48 -0
- data/lib/terminal-shop/models/cart_remove_gift_card_params.rb +18 -0
- data/lib/terminal-shop/models/cart_remove_gift_card_response.rb +19 -0
- data/lib/terminal-shop/models/product.rb +72 -46
- 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/cart.rb +43 -1
- 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 +13 -1
- data/rbi/lib/terminal-shop/base_client.rbi +29 -35
- data/rbi/lib/terminal-shop/base_model.rbi +235 -217
- data/rbi/lib/terminal-shop/base_page.rbi +2 -2
- data/rbi/lib/terminal-shop/client.rbi +2 -2
- data/rbi/lib/terminal-shop/errors.rbi +11 -10
- data/rbi/lib/terminal-shop/models/address.rbi +2 -2
- data/rbi/lib/terminal-shop/models/address_create_params.rbi +3 -13
- data/rbi/lib/terminal-shop/models/address_create_response.rbi +2 -2
- data/rbi/lib/terminal-shop/models/address_delete_params.rbi +5 -2
- data/rbi/lib/terminal-shop/models/address_delete_response.rbi +2 -2
- data/rbi/lib/terminal-shop/models/address_get_params.rbi +21 -0
- data/rbi/lib/terminal-shop/models/address_get_response.rbi +23 -0
- data/rbi/lib/terminal-shop/models/address_list_params.rbi +5 -2
- data/rbi/lib/terminal-shop/models/address_list_response.rbi +2 -2
- data/rbi/lib/terminal-shop/models/app.rbi +2 -2
- data/rbi/lib/terminal-shop/models/app_create_params.rbi +29 -4
- data/rbi/lib/terminal-shop/models/app_create_response.rbi +4 -4
- data/rbi/lib/terminal-shop/models/app_delete_params.rbi +5 -2
- data/rbi/lib/terminal-shop/models/app_delete_response.rbi +2 -2
- data/rbi/lib/terminal-shop/models/app_get_params.rbi +5 -2
- data/rbi/lib/terminal-shop/models/app_get_response.rbi +2 -2
- data/rbi/lib/terminal-shop/models/app_list_params.rbi +5 -2
- data/rbi/lib/terminal-shop/models/app_list_response.rbi +2 -2
- data/rbi/lib/terminal-shop/models/card.rbi +4 -4
- data/rbi/lib/terminal-shop/models/card_collect_params.rbi +5 -2
- data/rbi/lib/terminal-shop/models/card_collect_response.rbi +4 -4
- data/rbi/lib/terminal-shop/models/card_create_params.rbi +2 -2
- data/rbi/lib/terminal-shop/models/card_create_response.rbi +2 -2
- data/rbi/lib/terminal-shop/models/card_delete_params.rbi +5 -2
- data/rbi/lib/terminal-shop/models/card_delete_response.rbi +2 -2
- data/rbi/lib/terminal-shop/models/card_get_params.rbi +21 -0
- data/rbi/lib/terminal-shop/models/card_get_response.rbi +23 -0
- data/rbi/lib/terminal-shop/models/card_list_params.rbi +5 -2
- data/rbi/lib/terminal-shop/models/card_list_response.rbi +2 -2
- data/rbi/lib/terminal-shop/models/cart.rbi +45 -9
- data/rbi/lib/terminal-shop/models/cart_convert_params.rbi +17 -3
- data/rbi/lib/terminal-shop/models/cart_convert_response.rbi +2 -2
- data/rbi/lib/terminal-shop/models/cart_get_params.rbi +5 -2
- data/rbi/lib/terminal-shop/models/cart_get_response.rbi +2 -2
- data/rbi/lib/terminal-shop/models/cart_redeem_gift_card_params.rbi +32 -0
- data/rbi/lib/terminal-shop/models/cart_redeem_gift_card_response.rbi +66 -0
- data/rbi/lib/terminal-shop/models/cart_remove_gift_card_params.rbi +21 -0
- data/rbi/lib/terminal-shop/models/cart_remove_gift_card_response.rbi +23 -0
- data/rbi/lib/terminal-shop/models/cart_set_address_params.rbi +2 -2
- data/rbi/lib/terminal-shop/models/cart_set_address_response.rbi +2 -2
- data/rbi/lib/terminal-shop/models/cart_set_card_params.rbi +2 -2
- data/rbi/lib/terminal-shop/models/cart_set_card_response.rbi +2 -2
- data/rbi/lib/terminal-shop/models/cart_set_item_params.rbi +2 -2
- data/rbi/lib/terminal-shop/models/cart_set_item_response.rbi +2 -2
- data/rbi/lib/terminal-shop/models/email_create_params.rbi +2 -2
- data/rbi/lib/terminal-shop/models/email_create_response.rbi +2 -2
- data/rbi/lib/terminal-shop/models/order.rbi +10 -10
- data/rbi/lib/terminal-shop/models/order_create_params.rbi +2 -2
- data/rbi/lib/terminal-shop/models/order_create_response.rbi +2 -2
- data/rbi/lib/terminal-shop/models/order_get_params.rbi +5 -2
- data/rbi/lib/terminal-shop/models/order_get_response.rbi +2 -2
- data/rbi/lib/terminal-shop/models/order_list_params.rbi +5 -2
- data/rbi/lib/terminal-shop/models/order_list_response.rbi +2 -2
- data/rbi/lib/terminal-shop/models/product.rbi +88 -27
- data/rbi/lib/terminal-shop/models/product_get_params.rbi +21 -0
- data/rbi/lib/terminal-shop/models/product_get_response.rbi +23 -0
- data/rbi/lib/terminal-shop/models/product_list_params.rbi +5 -2
- data/rbi/lib/terminal-shop/models/product_list_response.rbi +2 -2
- data/rbi/lib/terminal-shop/models/product_variant.rbi +2 -2
- data/rbi/lib/terminal-shop/models/profile.rbi +4 -4
- data/rbi/lib/terminal-shop/models/profile_me_params.rbi +5 -2
- data/rbi/lib/terminal-shop/models/profile_me_response.rbi +2 -2
- data/rbi/lib/terminal-shop/models/profile_update_params.rbi +9 -14
- data/rbi/lib/terminal-shop/models/profile_update_response.rbi +2 -2
- data/rbi/lib/terminal-shop/models/subscription.rbi +15 -13
- data/rbi/lib/terminal-shop/models/subscription_create_params.rbi +5 -2
- data/rbi/lib/terminal-shop/models/subscription_create_response.rbi +2 -2
- data/rbi/lib/terminal-shop/models/subscription_delete_params.rbi +5 -2
- data/rbi/lib/terminal-shop/models/subscription_delete_response.rbi +2 -2
- data/rbi/lib/terminal-shop/models/subscription_get_params.rbi +21 -0
- data/rbi/lib/terminal-shop/models/subscription_get_response.rbi +23 -0
- data/rbi/lib/terminal-shop/models/subscription_list_params.rbi +5 -2
- data/rbi/lib/terminal-shop/models/subscription_list_response.rbi +2 -2
- data/rbi/lib/terminal-shop/models/token.rbi +2 -2
- data/rbi/lib/terminal-shop/models/token_create_params.rbi +5 -2
- data/rbi/lib/terminal-shop/models/token_create_response.rbi +4 -4
- data/rbi/lib/terminal-shop/models/token_delete_params.rbi +5 -2
- data/rbi/lib/terminal-shop/models/token_delete_response.rbi +2 -2
- data/rbi/lib/terminal-shop/models/token_get_params.rbi +5 -2
- data/rbi/lib/terminal-shop/models/token_get_response.rbi +2 -2
- data/rbi/lib/terminal-shop/models/token_list_params.rbi +5 -2
- data/rbi/lib/terminal-shop/models/token_list_response.rbi +2 -2
- data/rbi/lib/terminal-shop/models/view_init_params.rbi +5 -2
- data/rbi/lib/terminal-shop/models/view_init_response.rbi +5 -15
- data/rbi/lib/terminal-shop/pooled_net_requester.rbi +12 -10
- data/rbi/lib/terminal-shop/request_options.rbi +4 -0
- data/rbi/lib/terminal-shop/resources/address.rbi +12 -2
- data/rbi/lib/terminal-shop/resources/app.rbi +3 -5
- data/rbi/lib/terminal-shop/resources/card.rbi +12 -2
- data/rbi/lib/terminal-shop/resources/cart.rbi +24 -4
- data/rbi/lib/terminal-shop/resources/email.rbi +2 -2
- data/rbi/lib/terminal-shop/resources/order.rbi +2 -2
- data/rbi/lib/terminal-shop/resources/product.rbi +12 -2
- data/rbi/lib/terminal-shop/resources/profile.rbi +5 -5
- data/rbi/lib/terminal-shop/resources/subscription.rbi +12 -2
- data/rbi/lib/terminal-shop/resources/token.rbi +2 -2
- data/rbi/lib/terminal-shop/resources/view.rbi +2 -2
- data/rbi/lib/terminal-shop/util.rbi +153 -104
- 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/cart.rbs +27 -2
- data/sig/terminal-shop/models/cart_convert_params.rbs +10 -2
- data/sig/terminal-shop/models/cart_redeem_gift_card_params.rbs +25 -0
- data/sig/terminal-shop/models/cart_redeem_gift_card_response.rbs +47 -0
- data/sig/terminal-shop/models/cart_remove_gift_card_params.rbs +19 -0
- data/sig/terminal-shop/models/cart_remove_gift_card_response.rbs +18 -0
- data/sig/terminal-shop/models/product.rbs +58 -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/request_options.rbs +4 -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/cart.rbs +20 -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 +40 -4
@@ -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
|
@@ -74,6 +74,25 @@ module TerminalShop
|
|
74
74
|
)
|
75
75
|
end
|
76
76
|
|
77
|
+
# Get the shipping address with the given ID.
|
78
|
+
#
|
79
|
+
# @param id [String] ID of the shipping address to get.
|
80
|
+
#
|
81
|
+
# @param params [TerminalShop::Models::AddressGetParams, Hash{Symbol=>Object}] .
|
82
|
+
#
|
83
|
+
# @option params [TerminalShop::RequestOptions, Hash{Symbol=>Object}, nil] :request_options
|
84
|
+
#
|
85
|
+
# @return [TerminalShop::Models::AddressGetResponse]
|
86
|
+
#
|
87
|
+
def get(id, params = {})
|
88
|
+
@client.request(
|
89
|
+
method: :get,
|
90
|
+
path: ["address/%0s", id],
|
91
|
+
model: TerminalShop::Models::AddressGetResponse,
|
92
|
+
options: params[:request_options]
|
93
|
+
)
|
94
|
+
end
|
95
|
+
|
77
96
|
# @param client [TerminalShop::Client]
|
78
97
|
#
|
79
98
|
def initialize(client:)
|
@@ -7,13 +7,9 @@ module TerminalShop
|
|
7
7
|
#
|
8
8
|
# @param params [TerminalShop::Models::AppCreateParams, Hash{Symbol=>Object}] .
|
9
9
|
#
|
10
|
-
# @option params [String] :
|
10
|
+
# @option params [String] :name
|
11
11
|
#
|
12
|
-
# @option params [String] :
|
13
|
-
#
|
14
|
-
# @option params [String] :redirect_uri Redirect URI of the app.
|
15
|
-
#
|
16
|
-
# @option params [String] :secret OAuth 2.0 client secret of the app (obfuscated).
|
12
|
+
# @option params [String] :redirect_uri
|
17
13
|
#
|
18
14
|
# @option params [TerminalShop::RequestOptions, Hash{Symbol=>Object}, nil] :request_options
|
19
15
|
#
|
@@ -79,6 +79,25 @@ module TerminalShop
|
|
79
79
|
)
|
80
80
|
end
|
81
81
|
|
82
|
+
# Get a credit card by ID associated with the current user.
|
83
|
+
#
|
84
|
+
# @param id [String] ID of the card to get.
|
85
|
+
#
|
86
|
+
# @param params [TerminalShop::Models::CardGetParams, Hash{Symbol=>Object}] .
|
87
|
+
#
|
88
|
+
# @option params [TerminalShop::RequestOptions, Hash{Symbol=>Object}, nil] :request_options
|
89
|
+
#
|
90
|
+
# @return [TerminalShop::Models::CardGetResponse]
|
91
|
+
#
|
92
|
+
def get(id, params = {})
|
93
|
+
@client.request(
|
94
|
+
method: :get,
|
95
|
+
path: ["card/%0s", id],
|
96
|
+
model: TerminalShop::Models::CardGetResponse,
|
97
|
+
options: params[:request_options]
|
98
|
+
)
|
99
|
+
end
|
100
|
+
|
82
101
|
# @param client [TerminalShop::Client]
|
83
102
|
#
|
84
103
|
def initialize(client:)
|
@@ -7,16 +7,20 @@ module TerminalShop
|
|
7
7
|
#
|
8
8
|
# @param params [TerminalShop::Models::CartConvertParams, Hash{Symbol=>Object}] .
|
9
9
|
#
|
10
|
+
# @option params [String] :recipient_email
|
11
|
+
#
|
10
12
|
# @option params [TerminalShop::RequestOptions, Hash{Symbol=>Object}, nil] :request_options
|
11
13
|
#
|
12
14
|
# @return [TerminalShop::Models::CartConvertResponse]
|
13
15
|
#
|
14
16
|
def convert(params = {})
|
17
|
+
parsed, options = TerminalShop::Models::CartConvertParams.dump_request(params)
|
15
18
|
@client.request(
|
16
19
|
method: :post,
|
17
20
|
path: "cart/convert",
|
21
|
+
body: parsed,
|
18
22
|
model: TerminalShop::Models::CartConvertResponse,
|
19
|
-
options:
|
23
|
+
options: options
|
20
24
|
)
|
21
25
|
end
|
22
26
|
|
@@ -37,6 +41,44 @@ module TerminalShop
|
|
37
41
|
)
|
38
42
|
end
|
39
43
|
|
44
|
+
# Apply a gift card to the current user's cart.
|
45
|
+
#
|
46
|
+
# @param params [TerminalShop::Models::CartRedeemGiftCardParams, Hash{Symbol=>Object}] .
|
47
|
+
#
|
48
|
+
# @option params [String] :gift_card_id
|
49
|
+
#
|
50
|
+
# @option params [TerminalShop::RequestOptions, Hash{Symbol=>Object}, nil] :request_options
|
51
|
+
#
|
52
|
+
# @return [TerminalShop::Models::CartRedeemGiftCardResponse]
|
53
|
+
#
|
54
|
+
def redeem_gift_card(params)
|
55
|
+
parsed, options = TerminalShop::Models::CartRedeemGiftCardParams.dump_request(params)
|
56
|
+
@client.request(
|
57
|
+
method: :put,
|
58
|
+
path: "cart/gift-card",
|
59
|
+
body: parsed,
|
60
|
+
model: TerminalShop::Models::CartRedeemGiftCardResponse,
|
61
|
+
options: options
|
62
|
+
)
|
63
|
+
end
|
64
|
+
|
65
|
+
# Remove the gift card from the current user's cart.
|
66
|
+
#
|
67
|
+
# @param params [TerminalShop::Models::CartRemoveGiftCardParams, Hash{Symbol=>Object}] .
|
68
|
+
#
|
69
|
+
# @option params [TerminalShop::RequestOptions, Hash{Symbol=>Object}, nil] :request_options
|
70
|
+
#
|
71
|
+
# @return [TerminalShop::Models::CartRemoveGiftCardResponse]
|
72
|
+
#
|
73
|
+
def remove_gift_card(params = {})
|
74
|
+
@client.request(
|
75
|
+
method: :delete,
|
76
|
+
path: "cart/gift-card",
|
77
|
+
model: TerminalShop::Models::CartRemoveGiftCardResponse,
|
78
|
+
options: params[:request_options]
|
79
|
+
)
|
80
|
+
end
|
81
|
+
|
40
82
|
# Set the shipping address for the current user's cart.
|
41
83
|
#
|
42
84
|
# @param params [TerminalShop::Models::CartSetAddressParams, Hash{Symbol=>Object}] .
|
@@ -20,6 +20,25 @@ module TerminalShop
|
|
20
20
|
)
|
21
21
|
end
|
22
22
|
|
23
|
+
# Get a product by ID from the Terminal shop.
|
24
|
+
#
|
25
|
+
# @param id [String] ID of the product to get.
|
26
|
+
#
|
27
|
+
# @param params [TerminalShop::Models::ProductGetParams, Hash{Symbol=>Object}] .
|
28
|
+
#
|
29
|
+
# @option params [TerminalShop::RequestOptions, Hash{Symbol=>Object}, nil] :request_options
|
30
|
+
#
|
31
|
+
# @return [TerminalShop::Models::ProductGetResponse]
|
32
|
+
#
|
33
|
+
def get(id, params = {})
|
34
|
+
@client.request(
|
35
|
+
method: :get,
|
36
|
+
path: ["product/%0s", id],
|
37
|
+
model: TerminalShop::Models::ProductGetResponse,
|
38
|
+
options: params[:request_options]
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
23
42
|
# @param client [TerminalShop::Client]
|
24
43
|
#
|
25
44
|
def initialize(client:)
|
@@ -7,15 +7,15 @@ module TerminalShop
|
|
7
7
|
#
|
8
8
|
# @param params [TerminalShop::Models::ProfileUpdateParams, Hash{Symbol=>Object}] .
|
9
9
|
#
|
10
|
-
# @option params [String
|
10
|
+
# @option params [String] :email
|
11
11
|
#
|
12
|
-
# @option params [String
|
12
|
+
# @option params [String] :name
|
13
13
|
#
|
14
14
|
# @option params [TerminalShop::RequestOptions, Hash{Symbol=>Object}, nil] :request_options
|
15
15
|
#
|
16
16
|
# @return [TerminalShop::Models::ProfileUpdateResponse]
|
17
17
|
#
|
18
|
-
def update(params
|
18
|
+
def update(params)
|
19
19
|
parsed, options = TerminalShop::Models::ProfileUpdateParams.dump_request(params)
|
20
20
|
@client.request(
|
21
21
|
method: :put,
|
@@ -72,6 +72,25 @@ module TerminalShop
|
|
72
72
|
)
|
73
73
|
end
|
74
74
|
|
75
|
+
# Get the subscription with the given ID.
|
76
|
+
#
|
77
|
+
# @param id [String] ID of the subscription to get.
|
78
|
+
#
|
79
|
+
# @param params [TerminalShop::Models::SubscriptionGetParams, Hash{Symbol=>Object}] .
|
80
|
+
#
|
81
|
+
# @option params [TerminalShop::RequestOptions, Hash{Symbol=>Object}, nil] :request_options
|
82
|
+
#
|
83
|
+
# @return [TerminalShop::Models::SubscriptionGetResponse]
|
84
|
+
#
|
85
|
+
def get(id, params = {})
|
86
|
+
@client.request(
|
87
|
+
method: :get,
|
88
|
+
path: ["subscription/%0s", id],
|
89
|
+
model: TerminalShop::Models::SubscriptionGetResponse,
|
90
|
+
options: params[:request_options]
|
91
|
+
)
|
92
|
+
end
|
93
|
+
|
75
94
|
# @param client [TerminalShop::Client]
|
76
95
|
#
|
77
96
|
def initialize(client:)
|
data/lib/terminal-shop/util.rb
CHANGED
@@ -496,7 +496,7 @@ module TerminalShop
|
|
496
496
|
#
|
497
497
|
def decode_content(headers, stream:, suppress_error: false)
|
498
498
|
case headers["content-type"]
|
499
|
-
in %r{^application/json}
|
499
|
+
in %r{^application/(?:vnd\.api\+)?json}
|
500
500
|
json = stream.to_a.join
|
501
501
|
begin
|
502
502
|
JSON.parse(json, symbolize_names: true)
|
@@ -504,6 +504,11 @@ module TerminalShop
|
|
504
504
|
raise e unless suppress_error
|
505
505
|
json
|
506
506
|
end
|
507
|
+
in %r{^text/event-stream}
|
508
|
+
lines = decode_lines(stream)
|
509
|
+
decode_sse(lines)
|
510
|
+
in %r{^application/(?:x-)?jsonl}
|
511
|
+
decode_lines(stream)
|
507
512
|
in %r{^text/}
|
508
513
|
stream.to_a.join
|
509
514
|
else
|
@@ -512,6 +517,135 @@ module TerminalShop
|
|
512
517
|
end
|
513
518
|
end
|
514
519
|
end
|
520
|
+
|
521
|
+
class << self
|
522
|
+
# @private
|
523
|
+
#
|
524
|
+
# https://doc.rust-lang.org/std/iter/trait.FusedIterator.html
|
525
|
+
#
|
526
|
+
# @param enum [Enumerable]
|
527
|
+
# @param close [Proc]
|
528
|
+
#
|
529
|
+
# @return [Enumerable]
|
530
|
+
#
|
531
|
+
def fused_enum(enum, &close)
|
532
|
+
fused = false
|
533
|
+
iter = Enumerator.new do |y|
|
534
|
+
next if fused
|
535
|
+
|
536
|
+
fused = true
|
537
|
+
loop { y << enum.next }
|
538
|
+
ensure
|
539
|
+
close&.call
|
540
|
+
close = nil
|
541
|
+
end
|
542
|
+
|
543
|
+
iter.define_singleton_method(:rewind) do
|
544
|
+
fused = true
|
545
|
+
self
|
546
|
+
end
|
547
|
+
iter
|
548
|
+
end
|
549
|
+
|
550
|
+
# @private
|
551
|
+
#
|
552
|
+
# @param enum [Enumerable, nil]
|
553
|
+
#
|
554
|
+
def close_fused!(enum)
|
555
|
+
return unless enum.is_a?(Enumerator)
|
556
|
+
|
557
|
+
# rubocop:disable Lint/UnreachableLoop
|
558
|
+
enum.rewind.each { break }
|
559
|
+
# rubocop:enable Lint/UnreachableLoop
|
560
|
+
end
|
561
|
+
|
562
|
+
# @private
|
563
|
+
#
|
564
|
+
# @param enum [Enumerable, nil]
|
565
|
+
# @param blk [Proc]
|
566
|
+
#
|
567
|
+
def chain_fused(enum, &blk)
|
568
|
+
iter = Enumerator.new { blk.call(_1) }
|
569
|
+
fused_enum(iter) { close_fused!(enum) }
|
570
|
+
end
|
571
|
+
end
|
572
|
+
|
573
|
+
class << self
|
574
|
+
# @private
|
575
|
+
#
|
576
|
+
# @param enum [Enumerable]
|
577
|
+
#
|
578
|
+
# @return [Enumerable]
|
579
|
+
#
|
580
|
+
def decode_lines(enum)
|
581
|
+
re = /(\r\n|\r|\n)/
|
582
|
+
buffer = String.new.b
|
583
|
+
cr_seen = nil
|
584
|
+
|
585
|
+
chain_fused(enum) do |y|
|
586
|
+
enum.each do |row|
|
587
|
+
buffer << row
|
588
|
+
while (match = re.match(buffer, cr_seen.to_i))
|
589
|
+
case [match.captures.first, cr_seen]
|
590
|
+
in ["\r", nil]
|
591
|
+
cr_seen = match.end(1)
|
592
|
+
next
|
593
|
+
in ["\r" | "\r\n", Integer]
|
594
|
+
y << buffer.slice!(..(cr_seen.pred))
|
595
|
+
else
|
596
|
+
y << buffer.slice!(..(match.end(1).pred))
|
597
|
+
end
|
598
|
+
cr_seen = nil
|
599
|
+
end
|
600
|
+
end
|
601
|
+
|
602
|
+
y << buffer.slice!(..(cr_seen.pred)) unless cr_seen.nil?
|
603
|
+
y << buffer unless buffer.empty?
|
604
|
+
end
|
605
|
+
end
|
606
|
+
|
607
|
+
# @private
|
608
|
+
#
|
609
|
+
# https://html.spec.whatwg.org/multipage/server-sent-events.html#parsing-an-event-stream
|
610
|
+
#
|
611
|
+
# @param lines [Enumerable]
|
612
|
+
#
|
613
|
+
# @return [Hash{Symbol=>Object}]
|
614
|
+
#
|
615
|
+
def decode_sse(lines)
|
616
|
+
chain_fused(lines) do |y|
|
617
|
+
blank = {event: nil, data: nil, id: nil, retry: nil}
|
618
|
+
current = {}
|
619
|
+
|
620
|
+
lines.each do |line|
|
621
|
+
case line.sub(/\R$/, "")
|
622
|
+
in ""
|
623
|
+
next if current.empty?
|
624
|
+
y << {**blank, **current}
|
625
|
+
current = {}
|
626
|
+
in /^:/
|
627
|
+
next
|
628
|
+
in /^([^:]+):\s?(.*)$/
|
629
|
+
field, value = Regexp.last_match.captures
|
630
|
+
case field
|
631
|
+
in "event"
|
632
|
+
current.merge!(event: value)
|
633
|
+
in "data"
|
634
|
+
(current[:data] ||= String.new.b) << value << "\n"
|
635
|
+
in "id" unless value.include?("\0")
|
636
|
+
current.merge!(id: value)
|
637
|
+
in "retry" if /^\d+$/ =~ value
|
638
|
+
current.merge!(retry: Integer(value))
|
639
|
+
else
|
640
|
+
end
|
641
|
+
else
|
642
|
+
end
|
643
|
+
end
|
644
|
+
|
645
|
+
y << {**blank, **current} unless current.empty?
|
646
|
+
end
|
647
|
+
end
|
648
|
+
end
|
515
649
|
end
|
516
650
|
|
517
651
|
# rubocop:enable Metrics/ModuleLength
|
data/lib/terminal-shop.rb
CHANGED
@@ -28,15 +28,17 @@ require_relative "terminal-shop/errors"
|
|
28
28
|
require_relative "terminal-shop/base_client"
|
29
29
|
require_relative "terminal-shop/pooled_net_requester"
|
30
30
|
require_relative "terminal-shop/client"
|
31
|
-
require_relative "terminal-shop/models/app"
|
32
31
|
require_relative "terminal-shop/models/subscription"
|
33
32
|
require_relative "terminal-shop/models/address"
|
34
33
|
require_relative "terminal-shop/models/address_create_params"
|
35
34
|
require_relative "terminal-shop/models/address_create_response"
|
36
35
|
require_relative "terminal-shop/models/address_delete_params"
|
37
36
|
require_relative "terminal-shop/models/address_delete_response"
|
37
|
+
require_relative "terminal-shop/models/address_get_params"
|
38
|
+
require_relative "terminal-shop/models/address_get_response"
|
38
39
|
require_relative "terminal-shop/models/address_list_params"
|
39
40
|
require_relative "terminal-shop/models/address_list_response"
|
41
|
+
require_relative "terminal-shop/models/app"
|
40
42
|
require_relative "terminal-shop/models/app_create_params"
|
41
43
|
require_relative "terminal-shop/models/app_create_response"
|
42
44
|
require_relative "terminal-shop/models/app_delete_params"
|
@@ -52,6 +54,8 @@ require_relative "terminal-shop/models/card_create_params"
|
|
52
54
|
require_relative "terminal-shop/models/card_create_response"
|
53
55
|
require_relative "terminal-shop/models/card_delete_params"
|
54
56
|
require_relative "terminal-shop/models/card_delete_response"
|
57
|
+
require_relative "terminal-shop/models/card_get_params"
|
58
|
+
require_relative "terminal-shop/models/card_get_response"
|
55
59
|
require_relative "terminal-shop/models/card_list_params"
|
56
60
|
require_relative "terminal-shop/models/card_list_response"
|
57
61
|
require_relative "terminal-shop/models/cart"
|
@@ -59,6 +63,10 @@ require_relative "terminal-shop/models/cart_convert_params"
|
|
59
63
|
require_relative "terminal-shop/models/cart_convert_response"
|
60
64
|
require_relative "terminal-shop/models/cart_get_params"
|
61
65
|
require_relative "terminal-shop/models/cart_get_response"
|
66
|
+
require_relative "terminal-shop/models/cart_redeem_gift_card_params"
|
67
|
+
require_relative "terminal-shop/models/cart_redeem_gift_card_response"
|
68
|
+
require_relative "terminal-shop/models/cart_remove_gift_card_params"
|
69
|
+
require_relative "terminal-shop/models/cart_remove_gift_card_response"
|
62
70
|
require_relative "terminal-shop/models/cart_set_address_params"
|
63
71
|
require_relative "terminal-shop/models/cart_set_address_response"
|
64
72
|
require_relative "terminal-shop/models/cart_set_card_params"
|
@@ -75,6 +83,8 @@ require_relative "terminal-shop/models/order_get_response"
|
|
75
83
|
require_relative "terminal-shop/models/order_list_params"
|
76
84
|
require_relative "terminal-shop/models/order_list_response"
|
77
85
|
require_relative "terminal-shop/models/product"
|
86
|
+
require_relative "terminal-shop/models/product_get_params"
|
87
|
+
require_relative "terminal-shop/models/product_get_response"
|
78
88
|
require_relative "terminal-shop/models/product_list_params"
|
79
89
|
require_relative "terminal-shop/models/product_list_response"
|
80
90
|
require_relative "terminal-shop/models/product_variant"
|
@@ -87,6 +97,8 @@ require_relative "terminal-shop/models/subscription_create_params"
|
|
87
97
|
require_relative "terminal-shop/models/subscription_create_response"
|
88
98
|
require_relative "terminal-shop/models/subscription_delete_params"
|
89
99
|
require_relative "terminal-shop/models/subscription_delete_response"
|
100
|
+
require_relative "terminal-shop/models/subscription_get_params"
|
101
|
+
require_relative "terminal-shop/models/subscription_get_response"
|
90
102
|
require_relative "terminal-shop/models/subscription_list_params"
|
91
103
|
require_relative "terminal-shop/models/subscription_list_response"
|
92
104
|
require_relative "terminal-shop/models/token"
|
@@ -21,7 +21,8 @@ module TerminalShop
|
|
21
21
|
),
|
22
22
|
body: T.nilable(T.anything),
|
23
23
|
unwrap: T.nilable(Symbol),
|
24
|
-
page: T.nilable(T::Class[TerminalShop::BaseModel]),
|
24
|
+
page: T.nilable(T::Class[TerminalShop::BasePage[TerminalShop::BaseModel]]),
|
25
|
+
stream: T.nilable(T::Class[T.anything]),
|
25
26
|
model: T.nilable(TerminalShop::Converter::Input),
|
26
27
|
options: T.nilable(T.any(TerminalShop::RequestOptions, T::Hash[Symbol, T.anything]))
|
27
28
|
}
|
@@ -42,25 +43,27 @@ module TerminalShop
|
|
42
43
|
|
43
44
|
PLATFORM_HEADERS = T::Hash[String, String]
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
46
|
+
class << self
|
47
|
+
sig { params(req: TerminalShop::BaseClient::RequestComponentsShape).void }
|
48
|
+
def validate!(req)
|
49
|
+
end
|
50
|
+
|
51
|
+
sig do
|
52
|
+
params(status: Integer, headers: T.any(T::Hash[String, String], Net::HTTPHeader)).returns(T::Boolean)
|
53
|
+
end
|
54
|
+
def should_retry?(status, headers:)
|
55
|
+
end
|
56
|
+
|
57
|
+
sig do
|
58
|
+
params(
|
59
|
+
request: TerminalShop::BaseClient::RequestInputShape,
|
60
|
+
status: Integer,
|
61
|
+
response_headers: T.any(T::Hash[String, String], Net::HTTPHeader)
|
62
|
+
)
|
63
|
+
.returns(TerminalShop::BaseClient::RequestInputShape)
|
64
|
+
end
|
65
|
+
def follow_redirect(request, status:, response_headers:)
|
66
|
+
end
|
64
67
|
end
|
65
68
|
|
66
69
|
sig { returns(T.anything) }
|
@@ -82,9 +85,9 @@ module TerminalShop
|
|
82
85
|
T.nilable(T.any(String, Integer, T::Array[T.nilable(T.any(String, Integer))]))],
|
83
86
|
idempotency_header: T.nilable(String)
|
84
87
|
)
|
85
|
-
.
|
88
|
+
.returns(T.attached_class)
|
86
89
|
end
|
87
|
-
def
|
90
|
+
def self.new(
|
88
91
|
base_url:,
|
89
92
|
timeout: 0.0,
|
90
93
|
max_retries: 0,
|
@@ -122,22 +125,11 @@ module TerminalShop
|
|
122
125
|
retry_count: Integer,
|
123
126
|
send_retry_header: T::Boolean
|
124
127
|
)
|
125
|
-
.returns([Net::HTTPResponse, T::Enumerable[String]])
|
128
|
+
.returns([Integer, Net::HTTPResponse, T::Enumerable[String]])
|
126
129
|
end
|
127
130
|
private def send_request(request, redirect_count:, retry_count:, send_retry_header:)
|
128
131
|
end
|
129
132
|
|
130
|
-
sig do
|
131
|
-
params(
|
132
|
-
req: TerminalShop::BaseClient::RequestComponentsShape,
|
133
|
-
headers: T.any(T::Hash[String, String], Net::HTTPHeader),
|
134
|
-
stream: T::Enumerable[String]
|
135
|
-
)
|
136
|
-
.returns(T.anything)
|
137
|
-
end
|
138
|
-
private def parse_response(req, headers:, stream:)
|
139
|
-
end
|
140
|
-
|
141
133
|
sig do
|
142
134
|
params(
|
143
135
|
method: Symbol,
|
@@ -155,7 +147,8 @@ module TerminalShop
|
|
155
147
|
),
|
156
148
|
body: T.nilable(T.anything),
|
157
149
|
unwrap: T.nilable(Symbol),
|
158
|
-
page: T.nilable(T::Class[TerminalShop::BaseModel]),
|
150
|
+
page: T.nilable(T::Class[TerminalShop::BasePage[TerminalShop::BaseModel]]),
|
151
|
+
stream: T.nilable(T::Class[T.anything]),
|
159
152
|
model: T.nilable(TerminalShop::Converter::Input),
|
160
153
|
options: T.nilable(T.any(TerminalShop::RequestOptions, T::Hash[Symbol, T.anything]))
|
161
154
|
)
|
@@ -169,6 +162,7 @@ module TerminalShop
|
|
169
162
|
body: nil,
|
170
163
|
unwrap: nil,
|
171
164
|
page: nil,
|
165
|
+
stream: nil,
|
172
166
|
model: TerminalShop::Unknown,
|
173
167
|
options: {}
|
174
168
|
)
|