terminal-shop 1.7.0 → 2.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/README.md +17 -1
- data/lib/terminal-shop/base_client.rb +47 -56
- data/lib/terminal-shop/base_model.rb +300 -352
- data/lib/terminal-shop/base_page.rb +30 -31
- data/lib/terminal-shop/client.rb +2 -3
- data/lib/terminal-shop/errors.rb +12 -17
- data/lib/terminal-shop/extern.rb +1 -4
- data/lib/terminal-shop/models/product.rb +7 -3
- data/lib/terminal-shop/models/region.rb +7 -3
- data/lib/terminal-shop/models/subscription.rb +7 -3
- data/lib/terminal-shop/pooled_net_requester.rb +30 -21
- data/lib/terminal-shop/request_options.rb +5 -12
- 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 +59 -77
- data/lib/terminal-shop/version.rb +1 -1
- data/lib/terminal-shop.rb +16 -0
- data/manifest.yaml +1 -0
- data/rbi/lib/terminal-shop/base_client.rbi +63 -41
- data/rbi/lib/terminal-shop/base_model.rbi +278 -129
- data/rbi/lib/terminal-shop/base_page.rbi +1 -4
- data/rbi/lib/terminal-shop/client.rbi +29 -30
- data/rbi/lib/terminal-shop/errors.rbi +12 -14
- data/rbi/lib/terminal-shop/extern.rbi +1 -1
- data/rbi/lib/terminal-shop/models/address.rbi +25 -51
- data/rbi/lib/terminal-shop/models/address_create_params.rbi +23 -46
- data/rbi/lib/terminal-shop/models/address_create_response.rbi +2 -6
- data/rbi/lib/terminal-shop/models/address_delete_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/address_delete_response.rbi +1 -6
- data/rbi/lib/terminal-shop/models/address_get_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/address_get_response.rbi +8 -6
- data/rbi/lib/terminal-shop/models/address_list_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/address_list_response.rbi +5 -6
- data/rbi/lib/terminal-shop/models/app.rbi +9 -24
- data/rbi/lib/terminal-shop/models/app_create_params.rbi +3 -13
- data/rbi/lib/terminal-shop/models/app_create_response.rbi +10 -20
- data/rbi/lib/terminal-shop/models/app_delete_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/app_delete_response.rbi +1 -6
- data/rbi/lib/terminal-shop/models/app_get_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/app_get_response.rbi +5 -6
- data/rbi/lib/terminal-shop/models/app_list_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/app_list_response.rbi +5 -6
- data/rbi/lib/terminal-shop/models/card.rbi +22 -36
- data/rbi/lib/terminal-shop/models/card_collect_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/card_collect_response.rbi +11 -14
- data/rbi/lib/terminal-shop/models/card_create_params.rbi +4 -7
- data/rbi/lib/terminal-shop/models/card_create_response.rbi +2 -6
- data/rbi/lib/terminal-shop/models/card_delete_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/card_delete_response.rbi +1 -6
- data/rbi/lib/terminal-shop/models/card_get_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/card_get_response.rbi +5 -6
- data/rbi/lib/terminal-shop/models/card_list_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/card_list_response.rbi +5 -6
- data/rbi/lib/terminal-shop/models/cart.rbi +53 -88
- data/rbi/lib/terminal-shop/models/cart_clear_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/cart_clear_response.rbi +1 -6
- data/rbi/lib/terminal-shop/models/cart_convert_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/cart_convert_response.rbi +5 -6
- data/rbi/lib/terminal-shop/models/cart_get_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/cart_get_response.rbi +5 -6
- data/rbi/lib/terminal-shop/models/cart_set_address_params.rbi +3 -7
- data/rbi/lib/terminal-shop/models/cart_set_address_response.rbi +1 -6
- data/rbi/lib/terminal-shop/models/cart_set_card_params.rbi +3 -7
- data/rbi/lib/terminal-shop/models/cart_set_card_response.rbi +1 -6
- data/rbi/lib/terminal-shop/models/cart_set_item_params.rbi +5 -13
- data/rbi/lib/terminal-shop/models/cart_set_item_response.rbi +5 -6
- data/rbi/lib/terminal-shop/models/email_create_params.rbi +3 -7
- data/rbi/lib/terminal-shop/models/email_create_response.rbi +1 -6
- data/rbi/lib/terminal-shop/models/order.rbi +80 -139
- data/rbi/lib/terminal-shop/models/order_create_params.rbi +7 -19
- data/rbi/lib/terminal-shop/models/order_create_response.rbi +2 -6
- data/rbi/lib/terminal-shop/models/order_get_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/order_get_response.rbi +5 -6
- data/rbi/lib/terminal-shop/models/order_list_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/order_list_response.rbi +5 -6
- data/rbi/lib/terminal-shop/models/product.rbi +52 -80
- data/rbi/lib/terminal-shop/models/product_get_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/product_get_response.rbi +8 -6
- data/rbi/lib/terminal-shop/models/product_list_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/product_list_response.rbi +5 -6
- data/rbi/lib/terminal-shop/models/product_variant.rbi +7 -18
- data/rbi/lib/terminal-shop/models/profile.rbi +20 -36
- data/rbi/lib/terminal-shop/models/profile_me_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/profile_me_response.rbi +8 -6
- data/rbi/lib/terminal-shop/models/profile_update_params.rbi +3 -13
- data/rbi/lib/terminal-shop/models/profile_update_response.rbi +8 -6
- data/rbi/lib/terminal-shop/models/region.rbi +10 -8
- data/rbi/lib/terminal-shop/models/subscription.rbi +35 -75
- data/rbi/lib/terminal-shop/models/subscription_create_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/subscription_create_response.rbi +1 -6
- data/rbi/lib/terminal-shop/models/subscription_delete_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/subscription_delete_response.rbi +1 -6
- data/rbi/lib/terminal-shop/models/subscription_get_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/subscription_get_response.rbi +8 -6
- data/rbi/lib/terminal-shop/models/subscription_list_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/subscription_list_response.rbi +4 -8
- data/rbi/lib/terminal-shop/models/token.rbi +8 -18
- data/rbi/lib/terminal-shop/models/token_create_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/token_create_response.rbi +11 -20
- data/rbi/lib/terminal-shop/models/token_delete_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/token_delete_response.rbi +1 -6
- data/rbi/lib/terminal-shop/models/token_get_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/token_get_response.rbi +6 -6
- data/rbi/lib/terminal-shop/models/token_list_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/token_list_response.rbi +5 -6
- data/rbi/lib/terminal-shop/models/view_init_params.rbi +1 -1
- data/rbi/lib/terminal-shop/models/view_init_response.rbi +37 -81
- data/rbi/lib/terminal-shop/pooled_net_requester.rbi +24 -6
- data/rbi/lib/terminal-shop/request_options.rbi +32 -57
- data/rbi/lib/terminal-shop/resources/address.rbi +26 -6
- data/rbi/lib/terminal-shop/resources/app.rbi +18 -6
- data/rbi/lib/terminal-shop/resources/card.rbi +27 -8
- data/rbi/lib/terminal-shop/resources/cart.rbi +29 -9
- data/rbi/lib/terminal-shop/resources/email.rbi +7 -2
- data/rbi/lib/terminal-shop/resources/order.rbi +20 -5
- data/rbi/lib/terminal-shop/resources/product.rbi +9 -3
- data/rbi/lib/terminal-shop/resources/profile.rbi +4 -2
- data/rbi/lib/terminal-shop/resources/subscription.rbi +26 -6
- data/rbi/lib/terminal-shop/resources/token.rbi +18 -6
- data/rbi/lib/terminal-shop/resources/view.rbi +3 -1
- data/rbi/lib/terminal-shop/util.rbi +78 -20
- data/rbi/lib/terminal-shop/version.rbi +1 -1
- data/sig/terminal-shop/base_client.rbs +20 -15
- data/sig/terminal-shop/base_model.rbs +36 -18
- data/sig/terminal-shop/client.rbs +8 -8
- data/sig/terminal-shop/errors.rbs +21 -21
- data/sig/terminal-shop/models/address.rbs +11 -15
- data/sig/terminal-shop/models/address_create_params.rbs +11 -16
- data/sig/terminal-shop/models/address_create_response.rbs +1 -6
- data/sig/terminal-shop/models/address_delete_params.rbs +1 -6
- data/sig/terminal-shop/models/address_delete_response.rbs +1 -6
- data/sig/terminal-shop/models/address_get_params.rbs +1 -6
- data/sig/terminal-shop/models/address_get_response.rbs +1 -6
- data/sig/terminal-shop/models/address_list_params.rbs +1 -6
- data/sig/terminal-shop/models/address_list_response.rbs +1 -6
- data/sig/terminal-shop/models/app.rbs +6 -5
- data/sig/terminal-shop/models/app_create_params.rbs +5 -10
- data/sig/terminal-shop/models/app_create_response.rbs +4 -12
- data/sig/terminal-shop/models/app_delete_params.rbs +1 -6
- data/sig/terminal-shop/models/app_delete_response.rbs +1 -6
- data/sig/terminal-shop/models/app_get_params.rbs +1 -5
- data/sig/terminal-shop/models/app_get_response.rbs +1 -5
- data/sig/terminal-shop/models/app_list_params.rbs +1 -5
- data/sig/terminal-shop/models/app_list_response.rbs +1 -6
- data/sig/terminal-shop/models/card.rbs +7 -16
- data/sig/terminal-shop/models/card_collect_params.rbs +1 -6
- data/sig/terminal-shop/models/card_collect_response.rbs +4 -12
- data/sig/terminal-shop/models/card_create_params.rbs +4 -6
- data/sig/terminal-shop/models/card_create_response.rbs +1 -6
- data/sig/terminal-shop/models/card_delete_params.rbs +1 -6
- data/sig/terminal-shop/models/card_delete_response.rbs +1 -6
- data/sig/terminal-shop/models/card_get_params.rbs +1 -5
- data/sig/terminal-shop/models/card_get_response.rbs +1 -6
- data/sig/terminal-shop/models/card_list_params.rbs +1 -5
- data/sig/terminal-shop/models/card_list_response.rbs +1 -6
- data/sig/terminal-shop/models/cart.rbs +20 -34
- data/sig/terminal-shop/models/cart_clear_params.rbs +1 -6
- data/sig/terminal-shop/models/cart_clear_response.rbs +1 -6
- data/sig/terminal-shop/models/cart_convert_params.rbs +1 -6
- data/sig/terminal-shop/models/cart_convert_response.rbs +1 -6
- data/sig/terminal-shop/models/cart_get_params.rbs +1 -5
- data/sig/terminal-shop/models/cart_get_response.rbs +1 -6
- data/sig/terminal-shop/models/cart_set_address_params.rbs +4 -9
- data/sig/terminal-shop/models/cart_set_address_response.rbs +1 -6
- data/sig/terminal-shop/models/cart_set_card_params.rbs +4 -6
- data/sig/terminal-shop/models/cart_set_card_response.rbs +1 -6
- data/sig/terminal-shop/models/cart_set_item_params.rbs +5 -10
- data/sig/terminal-shop/models/cart_set_item_response.rbs +1 -6
- data/sig/terminal-shop/models/email_create_params.rbs +4 -6
- data/sig/terminal-shop/models/email_create_response.rbs +1 -6
- data/sig/terminal-shop/models/order.rbs +31 -50
- data/sig/terminal-shop/models/order_create_params.rbs +6 -11
- data/sig/terminal-shop/models/order_create_response.rbs +1 -6
- data/sig/terminal-shop/models/order_get_params.rbs +1 -5
- data/sig/terminal-shop/models/order_get_response.rbs +1 -6
- data/sig/terminal-shop/models/order_list_params.rbs +1 -6
- data/sig/terminal-shop/models/order_list_response.rbs +1 -6
- data/sig/terminal-shop/models/product.rbs +20 -27
- data/sig/terminal-shop/models/product_get_params.rbs +1 -6
- data/sig/terminal-shop/models/product_get_response.rbs +1 -6
- data/sig/terminal-shop/models/product_list_params.rbs +1 -6
- data/sig/terminal-shop/models/product_list_response.rbs +1 -6
- data/sig/terminal-shop/models/product_variant.rbs +1 -5
- data/sig/terminal-shop/models/profile.rbs +8 -17
- data/sig/terminal-shop/models/profile_me_params.rbs +1 -6
- data/sig/terminal-shop/models/profile_me_response.rbs +1 -6
- data/sig/terminal-shop/models/profile_update_params.rbs +5 -10
- data/sig/terminal-shop/models/profile_update_response.rbs +1 -6
- data/sig/terminal-shop/models/region.rbs +4 -2
- data/sig/terminal-shop/models/subscription.rbs +15 -27
- data/sig/terminal-shop/models/subscription_create_params.rbs +1 -6
- data/sig/terminal-shop/models/subscription_create_response.rbs +1 -6
- data/sig/terminal-shop/models/subscription_delete_params.rbs +1 -6
- data/sig/terminal-shop/models/subscription_delete_response.rbs +1 -6
- data/sig/terminal-shop/models/subscription_get_params.rbs +1 -6
- data/sig/terminal-shop/models/subscription_get_response.rbs +1 -6
- data/sig/terminal-shop/models/subscription_list_params.rbs +1 -6
- data/sig/terminal-shop/models/subscription_list_response.rbs +3 -6
- data/sig/terminal-shop/models/token.rbs +1 -5
- data/sig/terminal-shop/models/token_create_params.rbs +1 -6
- data/sig/terminal-shop/models/token_create_response.rbs +4 -12
- data/sig/terminal-shop/models/token_delete_params.rbs +1 -6
- data/sig/terminal-shop/models/token_delete_response.rbs +1 -6
- data/sig/terminal-shop/models/token_get_params.rbs +1 -5
- data/sig/terminal-shop/models/token_get_response.rbs +1 -6
- data/sig/terminal-shop/models/token_list_params.rbs +1 -6
- data/sig/terminal-shop/models/token_list_response.rbs +1 -6
- data/sig/terminal-shop/models/view_init_params.rbs +1 -5
- data/sig/terminal-shop/models/view_init_response.rbs +15 -23
- data/sig/terminal-shop/pooled_net_requester.rbs +10 -3
- data/sig/terminal-shop/request_options.rbs +2 -2
- data/sig/terminal-shop/resources/address.rbs +22 -41
- data/sig/terminal-shop/resources/app.rbs +16 -34
- data/sig/terminal-shop/resources/card.rbs +18 -40
- data/sig/terminal-shop/resources/cart.rbs +22 -47
- data/sig/terminal-shop/resources/email.rbs +4 -8
- data/sig/terminal-shop/resources/order.rbs +13 -26
- data/sig/terminal-shop/resources/product.rbs +7 -16
- data/sig/terminal-shop/resources/profile.rbs +8 -16
- data/sig/terminal-shop/resources/subscription.rbs +21 -43
- data/sig/terminal-shop/resources/token.rbs +14 -32
- data/sig/terminal-shop/resources/view.rbs +3 -7
- data/sig/terminal-shop/util.rbs +9 -9
- data/sig/terminal-shop/version.rbs +1 -1
- metadata +4 -4
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,35 +360,34 @@ 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
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
370
|
+
value =
|
371
|
+
case val
|
372
|
+
in Array
|
373
|
+
val.map { _1.to_s.strip }.join(", ")
|
374
|
+
else
|
375
|
+
val&.to_s&.strip
|
376
|
+
end
|
377
|
+
[key.downcase, value]
|
398
378
|
end
|
399
379
|
end
|
400
380
|
end
|
401
381
|
|
402
|
-
# @private
|
382
|
+
# @api private
|
403
383
|
#
|
404
384
|
# An adapter that satisfies the IO interface required by `::IO.copy_stream`
|
405
385
|
class ReadIOAdapter
|
406
|
-
# @private
|
386
|
+
# @api private
|
407
387
|
#
|
408
388
|
# @param max_len [Integer, nil]
|
409
389
|
#
|
410
390
|
# @return [String]
|
411
|
-
#
|
412
391
|
private def read_enum(max_len)
|
413
392
|
case max_len
|
414
393
|
in nil
|
@@ -422,13 +401,12 @@ module TerminalShop
|
|
422
401
|
@buf.slice!(0..)
|
423
402
|
end
|
424
403
|
|
425
|
-
# @private
|
404
|
+
# @api private
|
426
405
|
#
|
427
406
|
# @param max_len [Integer, nil]
|
428
407
|
# @param out_string [String, nil]
|
429
408
|
#
|
430
409
|
# @return [String, nil]
|
431
|
-
#
|
432
410
|
def read(max_len = nil, out_string = nil)
|
433
411
|
case @stream
|
434
412
|
in nil
|
@@ -447,11 +425,12 @@ module TerminalShop
|
|
447
425
|
.tap(&@blk)
|
448
426
|
end
|
449
427
|
|
450
|
-
# @private
|
428
|
+
# @api private
|
451
429
|
#
|
452
430
|
# @param stream [String, IO, StringIO, Enumerable]
|
453
431
|
# @param blk [Proc]
|
454
432
|
#
|
433
|
+
# @yieldparam [String]
|
455
434
|
def initialize(stream, &blk)
|
456
435
|
@stream = stream.is_a?(String) ? StringIO.new(stream) : stream
|
457
436
|
@buf = String.new.b
|
@@ -462,8 +441,8 @@ module TerminalShop
|
|
462
441
|
class << self
|
463
442
|
# @param blk [Proc]
|
464
443
|
#
|
444
|
+
# @yieldparam [Enumerator::Yielder]
|
465
445
|
# @return [Enumerable]
|
466
|
-
#
|
467
446
|
def string_io(&blk)
|
468
447
|
Enumerator.new do |y|
|
469
448
|
y.define_singleton_method(:write) do
|
@@ -477,13 +456,14 @@ module TerminalShop
|
|
477
456
|
end
|
478
457
|
|
479
458
|
class << self
|
480
|
-
#
|
459
|
+
# rubocop:disable Naming/MethodParameterName
|
460
|
+
|
461
|
+
# @api private
|
481
462
|
#
|
482
463
|
# @param y [Enumerator::Yielder]
|
483
464
|
# @param boundary [String]
|
484
465
|
# @param key [Symbol, String]
|
485
466
|
# @param val [Object]
|
486
|
-
#
|
487
467
|
private def encode_multipart_formdata(y, boundary:, key:, val:)
|
488
468
|
y << "--#{boundary}\r\n"
|
489
469
|
y << "Content-Disposition: form-data"
|
@@ -516,12 +496,13 @@ module TerminalShop
|
|
516
496
|
y << "\r\n"
|
517
497
|
end
|
518
498
|
|
519
|
-
#
|
499
|
+
# rubocop:enable Naming/MethodParameterName
|
500
|
+
|
501
|
+
# @api private
|
520
502
|
#
|
521
503
|
# @param body [Object]
|
522
504
|
#
|
523
505
|
# @return [Array(String, Enumerable)]
|
524
|
-
#
|
525
506
|
private def encode_multipart_streaming(body)
|
526
507
|
boundary = SecureRandom.urlsafe_base64(60)
|
527
508
|
|
@@ -547,18 +528,19 @@ module TerminalShop
|
|
547
528
|
[boundary, strio]
|
548
529
|
end
|
549
530
|
|
550
|
-
# @private
|
531
|
+
# @api private
|
551
532
|
#
|
552
533
|
# @param headers [Hash{String=>String}]
|
553
534
|
# @param body [Object]
|
554
535
|
#
|
555
536
|
# @return [Object]
|
556
|
-
#
|
557
537
|
def encode_content(headers, body)
|
558
538
|
content_type = headers["content-type"]
|
559
539
|
case [content_type, body]
|
560
|
-
in [
|
540
|
+
in [%r{^application/(?:vnd\.api\+)?json}, Hash | Array]
|
561
541
|
[headers, JSON.fast_generate(body)]
|
542
|
+
in [%r{^application/(?:x-)?jsonl}, Enumerable]
|
543
|
+
[headers, body.lazy.map { JSON.fast_generate(_1) }]
|
562
544
|
in [%r{^multipart/form-data}, Hash | IO | StringIO]
|
563
545
|
boundary, strio = encode_multipart_streaming(body)
|
564
546
|
headers = {**headers, "content-type" => "#{content_type}; boundary=#{boundary}"}
|
@@ -570,7 +552,7 @@ module TerminalShop
|
|
570
552
|
end
|
571
553
|
end
|
572
554
|
|
573
|
-
# @private
|
555
|
+
# @api private
|
574
556
|
#
|
575
557
|
# @param headers [Hash{String=>String}, Net::HTTPHeader]
|
576
558
|
# @param stream [Enumerable]
|
@@ -578,7 +560,6 @@ module TerminalShop
|
|
578
560
|
#
|
579
561
|
# @raise [JSON::ParserError]
|
580
562
|
# @return [Object]
|
581
|
-
#
|
582
563
|
def decode_content(headers, stream:, suppress_error: false)
|
583
564
|
case headers["content-type"]
|
584
565
|
in %r{^application/(?:vnd\.api\+)?json}
|
@@ -589,11 +570,14 @@ module TerminalShop
|
|
589
570
|
raise e unless suppress_error
|
590
571
|
json
|
591
572
|
end
|
573
|
+
in %r{^application/(?:x-)?jsonl}
|
574
|
+
lines = decode_lines(stream)
|
575
|
+
chain_fused(lines) do |y|
|
576
|
+
lines.each { y << JSON.parse(_1, symbolize_names: true) }
|
577
|
+
end
|
592
578
|
in %r{^text/event-stream}
|
593
579
|
lines = decode_lines(stream)
|
594
580
|
decode_sse(lines)
|
595
|
-
in %r{^application/(?:x-)?jsonl}
|
596
|
-
decode_lines(stream)
|
597
581
|
in %r{^text/}
|
598
582
|
stream.to_a.join
|
599
583
|
else
|
@@ -604,7 +588,7 @@ module TerminalShop
|
|
604
588
|
end
|
605
589
|
|
606
590
|
class << self
|
607
|
-
# @private
|
591
|
+
# @api private
|
608
592
|
#
|
609
593
|
# https://doc.rust-lang.org/std/iter/trait.FusedIterator.html
|
610
594
|
#
|
@@ -613,7 +597,6 @@ module TerminalShop
|
|
613
597
|
# @param close [Proc]
|
614
598
|
#
|
615
599
|
# @return [Enumerable]
|
616
|
-
#
|
617
600
|
def fused_enum(enum, external: false, &close)
|
618
601
|
fused = false
|
619
602
|
iter = Enumerator.new do |y|
|
@@ -637,10 +620,9 @@ module TerminalShop
|
|
637
620
|
iter
|
638
621
|
end
|
639
622
|
|
640
|
-
# @private
|
623
|
+
# @api private
|
641
624
|
#
|
642
625
|
# @param enum [Enumerable, nil]
|
643
|
-
#
|
644
626
|
def close_fused!(enum)
|
645
627
|
return unless enum.is_a?(Enumerator)
|
646
628
|
|
@@ -649,11 +631,13 @@ module TerminalShop
|
|
649
631
|
# rubocop:enable Lint/UnreachableLoop
|
650
632
|
end
|
651
633
|
|
652
|
-
# @private
|
634
|
+
# @api private
|
653
635
|
#
|
654
636
|
# @param enum [Enumerable, nil]
|
655
637
|
# @param blk [Proc]
|
656
638
|
#
|
639
|
+
# @yieldparam [Enumerator::Yielder]
|
640
|
+
# @return [Enumerable]
|
657
641
|
def chain_fused(enum, &blk)
|
658
642
|
iter = Enumerator.new { blk.call(_1) }
|
659
643
|
fused_enum(iter) { close_fused!(enum) }
|
@@ -661,12 +645,11 @@ module TerminalShop
|
|
661
645
|
end
|
662
646
|
|
663
647
|
class << self
|
664
|
-
# @private
|
648
|
+
# @api private
|
665
649
|
#
|
666
650
|
# @param enum [Enumerable]
|
667
651
|
#
|
668
652
|
# @return [Enumerable]
|
669
|
-
#
|
670
653
|
def decode_lines(enum)
|
671
654
|
re = /(\r\n|\r|\n)/
|
672
655
|
buffer = String.new.b
|
@@ -696,14 +679,13 @@ module TerminalShop
|
|
696
679
|
end
|
697
680
|
end
|
698
681
|
|
699
|
-
# @private
|
682
|
+
# @api private
|
700
683
|
#
|
701
684
|
# https://html.spec.whatwg.org/multipage/server-sent-events.html#parsing-an-event-stream
|
702
685
|
#
|
703
686
|
# @param lines [Enumerable]
|
704
687
|
#
|
705
688
|
# @return [Hash{Symbol=>Object}]
|
706
|
-
#
|
707
689
|
def decode_sse(lines)
|
708
690
|
# rubocop:disable Metrics/BlockLength
|
709
691
|
chain_fused(lines) do |y|
|
data/lib/terminal-shop.rb
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# We already ship the preferred sorbet manifests in the package itself.
|
4
|
+
# `tapioca` currently does not offer us a way to opt out of unnecessary compilation.
|
5
|
+
if Object.const_defined?(:Tapioca) && caller_locations.any? { _1.path.end_with?("tapioca/cli.rb") }
|
6
|
+
Warning.warn(
|
7
|
+
<<~WARN
|
8
|
+
\n
|
9
|
+
⚠️ skipped loading of "terminal-shop" gem under `tapioca`.
|
10
|
+
|
11
|
+
This message is normal and expected if you are running a `tapioca` command, and does not impact `.rbi` generation.
|
12
|
+
\n
|
13
|
+
WARN
|
14
|
+
)
|
15
|
+
return
|
16
|
+
end
|
17
|
+
|
3
18
|
# Standard libraries.
|
4
19
|
require "cgi"
|
5
20
|
require "date"
|
@@ -7,6 +22,7 @@ require "erb"
|
|
7
22
|
require "etc"
|
8
23
|
require "json"
|
9
24
|
require "net/http"
|
25
|
+
require "pathname"
|
10
26
|
require "rbconfig"
|
11
27
|
require "securerandom"
|
12
28
|
require "set"
|