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.
Files changed (171) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +27 -19
  3. data/lib/terminal-shop/base_client.rb +35 -55
  4. data/lib/terminal-shop/base_model.rb +457 -438
  5. data/lib/terminal-shop/base_page.rb +2 -2
  6. data/lib/terminal-shop/client.rb +1 -1
  7. data/lib/terminal-shop/errors.rb +3 -2
  8. data/lib/terminal-shop/models/address_get_params.rb +18 -0
  9. data/lib/terminal-shop/models/address_get_response.rb +20 -0
  10. data/lib/terminal-shop/models/app_create_params.rb +14 -2
  11. data/lib/terminal-shop/models/card_get_params.rb +18 -0
  12. data/lib/terminal-shop/models/card_get_response.rb +20 -0
  13. data/lib/terminal-shop/models/cart.rb +35 -2
  14. data/lib/terminal-shop/models/cart_convert_params.rb +11 -1
  15. data/lib/terminal-shop/models/cart_redeem_gift_card_params.rb +24 -0
  16. data/lib/terminal-shop/models/cart_redeem_gift_card_response.rb +48 -0
  17. data/lib/terminal-shop/models/cart_remove_gift_card_params.rb +18 -0
  18. data/lib/terminal-shop/models/cart_remove_gift_card_response.rb +19 -0
  19. data/lib/terminal-shop/models/product.rb +72 -46
  20. data/lib/terminal-shop/models/product_get_params.rb +18 -0
  21. data/lib/terminal-shop/models/product_get_response.rb +20 -0
  22. data/lib/terminal-shop/models/profile_update_params.rb +7 -9
  23. data/lib/terminal-shop/models/subscription.rb +0 -10
  24. data/lib/terminal-shop/models/subscription_get_params.rb +18 -0
  25. data/lib/terminal-shop/models/subscription_get_response.rb +20 -0
  26. data/lib/terminal-shop/pooled_net_requester.rb +14 -9
  27. data/lib/terminal-shop/resources/address.rb +19 -0
  28. data/lib/terminal-shop/resources/app.rb +2 -6
  29. data/lib/terminal-shop/resources/card.rb +19 -0
  30. data/lib/terminal-shop/resources/cart.rb +43 -1
  31. data/lib/terminal-shop/resources/product.rb +19 -0
  32. data/lib/terminal-shop/resources/profile.rb +3 -3
  33. data/lib/terminal-shop/resources/subscription.rb +19 -0
  34. data/lib/terminal-shop/util.rb +135 -1
  35. data/lib/terminal-shop/version.rb +1 -1
  36. data/lib/terminal-shop.rb +13 -1
  37. data/rbi/lib/terminal-shop/base_client.rbi +29 -35
  38. data/rbi/lib/terminal-shop/base_model.rbi +235 -217
  39. data/rbi/lib/terminal-shop/base_page.rbi +2 -2
  40. data/rbi/lib/terminal-shop/client.rbi +2 -2
  41. data/rbi/lib/terminal-shop/errors.rbi +11 -10
  42. data/rbi/lib/terminal-shop/models/address.rbi +2 -2
  43. data/rbi/lib/terminal-shop/models/address_create_params.rbi +3 -13
  44. data/rbi/lib/terminal-shop/models/address_create_response.rbi +2 -2
  45. data/rbi/lib/terminal-shop/models/address_delete_params.rbi +5 -2
  46. data/rbi/lib/terminal-shop/models/address_delete_response.rbi +2 -2
  47. data/rbi/lib/terminal-shop/models/address_get_params.rbi +21 -0
  48. data/rbi/lib/terminal-shop/models/address_get_response.rbi +23 -0
  49. data/rbi/lib/terminal-shop/models/address_list_params.rbi +5 -2
  50. data/rbi/lib/terminal-shop/models/address_list_response.rbi +2 -2
  51. data/rbi/lib/terminal-shop/models/app.rbi +2 -2
  52. data/rbi/lib/terminal-shop/models/app_create_params.rbi +29 -4
  53. data/rbi/lib/terminal-shop/models/app_create_response.rbi +4 -4
  54. data/rbi/lib/terminal-shop/models/app_delete_params.rbi +5 -2
  55. data/rbi/lib/terminal-shop/models/app_delete_response.rbi +2 -2
  56. data/rbi/lib/terminal-shop/models/app_get_params.rbi +5 -2
  57. data/rbi/lib/terminal-shop/models/app_get_response.rbi +2 -2
  58. data/rbi/lib/terminal-shop/models/app_list_params.rbi +5 -2
  59. data/rbi/lib/terminal-shop/models/app_list_response.rbi +2 -2
  60. data/rbi/lib/terminal-shop/models/card.rbi +4 -4
  61. data/rbi/lib/terminal-shop/models/card_collect_params.rbi +5 -2
  62. data/rbi/lib/terminal-shop/models/card_collect_response.rbi +4 -4
  63. data/rbi/lib/terminal-shop/models/card_create_params.rbi +2 -2
  64. data/rbi/lib/terminal-shop/models/card_create_response.rbi +2 -2
  65. data/rbi/lib/terminal-shop/models/card_delete_params.rbi +5 -2
  66. data/rbi/lib/terminal-shop/models/card_delete_response.rbi +2 -2
  67. data/rbi/lib/terminal-shop/models/card_get_params.rbi +21 -0
  68. data/rbi/lib/terminal-shop/models/card_get_response.rbi +23 -0
  69. data/rbi/lib/terminal-shop/models/card_list_params.rbi +5 -2
  70. data/rbi/lib/terminal-shop/models/card_list_response.rbi +2 -2
  71. data/rbi/lib/terminal-shop/models/cart.rbi +45 -9
  72. data/rbi/lib/terminal-shop/models/cart_convert_params.rbi +17 -3
  73. data/rbi/lib/terminal-shop/models/cart_convert_response.rbi +2 -2
  74. data/rbi/lib/terminal-shop/models/cart_get_params.rbi +5 -2
  75. data/rbi/lib/terminal-shop/models/cart_get_response.rbi +2 -2
  76. data/rbi/lib/terminal-shop/models/cart_redeem_gift_card_params.rbi +32 -0
  77. data/rbi/lib/terminal-shop/models/cart_redeem_gift_card_response.rbi +66 -0
  78. data/rbi/lib/terminal-shop/models/cart_remove_gift_card_params.rbi +21 -0
  79. data/rbi/lib/terminal-shop/models/cart_remove_gift_card_response.rbi +23 -0
  80. data/rbi/lib/terminal-shop/models/cart_set_address_params.rbi +2 -2
  81. data/rbi/lib/terminal-shop/models/cart_set_address_response.rbi +2 -2
  82. data/rbi/lib/terminal-shop/models/cart_set_card_params.rbi +2 -2
  83. data/rbi/lib/terminal-shop/models/cart_set_card_response.rbi +2 -2
  84. data/rbi/lib/terminal-shop/models/cart_set_item_params.rbi +2 -2
  85. data/rbi/lib/terminal-shop/models/cart_set_item_response.rbi +2 -2
  86. data/rbi/lib/terminal-shop/models/email_create_params.rbi +2 -2
  87. data/rbi/lib/terminal-shop/models/email_create_response.rbi +2 -2
  88. data/rbi/lib/terminal-shop/models/order.rbi +10 -10
  89. data/rbi/lib/terminal-shop/models/order_create_params.rbi +2 -2
  90. data/rbi/lib/terminal-shop/models/order_create_response.rbi +2 -2
  91. data/rbi/lib/terminal-shop/models/order_get_params.rbi +5 -2
  92. data/rbi/lib/terminal-shop/models/order_get_response.rbi +2 -2
  93. data/rbi/lib/terminal-shop/models/order_list_params.rbi +5 -2
  94. data/rbi/lib/terminal-shop/models/order_list_response.rbi +2 -2
  95. data/rbi/lib/terminal-shop/models/product.rbi +88 -27
  96. data/rbi/lib/terminal-shop/models/product_get_params.rbi +21 -0
  97. data/rbi/lib/terminal-shop/models/product_get_response.rbi +23 -0
  98. data/rbi/lib/terminal-shop/models/product_list_params.rbi +5 -2
  99. data/rbi/lib/terminal-shop/models/product_list_response.rbi +2 -2
  100. data/rbi/lib/terminal-shop/models/product_variant.rbi +2 -2
  101. data/rbi/lib/terminal-shop/models/profile.rbi +4 -4
  102. data/rbi/lib/terminal-shop/models/profile_me_params.rbi +5 -2
  103. data/rbi/lib/terminal-shop/models/profile_me_response.rbi +2 -2
  104. data/rbi/lib/terminal-shop/models/profile_update_params.rbi +9 -14
  105. data/rbi/lib/terminal-shop/models/profile_update_response.rbi +2 -2
  106. data/rbi/lib/terminal-shop/models/subscription.rbi +15 -13
  107. data/rbi/lib/terminal-shop/models/subscription_create_params.rbi +5 -2
  108. data/rbi/lib/terminal-shop/models/subscription_create_response.rbi +2 -2
  109. data/rbi/lib/terminal-shop/models/subscription_delete_params.rbi +5 -2
  110. data/rbi/lib/terminal-shop/models/subscription_delete_response.rbi +2 -2
  111. data/rbi/lib/terminal-shop/models/subscription_get_params.rbi +21 -0
  112. data/rbi/lib/terminal-shop/models/subscription_get_response.rbi +23 -0
  113. data/rbi/lib/terminal-shop/models/subscription_list_params.rbi +5 -2
  114. data/rbi/lib/terminal-shop/models/subscription_list_response.rbi +2 -2
  115. data/rbi/lib/terminal-shop/models/token.rbi +2 -2
  116. data/rbi/lib/terminal-shop/models/token_create_params.rbi +5 -2
  117. data/rbi/lib/terminal-shop/models/token_create_response.rbi +4 -4
  118. data/rbi/lib/terminal-shop/models/token_delete_params.rbi +5 -2
  119. data/rbi/lib/terminal-shop/models/token_delete_response.rbi +2 -2
  120. data/rbi/lib/terminal-shop/models/token_get_params.rbi +5 -2
  121. data/rbi/lib/terminal-shop/models/token_get_response.rbi +2 -2
  122. data/rbi/lib/terminal-shop/models/token_list_params.rbi +5 -2
  123. data/rbi/lib/terminal-shop/models/token_list_response.rbi +2 -2
  124. data/rbi/lib/terminal-shop/models/view_init_params.rbi +5 -2
  125. data/rbi/lib/terminal-shop/models/view_init_response.rbi +5 -15
  126. data/rbi/lib/terminal-shop/pooled_net_requester.rbi +12 -10
  127. data/rbi/lib/terminal-shop/request_options.rbi +4 -0
  128. data/rbi/lib/terminal-shop/resources/address.rbi +12 -2
  129. data/rbi/lib/terminal-shop/resources/app.rbi +3 -5
  130. data/rbi/lib/terminal-shop/resources/card.rbi +12 -2
  131. data/rbi/lib/terminal-shop/resources/cart.rbi +24 -4
  132. data/rbi/lib/terminal-shop/resources/email.rbi +2 -2
  133. data/rbi/lib/terminal-shop/resources/order.rbi +2 -2
  134. data/rbi/lib/terminal-shop/resources/product.rbi +12 -2
  135. data/rbi/lib/terminal-shop/resources/profile.rbi +5 -5
  136. data/rbi/lib/terminal-shop/resources/subscription.rbi +12 -2
  137. data/rbi/lib/terminal-shop/resources/token.rbi +2 -2
  138. data/rbi/lib/terminal-shop/resources/view.rbi +2 -2
  139. data/rbi/lib/terminal-shop/util.rbi +153 -104
  140. data/rbi/lib/terminal-shop/version.rbi +1 -1
  141. data/sig/terminal-shop/base_client.rbs +3 -7
  142. data/sig/terminal-shop/base_page.rbs +1 -1
  143. data/sig/terminal-shop/errors.rbs +2 -1
  144. data/sig/terminal-shop/models/address_get_params.rbs +19 -0
  145. data/sig/terminal-shop/models/address_get_response.rbs +18 -0
  146. data/sig/terminal-shop/models/app_create_params.rbs +12 -3
  147. data/sig/terminal-shop/models/card_get_params.rbs +18 -0
  148. data/sig/terminal-shop/models/card_get_response.rbs +18 -0
  149. data/sig/terminal-shop/models/cart.rbs +27 -2
  150. data/sig/terminal-shop/models/cart_convert_params.rbs +10 -2
  151. data/sig/terminal-shop/models/cart_redeem_gift_card_params.rbs +25 -0
  152. data/sig/terminal-shop/models/cart_redeem_gift_card_response.rbs +47 -0
  153. data/sig/terminal-shop/models/cart_remove_gift_card_params.rbs +19 -0
  154. data/sig/terminal-shop/models/cart_remove_gift_card_response.rbs +18 -0
  155. data/sig/terminal-shop/models/product.rbs +58 -17
  156. data/sig/terminal-shop/models/product_get_params.rbs +19 -0
  157. data/sig/terminal-shop/models/product_get_response.rbs +18 -0
  158. data/sig/terminal-shop/models/profile_update_params.rbs +5 -5
  159. data/sig/terminal-shop/models/subscription_get_params.rbs +19 -0
  160. data/sig/terminal-shop/models/subscription_get_response.rbs +19 -0
  161. data/sig/terminal-shop/request_options.rbs +4 -0
  162. data/sig/terminal-shop/resources/address.rbs +10 -0
  163. data/sig/terminal-shop/resources/app.rbs +0 -2
  164. data/sig/terminal-shop/resources/card.rbs +10 -0
  165. data/sig/terminal-shop/resources/cart.rbs +20 -0
  166. data/sig/terminal-shop/resources/product.rbs +10 -0
  167. data/sig/terminal-shop/resources/profile.rbs +3 -4
  168. data/sig/terminal-shop/resources/subscription.rbs +11 -0
  169. data/sig/terminal-shop/util.rbs +19 -0
  170. data/sig/terminal-shop/version.rbs +1 -1
  171. metadata +40 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4a3091f60527a7010ac8c95c545b0d74fdf801d4275fc573515a720cbe178fe8
4
- data.tar.gz: 25cef1faf2a04c0aaf4695e8c9c5ac03b51006cb69e119efa6ffd8c8967080c0
3
+ metadata.gz: 751da463435546aa646463c23f281021151b8416d6d96abd3fcb607cb4f1d2dd
4
+ data.tar.gz: 9b4b300351f7f8752b18fe11098c91b6c77fd805859f9d91aa90d85e04e4a5fe
5
5
  SHA512:
6
- metadata.gz: 31a440c12cd9f04c420d2baccb9d31f592d66cec2ad7bba4b240543cfd07ce5bb3a8155499154f835b13b95e737d2a70ac3fabfad3e30b3721ec7fe306124911
7
- data.tar.gz: 0c9d51f4b0e74fd05220865b119d4a9e7f23270eafee16348fc2f5ae0369f1dc89131e19607185817f3f1dfa75d34a308728ad97b2ba15d4e3c2db82352a6e19
6
+ metadata.gz: 200d08ede71db6dc925f78727b3e15474e825400e8ef73da2affa1ad6991b4f2832cdfe363c3b3348d308ccd5a6127288d9beea6263f819c232cbbbb82c28a6a
7
+ data.tar.gz: 433ff5cef723e81a8fef27c0d48a8e6a7cf30a3f051b1ad454cc2fc9d1e7b05e0bf70f7a995254ec265c0f2c48a980ab0a809122b885cba976de93bcf0066d7f
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # Terminal Ruby API library
2
2
 
3
- The Terminal Ruby library provides convenient access to the Terminal REST API from any Ruby 3.0.0+
4
- application.
3
+ The Terminal Ruby library provides convenient access to the Terminal REST API from any Ruby 3.0.0+ application.
5
4
 
6
5
  It is generated with [Stainless](https://www.stainless.com/).
7
6
 
@@ -13,8 +12,7 @@ The underlying REST API documentation can be found on [terminal.shop](https://te
13
12
 
14
13
  ## Installation
15
14
 
16
- To use this gem during the beta, install directly from GitHub with Bundler by
17
- adding the following to your application's `Gemfile`:
15
+ To use this gem during the beta, install directly from GitHub with Bundler by adding the following to your application's `Gemfile`:
18
16
 
19
17
  ```ruby
20
18
  gem "terminal-shop", git: "https://github.com/terminaldotshop/terminal-sdk-ruby", branch: "main"
@@ -26,8 +24,7 @@ To fetch an initial copy of the gem:
26
24
  bundle install
27
25
  ```
28
26
 
29
- To update the version used by your application when updates are pushed to
30
- GitHub:
27
+ To update the version used by your application when updates are pushed to GitHub:
31
28
 
32
29
  ```sh
33
30
  bundle update terminal-shop
@@ -51,9 +48,7 @@ puts(product.data)
51
48
 
52
49
  ### Errors
53
50
 
54
- When the library is unable to connect to the API, or if the API returns a
55
- non-success status code (i.e., 4xx or 5xx response), a subclass of
56
- `TerminalShop::Error` will be thrown:
51
+ When the library is unable to connect to the API, or if the API returns a non-success status code (i.e., 4xx or 5xx response), a subclass of `TerminalShop::Error` will be thrown:
57
52
 
58
53
  ```ruby
59
54
  begin
@@ -81,10 +76,9 @@ Error codes are as followed:
81
76
 
82
77
  ### Retries
83
78
 
84
- Certain errors will be automatically retried 2 times by default, with a short
85
- exponential backoff. Connection errors (for example, due to a network
86
- connectivity problem), 408 Request Timeout, 409 Conflict, 429 Rate Limit, >=500 Internal errors,
87
- and timeouts will all be retried by default.
79
+ Certain errors will be automatically retried 2 times by default, with a short exponential backoff.
80
+
81
+ Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict, 429 Rate Limit, >=500 Internal errors, and timeouts will all be retried by default.
88
82
 
89
83
  You can use the `max_retries` option to configure or disable this:
90
84
 
@@ -101,8 +95,8 @@ terminal.product.list(request_options: {max_retries: 5})
101
95
  ### Timeouts
102
96
 
103
97
  By default, requests will time out after 60 seconds.
104
- Timeouts are applied separately to the initial connection and the overall request time,
105
- so in some cases a request could wait 2\*timeout seconds before it fails.
98
+
99
+ Timeouts are applied separately to the initial connection and the overall request time, so in some cases a request could wait 2\*timeout seconds before it fails.
106
100
 
107
101
  You can use the `timeout` option to configure or disable this:
108
102
 
@@ -116,12 +110,26 @@ terminal = TerminalShop::Client.new(
116
110
  terminal.product.list(request_options: {timeout: 5})
117
111
  ```
118
112
 
113
+ ## Sorbet Support
114
+
115
+ This library is written with [Sorbet type definitions](https://sorbet.org/docs/rbi). However, there is no runtime dependency on the `sorbet-runtime`.
116
+
117
+ What this means is that while you can use Sorbet to type check your code statically, and benefit from the [Sorbet Language Server](https://sorbet.org/docs/lsp) in your editor, there is no runtime type checking and execution overhead from Sorbet itself.
118
+
119
+ Due to limitations with the Sorbet type system, where a method otherwise can take an instance of `TerminalShop::BaseModel` class, you will need to use the `**` splat operator to pass the arguments:
120
+
121
+ ```ruby
122
+ model = ProductListParams.new
123
+
124
+ terminal.product.list(**model)
125
+ ```
126
+
119
127
  ## Versioning
120
128
 
121
- This package follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions. As the
122
- library is in initial development and has a major version of `0`, APIs may change
123
- at any time.
129
+ This package follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions. As the library is in initial development and has a major version of `0`, APIs may change at any time.
130
+
131
+ This package considers improvements to the (non-runtime) `*.rbi` and `*.rbs` type definitions to be non-breaking changes.
124
132
 
125
133
  ## Requirements
126
134
 
127
- Ruby 3.0 or higher.
135
+ Ruby 3.0.0 or higher.
@@ -28,7 +28,7 @@ module TerminalShop
28
28
  # @raise [ArgumentError]
29
29
  #
30
30
  def validate!(req)
31
- keys = [:method, :path, :query, :headers, :body, :unwrap, :page, :model, :options]
31
+ keys = [:method, :path, :query, :headers, :body, :unwrap, :page, :stream, :model, :options]
32
32
  case req
33
33
  in Hash
34
34
  req.each_key do |k|
@@ -201,6 +201,8 @@ module TerminalShop
201
201
  #
202
202
  # @option req [Class, nil] :page
203
203
  #
204
+ # @option req [Class, nil] :stream
205
+ #
204
206
  # @option req [TerminalShop::Converter, Class, nil] :model
205
207
  #
206
208
  # @param opts [Hash{Symbol=>Object}] .
@@ -244,8 +246,8 @@ module TerminalShop
244
246
  end
245
247
 
246
248
  timeout = opts.fetch(:timeout, @timeout).to_f.clamp((0..))
247
- unless headers.key?("x-stainless-read-timeout") || timeout.zero?
248
- headers["x-stainless-read-timeout"] = timeout.to_s
249
+ unless headers.key?("x-stainless-timeout") || timeout.zero?
250
+ headers["x-stainless-timeout"] = timeout.to_s
249
251
  end
250
252
 
251
253
  headers.reject! { |_, v| v.to_s.empty? }
@@ -319,7 +321,7 @@ module TerminalShop
319
321
  # @param send_retry_header [Boolean]
320
322
  #
321
323
  # @raise [TerminalShop::APIError]
322
- # @return [Array(Net::HTTPResponse, Enumerable)]
324
+ # @return [Array(Integer, Net::HTTPResponse, Enumerable)]
323
325
  #
324
326
  private def send_request(request, redirect_count:, retry_count:, send_retry_header:)
325
327
  url, headers, max_retries, timeout = request.fetch_values(:url, :headers, :max_retries, :timeout)
@@ -342,7 +344,7 @@ module TerminalShop
342
344
 
343
345
  case status
344
346
  in ..299
345
- [response, stream]
347
+ [status, response, stream]
346
348
  in 300..399 if redirect_count >= self.class::MAX_REDIRECTS
347
349
  message = "Failed to complete the request within #{self.class::MAX_REDIRECTS} redirects."
348
350
 
@@ -360,13 +362,15 @@ module TerminalShop
360
362
  )
361
363
  in TerminalShop::APIConnectionError if retry_count >= max_retries
362
364
  raise status
363
- in (400..) if retry_count >= max_retries || (response && !self.class.should_retry?(
364
- status,
365
- headers: response
366
- ))
365
+ in (400..) if retry_count >= max_retries || !self.class.should_retry?(status, headers: response)
367
366
  decoded = TerminalShop::Util.decode_content(response, stream: stream, suppress_error: true)
368
367
 
369
- stream.each { srv_fault ? break : next }
368
+ if srv_fault
369
+ TerminalShop::Util.close_fused!(stream)
370
+ else
371
+ stream.each { next }
372
+ end
373
+
370
374
  raise TerminalShop::APIStatusError.for(
371
375
  url: url,
372
376
  status: status,
@@ -377,7 +381,11 @@ module TerminalShop
377
381
  in (400..) | TerminalShop::APIConnectionError
378
382
  delay = retry_delay(response, retry_count: retry_count)
379
383
 
380
- stream&.each { srv_fault ? break : next }
384
+ if srv_fault
385
+ TerminalShop::Util.close_fused!(stream)
386
+ else
387
+ stream&.each { next }
388
+ end
381
389
  sleep(delay)
382
390
 
383
391
  send_request(
@@ -389,48 +397,6 @@ module TerminalShop
389
397
  end
390
398
  end
391
399
 
392
- # @private
393
- #
394
- # @param req [Hash{Symbol=>Object}] .
395
- #
396
- # @option req [Symbol] :method
397
- #
398
- # @option req [String, Array<String>] :path
399
- #
400
- # @option req [Hash{String=>Array<String>, String, nil}, nil] :query
401
- #
402
- # @option req [Hash{String=>String, Integer, Array<String, Integer, nil>, nil}, nil] :headers
403
- #
404
- # @option req [Object, nil] :body
405
- #
406
- # @option req [Symbol, nil] :unwrap
407
- #
408
- # @option req [Class, nil] :page
409
- #
410
- # @option req [TerminalShop::Converter, Class, nil] :model
411
- #
412
- # @option req [TerminalShop::RequestOptions, Hash{Symbol=>Object}, nil] :options
413
- #
414
- # @param headers [Hash{String=>String}, Net::HTTPHeader]
415
- #
416
- # @param stream [Enumerable]
417
- #
418
- # @return [Object]
419
- #
420
- private def parse_response(req, headers:, stream:)
421
- decoded = TerminalShop::Util.decode_content(headers, stream: stream)
422
- unwrapped = TerminalShop::Util.dig(decoded, req[:unwrap])
423
-
424
- case [req[:page], req.fetch(:model, TerminalShop::Unknown)]
425
- in [Class => page, _]
426
- page.new(client: self, req: req, headers: headers, unwrapped: unwrapped)
427
- in [nil, Class | TerminalShop::Converter => model]
428
- TerminalShop::Converter.coerce(model, unwrapped)
429
- in [nil, nil]
430
- unwrapped
431
- end
432
- end
433
-
434
400
  # Execute the request specified by `req`. This is the method that all resource
435
401
  # methods call into.
436
402
  #
@@ -450,6 +416,8 @@ module TerminalShop
450
416
  #
451
417
  # @option req [Class, nil] :page
452
418
  #
419
+ # @option req [Class, nil] :stream
420
+ #
453
421
  # @option req [TerminalShop::Converter, Class, nil] :model
454
422
  #
455
423
  # @option req [TerminalShop::RequestOptions, Hash{Symbol=>Object}, nil] :options
@@ -459,19 +427,31 @@ module TerminalShop
459
427
  #
460
428
  def request(req)
461
429
  self.class.validate!(req)
430
+ model = req.fetch(:model) { TerminalShop::Unknown }
462
431
  opts = req[:options].to_h
463
432
  TerminalShop::RequestOptions.validate!(opts)
464
433
  request = build_request(req.except(:options), opts)
434
+ url = request.fetch(:url)
465
435
 
466
436
  # Don't send the current retry count in the headers if the caller modified the header defaults.
467
437
  send_retry_header = request.fetch(:headers)["x-stainless-retry-count"] == "0"
468
- response, stream = send_request(
438
+ status, response, stream = send_request(
469
439
  request,
470
440
  redirect_count: 0,
471
441
  retry_count: 0,
472
442
  send_retry_header: send_retry_header
473
443
  )
474
- parse_response(req, headers: response, stream: stream)
444
+
445
+ decoded = TerminalShop::Util.decode_content(response, stream: stream)
446
+ case req
447
+ in { stream: Class => st }
448
+ st.new(model: model, url: url, status: status, response: response, messages: decoded)
449
+ in { page: Class => page }
450
+ page.new(client: self, req: req, headers: response, page_data: decoded)
451
+ else
452
+ unwrapped = TerminalShop::Util.dig(decoded, req[:unwrap])
453
+ TerminalShop::Converter.coerce(model, unwrapped)
454
+ end
475
455
  end
476
456
 
477
457
  # @return [String]