terminal-shop 1.7.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.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -1
  3. data/lib/terminal-shop/base_client.rb +36 -46
  4. data/lib/terminal-shop/base_model.rb +65 -130
  5. data/lib/terminal-shop/base_page.rb +18 -18
  6. data/lib/terminal-shop/client.rb +1 -3
  7. data/lib/terminal-shop/errors.rb +12 -17
  8. data/lib/terminal-shop/extern.rb +1 -4
  9. data/lib/terminal-shop/models/subscription.rb +6 -0
  10. data/lib/terminal-shop/pooled_net_requester.rb +19 -21
  11. data/lib/terminal-shop/request_options.rb +4 -11
  12. data/lib/terminal-shop/resources/address.rb +0 -5
  13. data/lib/terminal-shop/resources/app.rb +0 -5
  14. data/lib/terminal-shop/resources/card.rb +0 -6
  15. data/lib/terminal-shop/resources/cart.rb +0 -7
  16. data/lib/terminal-shop/resources/email.rb +0 -2
  17. data/lib/terminal-shop/resources/order.rb +0 -4
  18. data/lib/terminal-shop/resources/product.rb +0 -3
  19. data/lib/terminal-shop/resources/profile.rb +0 -3
  20. data/lib/terminal-shop/resources/subscription.rb +0 -5
  21. data/lib/terminal-shop/resources/token.rb +0 -5
  22. data/lib/terminal-shop/resources/view.rb +0 -2
  23. data/lib/terminal-shop/util.rb +44 -71
  24. data/lib/terminal-shop/version.rb +1 -1
  25. data/lib/terminal-shop.rb +1 -0
  26. data/manifest.yaml +1 -0
  27. data/rbi/lib/terminal-shop/base_client.rbi +23 -0
  28. data/rbi/lib/terminal-shop/base_model.rbi +178 -52
  29. data/rbi/lib/terminal-shop/base_page.rbi +1 -2
  30. data/rbi/lib/terminal-shop/client.rbi +11 -0
  31. data/rbi/lib/terminal-shop/errors.rbi +33 -0
  32. data/rbi/lib/terminal-shop/extern.rbi +1 -1
  33. data/rbi/lib/terminal-shop/models/address.rbi +10 -0
  34. data/rbi/lib/terminal-shop/models/address_create_params.rbi +8 -0
  35. data/rbi/lib/terminal-shop/models/address_create_response.rbi +1 -0
  36. data/rbi/lib/terminal-shop/models/address_get_response.rbi +1 -0
  37. data/rbi/lib/terminal-shop/models/address_list_response.rbi +1 -0
  38. data/rbi/lib/terminal-shop/models/app.rbi +5 -0
  39. data/rbi/lib/terminal-shop/models/app_create_response.rbi +2 -0
  40. data/rbi/lib/terminal-shop/models/app_get_response.rbi +1 -0
  41. data/rbi/lib/terminal-shop/models/app_list_response.rbi +1 -0
  42. data/rbi/lib/terminal-shop/models/card.rbi +8 -0
  43. data/rbi/lib/terminal-shop/models/card_collect_response.rbi +4 -0
  44. data/rbi/lib/terminal-shop/models/card_create_params.rbi +2 -0
  45. data/rbi/lib/terminal-shop/models/card_create_response.rbi +1 -0
  46. data/rbi/lib/terminal-shop/models/card_get_response.rbi +1 -0
  47. data/rbi/lib/terminal-shop/models/card_list_response.rbi +1 -0
  48. data/rbi/lib/terminal-shop/models/cart.rbi +19 -0
  49. data/rbi/lib/terminal-shop/models/cart_convert_response.rbi +1 -0
  50. data/rbi/lib/terminal-shop/models/cart_get_response.rbi +1 -0
  51. data/rbi/lib/terminal-shop/models/cart_set_address_params.rbi +1 -0
  52. data/rbi/lib/terminal-shop/models/cart_set_card_params.rbi +1 -0
  53. data/rbi/lib/terminal-shop/models/cart_set_item_params.rbi +2 -0
  54. data/rbi/lib/terminal-shop/models/cart_set_item_response.rbi +1 -0
  55. data/rbi/lib/terminal-shop/models/email_create_params.rbi +1 -0
  56. data/rbi/lib/terminal-shop/models/order.rbi +28 -0
  57. data/rbi/lib/terminal-shop/models/order_create_params.rbi +3 -0
  58. data/rbi/lib/terminal-shop/models/order_create_response.rbi +1 -0
  59. data/rbi/lib/terminal-shop/models/order_get_response.rbi +1 -0
  60. data/rbi/lib/terminal-shop/models/order_list_response.rbi +1 -0
  61. data/rbi/lib/terminal-shop/models/product.rbi +12 -6
  62. data/rbi/lib/terminal-shop/models/product_get_response.rbi +1 -0
  63. data/rbi/lib/terminal-shop/models/product_list_response.rbi +1 -0
  64. data/rbi/lib/terminal-shop/models/product_variant.rbi +4 -0
  65. data/rbi/lib/terminal-shop/models/profile.rbi +8 -0
  66. data/rbi/lib/terminal-shop/models/profile_me_response.rbi +1 -0
  67. data/rbi/lib/terminal-shop/models/profile_update_response.rbi +1 -0
  68. data/rbi/lib/terminal-shop/models/region.rbi +3 -6
  69. data/rbi/lib/terminal-shop/models/subscription.rbi +18 -11
  70. data/rbi/lib/terminal-shop/models/subscription_get_response.rbi +1 -0
  71. data/rbi/lib/terminal-shop/models/subscription_list_response.rbi +1 -0
  72. data/rbi/lib/terminal-shop/models/token.rbi +5 -0
  73. data/rbi/lib/terminal-shop/models/token_create_response.rbi +3 -0
  74. data/rbi/lib/terminal-shop/models/token_get_response.rbi +2 -0
  75. data/rbi/lib/terminal-shop/models/token_list_response.rbi +1 -0
  76. data/rbi/lib/terminal-shop/models/view_init_response.rbi +5 -0
  77. data/rbi/lib/terminal-shop/pooled_net_requester.rbi +10 -3
  78. data/rbi/lib/terminal-shop/request_options.rbi +21 -2
  79. data/rbi/lib/terminal-shop/resources/address.rbi +22 -2
  80. data/rbi/lib/terminal-shop/resources/app.rbi +14 -2
  81. data/rbi/lib/terminal-shop/resources/card.rbi +22 -3
  82. data/rbi/lib/terminal-shop/resources/cart.rbi +23 -3
  83. data/rbi/lib/terminal-shop/resources/email.rbi +6 -1
  84. data/rbi/lib/terminal-shop/resources/order.rbi +17 -2
  85. data/rbi/lib/terminal-shop/resources/product.rbi +7 -1
  86. data/rbi/lib/terminal-shop/resources/profile.rbi +2 -0
  87. data/rbi/lib/terminal-shop/resources/subscription.rbi +21 -2
  88. data/rbi/lib/terminal-shop/resources/token.rbi +14 -2
  89. data/rbi/lib/terminal-shop/resources/view.rbi +2 -0
  90. data/rbi/lib/terminal-shop/util.rbi +55 -8
  91. data/rbi/lib/terminal-shop/version.rbi +1 -1
  92. data/sig/terminal-shop/base_client.rbs +6 -1
  93. data/sig/terminal-shop/base_model.rbs +8 -6
  94. data/sig/terminal-shop/errors.rbs +4 -4
  95. data/sig/terminal-shop/models/subscription.rbs +1 -1
  96. data/sig/terminal-shop/pooled_net_requester.rbs +7 -2
  97. data/sig/terminal-shop/util.rbs +4 -4
  98. data/sig/terminal-shop/version.rbs +1 -1
  99. metadata +4 -4
@@ -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
@@ -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, Object]
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 ["application/json", Hash | Array]
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|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TerminalShop
4
- VERSION = "1.7.0"
4
+ VERSION = "1.8.0"
5
5
  end
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"
data/manifest.yaml CHANGED
@@ -5,6 +5,7 @@ dependencies:
5
5
  - etc
6
6
  - json
7
7
  - net/http
8
+ - pathname
8
9
  - rbconfig
9
10
  - securerandom
10
11
  - set
@@ -1,6 +1,7 @@
1
1
  # typed: strong
2
2
 
3
3
  module TerminalShop
4
+ # @api private
4
5
  class BaseClient
5
6
  abstract!
6
7
 
@@ -44,16 +45,19 @@ module TerminalShop
44
45
  PLATFORM_HEADERS = T::Hash[String, String]
45
46
 
46
47
  class << self
48
+ # @api private
47
49
  sig { params(req: TerminalShop::BaseClient::RequestComponentsShape).void }
48
50
  def validate!(req)
49
51
  end
50
52
 
53
+ # @api private
51
54
  sig do
52
55
  params(status: Integer, headers: T.any(T::Hash[String, String], Net::HTTPHeader)).returns(T::Boolean)
53
56
  end
54
57
  def should_retry?(status, headers:)
55
58
  end
56
59
 
60
+ # @api private
57
61
  sig do
58
62
  params(
59
63
  request: TerminalShop::BaseClient::RequestInputShape,
@@ -64,6 +68,17 @@ module TerminalShop
64
68
  end
65
69
  def follow_redirect(request, status:, response_headers:)
66
70
  end
71
+
72
+ # @api private
73
+ sig do
74
+ params(
75
+ status: T.any(Integer, TerminalShop::APIConnectionError),
76
+ stream: T.nilable(T::Enumerable[String])
77
+ )
78
+ .void
79
+ end
80
+ def reap_connection!(status, stream:)
81
+ end
67
82
  end
68
83
 
69
84
  sig { returns(T.anything) }
@@ -74,6 +89,7 @@ module TerminalShop
74
89
  def requester=(_)
75
90
  end
76
91
 
92
+ # @api private
77
93
  sig do
78
94
  params(
79
95
  base_url: String,
@@ -98,14 +114,17 @@ module TerminalShop
98
114
  )
99
115
  end
100
116
 
117
+ # @api private
101
118
  sig { overridable.returns(T::Hash[String, String]) }
102
119
  private def auth_headers
103
120
  end
104
121
 
122
+ # @api private
105
123
  sig { returns(String) }
106
124
  private def generate_idempotency_key
107
125
  end
108
126
 
127
+ # @api private
109
128
  sig do
110
129
  overridable
111
130
  .params(req: TerminalShop::BaseClient::RequestComponentsShape, opts: T::Hash[Symbol, T.anything])
@@ -114,10 +133,12 @@ module TerminalShop
114
133
  private def build_request(req, opts)
115
134
  end
116
135
 
136
+ # @api private
117
137
  sig { params(headers: T::Hash[String, String], retry_count: Integer).returns(Float) }
118
138
  private def retry_delay(headers, retry_count:)
119
139
  end
120
140
 
141
+ # @api private
121
142
  sig do
122
143
  params(
123
144
  request: TerminalShop::BaseClient::RequestInputShape,
@@ -130,6 +151,8 @@ module TerminalShop
130
151
  private def send_request(request, redirect_count:, retry_count:, send_retry_header:)
131
152
  end
132
153
 
154
+ # Execute the request specified by `req`. This is the method that all resource
155
+ # methods call into.
133
156
  sig do
134
157
  params(
135
158
  method: Symbol,