terminal-shop 1.6.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 +88 -128
- 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/region.rb +15 -0
- data/lib/terminal-shop/models/subscription.rb +6 -0
- data/lib/terminal-shop/models/view_init_response.rb +3 -13
- 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 +2 -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 +15 -0
- 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 -13
- 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/region.rbs +12 -0
- data/sig/terminal-shop/models/subscription.rbs +1 -1
- data/sig/terminal-shop/models/view_init_response.rbs +3 -12
- 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 +7 -4
@@ -16,7 +16,6 @@ module TerminalShop
|
|
16
16
|
# @option params [TerminalShop::RequestOptions, Hash{Symbol=>Object}, nil] :request_options
|
17
17
|
#
|
18
18
|
# @return [TerminalShop::Models::OrderCreateResponse]
|
19
|
-
#
|
20
19
|
def create(params)
|
21
20
|
parsed, options = TerminalShop::Models::OrderCreateParams.dump_request(params)
|
22
21
|
@client.request(
|
@@ -35,7 +34,6 @@ module TerminalShop
|
|
35
34
|
# @option params [TerminalShop::RequestOptions, Hash{Symbol=>Object}, nil] :request_options
|
36
35
|
#
|
37
36
|
# @return [TerminalShop::Models::OrderListResponse]
|
38
|
-
#
|
39
37
|
def list(params = {})
|
40
38
|
@client.request(
|
41
39
|
method: :get,
|
@@ -54,7 +52,6 @@ module TerminalShop
|
|
54
52
|
# @option params [TerminalShop::RequestOptions, Hash{Symbol=>Object}, nil] :request_options
|
55
53
|
#
|
56
54
|
# @return [TerminalShop::Models::OrderGetResponse]
|
57
|
-
#
|
58
55
|
def get(id, params = {})
|
59
56
|
@client.request(
|
60
57
|
method: :get,
|
@@ -65,7 +62,6 @@ module TerminalShop
|
|
65
62
|
end
|
66
63
|
|
67
64
|
# @param client [TerminalShop::Client]
|
68
|
-
#
|
69
65
|
def initialize(client:)
|
70
66
|
@client = client
|
71
67
|
end
|
@@ -10,7 +10,6 @@ module TerminalShop
|
|
10
10
|
# @option params [TerminalShop::RequestOptions, Hash{Symbol=>Object}, nil] :request_options
|
11
11
|
#
|
12
12
|
# @return [TerminalShop::Models::ProductListResponse]
|
13
|
-
#
|
14
13
|
def list(params = {})
|
15
14
|
@client.request(
|
16
15
|
method: :get,
|
@@ -29,7 +28,6 @@ module TerminalShop
|
|
29
28
|
# @option params [TerminalShop::RequestOptions, Hash{Symbol=>Object}, nil] :request_options
|
30
29
|
#
|
31
30
|
# @return [TerminalShop::Models::ProductGetResponse]
|
32
|
-
#
|
33
31
|
def get(id, params = {})
|
34
32
|
@client.request(
|
35
33
|
method: :get,
|
@@ -40,7 +38,6 @@ module TerminalShop
|
|
40
38
|
end
|
41
39
|
|
42
40
|
# @param client [TerminalShop::Client]
|
43
|
-
#
|
44
41
|
def initialize(client:)
|
45
42
|
@client = client
|
46
43
|
end
|
@@ -14,7 +14,6 @@ module TerminalShop
|
|
14
14
|
# @option params [TerminalShop::RequestOptions, Hash{Symbol=>Object}, nil] :request_options
|
15
15
|
#
|
16
16
|
# @return [TerminalShop::Models::ProfileUpdateResponse]
|
17
|
-
#
|
18
17
|
def update(params)
|
19
18
|
parsed, options = TerminalShop::Models::ProfileUpdateParams.dump_request(params)
|
20
19
|
@client.request(
|
@@ -33,7 +32,6 @@ module TerminalShop
|
|
33
32
|
# @option params [TerminalShop::RequestOptions, Hash{Symbol=>Object}, nil] :request_options
|
34
33
|
#
|
35
34
|
# @return [TerminalShop::Models::ProfileMeResponse]
|
36
|
-
#
|
37
35
|
def me(params = {})
|
38
36
|
@client.request(
|
39
37
|
method: :get,
|
@@ -44,7 +42,6 @@ module TerminalShop
|
|
44
42
|
end
|
45
43
|
|
46
44
|
# @param client [TerminalShop::Client]
|
47
|
-
#
|
48
45
|
def initialize(client:)
|
49
46
|
@client = client
|
50
47
|
end
|
@@ -24,7 +24,6 @@ module TerminalShop
|
|
24
24
|
# @option params [TerminalShop::RequestOptions, Hash{Symbol=>Object}, nil] :request_options
|
25
25
|
#
|
26
26
|
# @return [TerminalShop::Models::SubscriptionCreateResponse]
|
27
|
-
#
|
28
27
|
def create(params)
|
29
28
|
parsed, options = TerminalShop::Models::SubscriptionCreateParams.dump_request(params)
|
30
29
|
@client.request(
|
@@ -43,7 +42,6 @@ module TerminalShop
|
|
43
42
|
# @option params [TerminalShop::RequestOptions, Hash{Symbol=>Object}, nil] :request_options
|
44
43
|
#
|
45
44
|
# @return [TerminalShop::Models::SubscriptionListResponse]
|
46
|
-
#
|
47
45
|
def list(params = {})
|
48
46
|
@client.request(
|
49
47
|
method: :get,
|
@@ -62,7 +60,6 @@ module TerminalShop
|
|
62
60
|
# @option params [TerminalShop::RequestOptions, Hash{Symbol=>Object}, nil] :request_options
|
63
61
|
#
|
64
62
|
# @return [TerminalShop::Models::SubscriptionDeleteResponse]
|
65
|
-
#
|
66
63
|
def delete(id, params = {})
|
67
64
|
@client.request(
|
68
65
|
method: :delete,
|
@@ -81,7 +78,6 @@ module TerminalShop
|
|
81
78
|
# @option params [TerminalShop::RequestOptions, Hash{Symbol=>Object}, nil] :request_options
|
82
79
|
#
|
83
80
|
# @return [TerminalShop::Models::SubscriptionGetResponse]
|
84
|
-
#
|
85
81
|
def get(id, params = {})
|
86
82
|
@client.request(
|
87
83
|
method: :get,
|
@@ -92,7 +88,6 @@ module TerminalShop
|
|
92
88
|
end
|
93
89
|
|
94
90
|
# @param client [TerminalShop::Client]
|
95
|
-
#
|
96
91
|
def initialize(client:)
|
97
92
|
@client = client
|
98
93
|
end
|
@@ -10,7 +10,6 @@ module TerminalShop
|
|
10
10
|
# @option params [TerminalShop::RequestOptions, Hash{Symbol=>Object}, nil] :request_options
|
11
11
|
#
|
12
12
|
# @return [TerminalShop::Models::TokenCreateResponse]
|
13
|
-
#
|
14
13
|
def create(params = {})
|
15
14
|
@client.request(
|
16
15
|
method: :post,
|
@@ -27,7 +26,6 @@ module TerminalShop
|
|
27
26
|
# @option params [TerminalShop::RequestOptions, Hash{Symbol=>Object}, nil] :request_options
|
28
27
|
#
|
29
28
|
# @return [TerminalShop::Models::TokenListResponse]
|
30
|
-
#
|
31
29
|
def list(params = {})
|
32
30
|
@client.request(
|
33
31
|
method: :get,
|
@@ -46,7 +44,6 @@ module TerminalShop
|
|
46
44
|
# @option params [TerminalShop::RequestOptions, Hash{Symbol=>Object}, nil] :request_options
|
47
45
|
#
|
48
46
|
# @return [TerminalShop::Models::TokenDeleteResponse]
|
49
|
-
#
|
50
47
|
def delete(id, params = {})
|
51
48
|
@client.request(
|
52
49
|
method: :delete,
|
@@ -65,7 +62,6 @@ module TerminalShop
|
|
65
62
|
# @option params [TerminalShop::RequestOptions, Hash{Symbol=>Object}, nil] :request_options
|
66
63
|
#
|
67
64
|
# @return [TerminalShop::Models::TokenGetResponse]
|
68
|
-
#
|
69
65
|
def get(id, params = {})
|
70
66
|
@client.request(
|
71
67
|
method: :get,
|
@@ -76,7 +72,6 @@ module TerminalShop
|
|
76
72
|
end
|
77
73
|
|
78
74
|
# @param client [TerminalShop::Client]
|
79
|
-
#
|
80
75
|
def initialize(client:)
|
81
76
|
@client = client
|
82
77
|
end
|
@@ -11,7 +11,6 @@ module TerminalShop
|
|
11
11
|
# @option params [TerminalShop::RequestOptions, Hash{Symbol=>Object}, nil] :request_options
|
12
12
|
#
|
13
13
|
# @return [TerminalShop::Models::ViewInitResponse]
|
14
|
-
#
|
15
14
|
def init(params = {})
|
16
15
|
@client.request(
|
17
16
|
method: :get,
|
@@ -22,7 +21,6 @@ module TerminalShop
|
|
22
21
|
end
|
23
22
|
|
24
23
|
# @param client [TerminalShop::Client]
|
25
|
-
#
|
26
24
|
def initialize(client:)
|
27
25
|
@client = client
|
28
26
|
end
|
data/lib/terminal-shop/util.rb
CHANGED
@@ -3,20 +3,17 @@
|
|
3
3
|
module TerminalShop
|
4
4
|
# rubocop:disable Metrics/ModuleLength
|
5
5
|
|
6
|
-
# @private
|
7
|
-
#
|
6
|
+
# @api private
|
8
7
|
module Util
|
9
|
-
# @private
|
8
|
+
# @api private
|
10
9
|
#
|
11
10
|
# @return [Float]
|
12
|
-
#
|
13
11
|
def self.monotonic_secs = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
14
12
|
|
15
13
|
class << self
|
16
|
-
# @private
|
14
|
+
# @api private
|
17
15
|
#
|
18
16
|
# @return [String]
|
19
|
-
#
|
20
17
|
def arch
|
21
18
|
case (arch = RbConfig::CONFIG["arch"])&.downcase
|
22
19
|
in nil
|
@@ -32,10 +29,9 @@ module TerminalShop
|
|
32
29
|
end
|
33
30
|
end
|
34
31
|
|
35
|
-
# @private
|
32
|
+
# @api private
|
36
33
|
#
|
37
34
|
# @return [String]
|
38
|
-
#
|
39
35
|
def os
|
40
36
|
case (host = RbConfig::CONFIG["host_os"])&.downcase
|
41
37
|
in nil
|
@@ -57,12 +53,11 @@ module TerminalShop
|
|
57
53
|
end
|
58
54
|
|
59
55
|
class << self
|
60
|
-
# @private
|
56
|
+
# @api private
|
61
57
|
#
|
62
58
|
# @param input [Object]
|
63
59
|
#
|
64
|
-
# @return [Boolean
|
65
|
-
#
|
60
|
+
# @return [Boolean]
|
66
61
|
def primitive?(input)
|
67
62
|
case input
|
68
63
|
in true | false | Integer | Float | Symbol | String
|
@@ -72,12 +67,11 @@ module TerminalShop
|
|
72
67
|
end
|
73
68
|
end
|
74
69
|
|
75
|
-
# @private
|
70
|
+
# @api private
|
76
71
|
#
|
77
72
|
# @param input [Object]
|
78
73
|
#
|
79
74
|
# @return [Boolean, Object]
|
80
|
-
#
|
81
75
|
def coerce_boolean(input)
|
82
76
|
case input.is_a?(String) ? input.downcase : input
|
83
77
|
in Numeric
|
@@ -91,13 +85,12 @@ module TerminalShop
|
|
91
85
|
end
|
92
86
|
end
|
93
87
|
|
94
|
-
# @private
|
88
|
+
# @api private
|
95
89
|
#
|
96
90
|
# @param input [Object]
|
97
91
|
#
|
98
92
|
# @raise [ArgumentError]
|
99
93
|
# @return [Boolean, nil]
|
100
|
-
#
|
101
94
|
def coerce_boolean!(input)
|
102
95
|
case coerce_boolean(input)
|
103
96
|
in true | false | nil => coerced
|
@@ -107,12 +100,11 @@ module TerminalShop
|
|
107
100
|
end
|
108
101
|
end
|
109
102
|
|
110
|
-
# @private
|
103
|
+
# @api private
|
111
104
|
#
|
112
105
|
# @param input [Object]
|
113
106
|
#
|
114
107
|
# @return [Integer, Object]
|
115
|
-
#
|
116
108
|
def coerce_integer(input)
|
117
109
|
case input
|
118
110
|
in true
|
@@ -124,12 +116,11 @@ module TerminalShop
|
|
124
116
|
end
|
125
117
|
end
|
126
118
|
|
127
|
-
# @private
|
119
|
+
# @api private
|
128
120
|
#
|
129
121
|
# @param input [Object]
|
130
122
|
#
|
131
123
|
# @return [Float, Object]
|
132
|
-
#
|
133
124
|
def coerce_float(input)
|
134
125
|
case input
|
135
126
|
in true
|
@@ -141,12 +132,11 @@ module TerminalShop
|
|
141
132
|
end
|
142
133
|
end
|
143
134
|
|
144
|
-
# @private
|
135
|
+
# @api private
|
145
136
|
#
|
146
137
|
# @param input [Object]
|
147
138
|
#
|
148
139
|
# @return [Hash{Object=>Object}, Object]
|
149
|
-
#
|
150
140
|
def coerce_hash(input)
|
151
141
|
case input
|
152
142
|
in NilClass | Array | Set | Enumerator
|
@@ -165,14 +155,13 @@ module TerminalShop
|
|
165
155
|
OMIT = Object.new.freeze
|
166
156
|
|
167
157
|
class << self
|
168
|
-
# @private
|
158
|
+
# @api private
|
169
159
|
#
|
170
160
|
# @param lhs [Object]
|
171
161
|
# @param rhs [Object]
|
172
162
|
# @param concat [Boolean]
|
173
163
|
#
|
174
164
|
# @return [Object]
|
175
|
-
#
|
176
165
|
private def deep_merge_lr(lhs, rhs, concat: false)
|
177
166
|
case [lhs, rhs, concat]
|
178
167
|
in [Hash, Hash, _]
|
@@ -191,7 +180,7 @@ module TerminalShop
|
|
191
180
|
end
|
192
181
|
end
|
193
182
|
|
194
|
-
# @private
|
183
|
+
# @api private
|
195
184
|
#
|
196
185
|
# Recursively merge one hash with another. If the values at a given key are not
|
197
186
|
# both hashes, just take the new value.
|
@@ -203,7 +192,6 @@ module TerminalShop
|
|
203
192
|
# @param concat [Boolean] whether to merge sequences by concatenation.
|
204
193
|
#
|
205
194
|
# @return [Object]
|
206
|
-
#
|
207
195
|
def deep_merge(*values, sentinel: nil, concat: false)
|
208
196
|
case values
|
209
197
|
in [value, *values]
|
@@ -215,7 +203,7 @@ module TerminalShop
|
|
215
203
|
end
|
216
204
|
end
|
217
205
|
|
218
|
-
# @private
|
206
|
+
# @api private
|
219
207
|
#
|
220
208
|
# @param data [Hash{Symbol=>Object}, Array<Object>, Object]
|
221
209
|
# @param pick [Symbol, Integer, Array<Symbol, Integer>, nil]
|
@@ -223,7 +211,6 @@ module TerminalShop
|
|
223
211
|
# @param blk [Proc, nil]
|
224
212
|
#
|
225
213
|
# @return [Object, nil]
|
226
|
-
#
|
227
214
|
def dig(data, pick, sentinel = nil, &blk)
|
228
215
|
case [data, pick, blk]
|
229
216
|
in [_, nil, nil]
|
@@ -248,22 +235,20 @@ module TerminalShop
|
|
248
235
|
end
|
249
236
|
|
250
237
|
class << self
|
251
|
-
# @private
|
238
|
+
# @api private
|
252
239
|
#
|
253
240
|
# @param uri [URI::Generic]
|
254
241
|
#
|
255
242
|
# @return [String]
|
256
|
-
#
|
257
243
|
def uri_origin(uri)
|
258
244
|
"#{uri.scheme}://#{uri.host}#{uri.port == uri.default_port ? '' : ":#{uri.port}"}"
|
259
245
|
end
|
260
246
|
|
261
|
-
# @private
|
247
|
+
# @api private
|
262
248
|
#
|
263
249
|
# @param path [String, Array<String>]
|
264
250
|
#
|
265
251
|
# @return [String]
|
266
|
-
#
|
267
252
|
def interpolate_path(path)
|
268
253
|
case path
|
269
254
|
in String
|
@@ -278,40 +263,37 @@ module TerminalShop
|
|
278
263
|
end
|
279
264
|
|
280
265
|
class << self
|
281
|
-
# @private
|
266
|
+
# @api private
|
282
267
|
#
|
283
268
|
# @param query [String, nil]
|
284
269
|
#
|
285
270
|
# @return [Hash{String=>Array<String>}]
|
286
|
-
#
|
287
271
|
def decode_query(query)
|
288
272
|
CGI.parse(query.to_s)
|
289
273
|
end
|
290
274
|
|
291
|
-
# @private
|
275
|
+
# @api private
|
292
276
|
#
|
293
277
|
# @param query [Hash{String=>Array<String>, String, nil}, nil]
|
294
278
|
#
|
295
279
|
# @return [String, nil]
|
296
|
-
#
|
297
280
|
def encode_query(query)
|
298
281
|
query.to_h.empty? ? nil : URI.encode_www_form(query)
|
299
282
|
end
|
300
283
|
end
|
301
284
|
|
302
285
|
class << self
|
303
|
-
# @private
|
286
|
+
# @api private
|
304
287
|
#
|
305
288
|
# @param url [URI::Generic, String]
|
306
289
|
#
|
307
290
|
# @return [Hash{Symbol=>String, Integer, nil}]
|
308
|
-
#
|
309
291
|
def parse_uri(url)
|
310
292
|
parsed = URI::Generic.component.zip(URI.split(url)).to_h
|
311
293
|
{**parsed, query: decode_query(parsed.fetch(:query))}
|
312
294
|
end
|
313
295
|
|
314
|
-
# @private
|
296
|
+
# @api private
|
315
297
|
#
|
316
298
|
# @param parsed [Hash{Symbol=>String, Integer, nil}] .
|
317
299
|
#
|
@@ -326,12 +308,11 @@ module TerminalShop
|
|
326
308
|
# @option parsed [Hash{String=>Array<String>}] :query
|
327
309
|
#
|
328
310
|
# @return [URI::Generic]
|
329
|
-
#
|
330
311
|
def unparse_uri(parsed)
|
331
312
|
URI::Generic.build(**parsed, query: encode_query(parsed.fetch(:query)))
|
332
313
|
end
|
333
314
|
|
334
|
-
# @private
|
315
|
+
# @api private
|
335
316
|
#
|
336
317
|
# @param lhs [Hash{Symbol=>String, Integer, nil}] .
|
337
318
|
#
|
@@ -358,7 +339,6 @@ module TerminalShop
|
|
358
339
|
# @option rhs [Hash{String=>Array<String>}] :query
|
359
340
|
#
|
360
341
|
# @return [URI::Generic]
|
361
|
-
#
|
362
342
|
def join_parsed_uri(lhs, rhs)
|
363
343
|
base_path, base_query = lhs.fetch_values(:path, :query)
|
364
344
|
slashed = base_path.end_with?("/") ? base_path : "#{base_path}/"
|
@@ -380,12 +360,11 @@ module TerminalShop
|
|
380
360
|
end
|
381
361
|
|
382
362
|
class << self
|
383
|
-
# @private
|
363
|
+
# @api private
|
384
364
|
#
|
385
365
|
# @param headers [Hash{String=>String, Integer, Array<String, Integer, nil>, nil}]
|
386
366
|
#
|
387
367
|
# @return [Hash{String=>String}]
|
388
|
-
#
|
389
368
|
def normalized_headers(*headers)
|
390
369
|
{}.merge(*headers.compact).to_h do |key, val|
|
391
370
|
case val
|
@@ -399,16 +378,15 @@ module TerminalShop
|
|
399
378
|
end
|
400
379
|
end
|
401
380
|
|
402
|
-
# @private
|
381
|
+
# @api private
|
403
382
|
#
|
404
383
|
# An adapter that satisfies the IO interface required by `::IO.copy_stream`
|
405
384
|
class ReadIOAdapter
|
406
|
-
# @private
|
385
|
+
# @api private
|
407
386
|
#
|
408
387
|
# @param max_len [Integer, nil]
|
409
388
|
#
|
410
389
|
# @return [String]
|
411
|
-
#
|
412
390
|
private def read_enum(max_len)
|
413
391
|
case max_len
|
414
392
|
in nil
|
@@ -422,13 +400,12 @@ module TerminalShop
|
|
422
400
|
@buf.slice!(0..)
|
423
401
|
end
|
424
402
|
|
425
|
-
# @private
|
403
|
+
# @api private
|
426
404
|
#
|
427
405
|
# @param max_len [Integer, nil]
|
428
406
|
# @param out_string [String, nil]
|
429
407
|
#
|
430
408
|
# @return [String, nil]
|
431
|
-
#
|
432
409
|
def read(max_len = nil, out_string = nil)
|
433
410
|
case @stream
|
434
411
|
in nil
|
@@ -447,11 +424,10 @@ module TerminalShop
|
|
447
424
|
.tap(&@blk)
|
448
425
|
end
|
449
426
|
|
450
|
-
# @private
|
427
|
+
# @api private
|
451
428
|
#
|
452
429
|
# @param stream [String, IO, StringIO, Enumerable]
|
453
430
|
# @param blk [Proc]
|
454
|
-
#
|
455
431
|
def initialize(stream, &blk)
|
456
432
|
@stream = stream.is_a?(String) ? StringIO.new(stream) : stream
|
457
433
|
@buf = String.new.b
|
@@ -463,7 +439,6 @@ module TerminalShop
|
|
463
439
|
# @param blk [Proc]
|
464
440
|
#
|
465
441
|
# @return [Enumerable]
|
466
|
-
#
|
467
442
|
def string_io(&blk)
|
468
443
|
Enumerator.new do |y|
|
469
444
|
y.define_singleton_method(:write) do
|
@@ -477,13 +452,12 @@ module TerminalShop
|
|
477
452
|
end
|
478
453
|
|
479
454
|
class << self
|
480
|
-
# @private
|
455
|
+
# @api private
|
481
456
|
#
|
482
457
|
# @param y [Enumerator::Yielder]
|
483
458
|
# @param boundary [String]
|
484
459
|
# @param key [Symbol, String]
|
485
460
|
# @param val [Object]
|
486
|
-
#
|
487
461
|
private def encode_multipart_formdata(y, boundary:, key:, val:)
|
488
462
|
y << "--#{boundary}\r\n"
|
489
463
|
y << "Content-Disposition: form-data"
|
@@ -516,12 +490,11 @@ module TerminalShop
|
|
516
490
|
y << "\r\n"
|
517
491
|
end
|
518
492
|
|
519
|
-
# @private
|
493
|
+
# @api private
|
520
494
|
#
|
521
495
|
# @param body [Object]
|
522
496
|
#
|
523
497
|
# @return [Array(String, Enumerable)]
|
524
|
-
#
|
525
498
|
private def encode_multipart_streaming(body)
|
526
499
|
boundary = SecureRandom.urlsafe_base64(60)
|
527
500
|
|
@@ -547,18 +520,19 @@ module TerminalShop
|
|
547
520
|
[boundary, strio]
|
548
521
|
end
|
549
522
|
|
550
|
-
# @private
|
523
|
+
# @api private
|
551
524
|
#
|
552
525
|
# @param headers [Hash{String=>String}]
|
553
526
|
# @param body [Object]
|
554
527
|
#
|
555
528
|
# @return [Object]
|
556
|
-
#
|
557
529
|
def encode_content(headers, body)
|
558
530
|
content_type = headers["content-type"]
|
559
531
|
case [content_type, body]
|
560
|
-
in [
|
532
|
+
in [%r{^application/(?:vnd\.api\+)?json}, Hash | Array]
|
561
533
|
[headers, JSON.fast_generate(body)]
|
534
|
+
in [%r{^application/(?:x-)?jsonl}, Enumerable]
|
535
|
+
[headers, body.lazy.map { JSON.fast_generate(_1) }]
|
562
536
|
in [%r{^multipart/form-data}, Hash | IO | StringIO]
|
563
537
|
boundary, strio = encode_multipart_streaming(body)
|
564
538
|
headers = {**headers, "content-type" => "#{content_type}; boundary=#{boundary}"}
|
@@ -570,7 +544,7 @@ module TerminalShop
|
|
570
544
|
end
|
571
545
|
end
|
572
546
|
|
573
|
-
# @private
|
547
|
+
# @api private
|
574
548
|
#
|
575
549
|
# @param headers [Hash{String=>String}, Net::HTTPHeader]
|
576
550
|
# @param stream [Enumerable]
|
@@ -578,7 +552,6 @@ module TerminalShop
|
|
578
552
|
#
|
579
553
|
# @raise [JSON::ParserError]
|
580
554
|
# @return [Object]
|
581
|
-
#
|
582
555
|
def decode_content(headers, stream:, suppress_error: false)
|
583
556
|
case headers["content-type"]
|
584
557
|
in %r{^application/(?:vnd\.api\+)?json}
|
@@ -589,11 +562,14 @@ module TerminalShop
|
|
589
562
|
raise e unless suppress_error
|
590
563
|
json
|
591
564
|
end
|
565
|
+
in %r{^application/(?:x-)?jsonl}
|
566
|
+
lines = decode_lines(stream)
|
567
|
+
chain_fused(lines) do |y|
|
568
|
+
lines.each { y << JSON.parse(_1, symbolize_names: true) }
|
569
|
+
end
|
592
570
|
in %r{^text/event-stream}
|
593
571
|
lines = decode_lines(stream)
|
594
572
|
decode_sse(lines)
|
595
|
-
in %r{^application/(?:x-)?jsonl}
|
596
|
-
decode_lines(stream)
|
597
573
|
in %r{^text/}
|
598
574
|
stream.to_a.join
|
599
575
|
else
|
@@ -604,7 +580,7 @@ module TerminalShop
|
|
604
580
|
end
|
605
581
|
|
606
582
|
class << self
|
607
|
-
# @private
|
583
|
+
# @api private
|
608
584
|
#
|
609
585
|
# https://doc.rust-lang.org/std/iter/trait.FusedIterator.html
|
610
586
|
#
|
@@ -613,7 +589,6 @@ module TerminalShop
|
|
613
589
|
# @param close [Proc]
|
614
590
|
#
|
615
591
|
# @return [Enumerable]
|
616
|
-
#
|
617
592
|
def fused_enum(enum, external: false, &close)
|
618
593
|
fused = false
|
619
594
|
iter = Enumerator.new do |y|
|
@@ -637,10 +612,9 @@ module TerminalShop
|
|
637
612
|
iter
|
638
613
|
end
|
639
614
|
|
640
|
-
# @private
|
615
|
+
# @api private
|
641
616
|
#
|
642
617
|
# @param enum [Enumerable, nil]
|
643
|
-
#
|
644
618
|
def close_fused!(enum)
|
645
619
|
return unless enum.is_a?(Enumerator)
|
646
620
|
|
@@ -649,11 +623,12 @@ module TerminalShop
|
|
649
623
|
# rubocop:enable Lint/UnreachableLoop
|
650
624
|
end
|
651
625
|
|
652
|
-
# @private
|
626
|
+
# @api private
|
653
627
|
#
|
654
628
|
# @param enum [Enumerable, nil]
|
655
629
|
# @param blk [Proc]
|
656
630
|
#
|
631
|
+
# @return [Enumerable]
|
657
632
|
def chain_fused(enum, &blk)
|
658
633
|
iter = Enumerator.new { blk.call(_1) }
|
659
634
|
fused_enum(iter) { close_fused!(enum) }
|
@@ -661,12 +636,11 @@ module TerminalShop
|
|
661
636
|
end
|
662
637
|
|
663
638
|
class << self
|
664
|
-
# @private
|
639
|
+
# @api private
|
665
640
|
#
|
666
641
|
# @param enum [Enumerable]
|
667
642
|
#
|
668
643
|
# @return [Enumerable]
|
669
|
-
#
|
670
644
|
def decode_lines(enum)
|
671
645
|
re = /(\r\n|\r|\n)/
|
672
646
|
buffer = String.new.b
|
@@ -696,14 +670,13 @@ module TerminalShop
|
|
696
670
|
end
|
697
671
|
end
|
698
672
|
|
699
|
-
# @private
|
673
|
+
# @api private
|
700
674
|
#
|
701
675
|
# https://html.spec.whatwg.org/multipage/server-sent-events.html#parsing-an-event-stream
|
702
676
|
#
|
703
677
|
# @param lines [Enumerable]
|
704
678
|
#
|
705
679
|
# @return [Hash{Symbol=>Object}]
|
706
|
-
#
|
707
680
|
def decode_sse(lines)
|
708
681
|
# rubocop:disable Metrics/BlockLength
|
709
682
|
chain_fused(lines) do |y|
|
data/lib/terminal-shop.rb
CHANGED
@@ -7,6 +7,7 @@ require "erb"
|
|
7
7
|
require "etc"
|
8
8
|
require "json"
|
9
9
|
require "net/http"
|
10
|
+
require "pathname"
|
10
11
|
require "rbconfig"
|
11
12
|
require "securerandom"
|
12
13
|
require "set"
|
@@ -91,6 +92,7 @@ require_relative "terminal-shop/models/profile_me_params"
|
|
91
92
|
require_relative "terminal-shop/models/profile_me_response"
|
92
93
|
require_relative "terminal-shop/models/profile_update_params"
|
93
94
|
require_relative "terminal-shop/models/profile_update_response"
|
95
|
+
require_relative "terminal-shop/models/region"
|
94
96
|
require_relative "terminal-shop/models/subscription_create_params"
|
95
97
|
require_relative "terminal-shop/models/subscription_create_response"
|
96
98
|
require_relative "terminal-shop/models/subscription_delete_params"
|