terminal-shop 0.1.0.pre.alpha.13 → 0.1.0.pre.alpha.15

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4d0377b351b29fd528cf8cfac1ca0709534478162601101eff9c1cec288167ac
4
- data.tar.gz: 9d0178a0d2193ebf30b3d87b056e9958de8f70921088c6877ac1b40c59537a2c
3
+ metadata.gz: 4a3091f60527a7010ac8c95c545b0d74fdf801d4275fc573515a720cbe178fe8
4
+ data.tar.gz: 25cef1faf2a04c0aaf4695e8c9c5ac03b51006cb69e119efa6ffd8c8967080c0
5
5
  SHA512:
6
- metadata.gz: d47c80cc764a70c4d04ce0ec5f0f82c7a374976334608d0bc2579cf58db62637f0c3def0a701756aef8b81817a840c78e7e6236cc52b48e81921fbd537ddf1c0
7
- data.tar.gz: 0daab830e1738889aa702da0b82b02b9bc5750c0b36dc7bf0e7a6c932e4430926b29047e038a335c3a3fc199b0547bd9f045e4d57b4fff7edd4370ad51896b7a
6
+ metadata.gz: 31a440c12cd9f04c420d2baccb9d31f592d66cec2ad7bba4b240543cfd07ce5bb3a8155499154f835b13b95e737d2a70ac3fabfad3e30b3721ec7fe306124911
7
+ data.tar.gz: 0c9d51f4b0e74fd05220865b119d4a9e7f23270eafee16348fc2f5ae0369f1dc89131e19607185817f3f1dfa75d34a308728ad97b2ba15d4e3c2db82352a6e19
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  The Terminal Ruby library provides convenient access to the Terminal REST API from any Ruby 3.0.0+
4
4
  application.
5
5
 
6
- It is generated with [Stainless](https://www.stainlessapi.com/).
6
+ It is generated with [Stainless](https://www.stainless.com/).
7
7
 
8
8
  ## Documentation
9
9
 
@@ -90,15 +90,13 @@ module TerminalShop
90
90
  def follow_redirect(request, status:, response_headers:)
91
91
  method, url, headers = request.fetch_values(:method, :url, :headers)
92
92
  location =
93
- TerminalShop::Util.suppress(ArgumentError) do
93
+ Kernel.then do
94
94
  URI.join(url, response_headers["location"])
95
+ rescue ArgumentError
96
+ message = "Server responded with status #{status} but no valid location header."
97
+ raise TerminalShop::APIConnectionError.new(url: url, message: message)
95
98
  end
96
99
 
97
- unless location
98
- message = "Server responded with status #{status} but no valid location header."
99
- raise TerminalShop::APIConnectionError.new(url: url, message: message)
100
- end
101
-
102
100
  request = {**request, url: location}
103
101
 
104
102
  case [url.scheme, location.scheme]
@@ -144,7 +142,7 @@ module TerminalShop
144
142
  # @param max_retries [Integer]
145
143
  # @param initial_retry_delay [Float]
146
144
  # @param max_retry_delay [Float]
147
- # @param headers [Hash{String=>String, nil}]
145
+ # @param headers [Hash{String=>String, Integer, Array<String, Integer, nil>, nil}]
148
146
  # @param idempotency_header [String, nil]
149
147
  #
150
148
  def initialize(
@@ -195,7 +193,7 @@ module TerminalShop
195
193
  #
196
194
  # @option req [Hash{String=>Array<String>, String, nil}, nil] :query
197
195
  #
198
- # @option req [Hash{String=>String, nil}, nil] :headers
196
+ # @option req [Hash{String=>String, Integer, Array<String, Integer, nil>, nil}, nil] :headers
199
197
  #
200
198
  # @option req [Object, nil] :body
201
199
  #
@@ -286,8 +284,10 @@ module TerminalShop
286
284
  retry_header = headers["retry-after"]
287
285
  return span if (span = Float(retry_header, exception: false))
288
286
 
289
- span = retry_header && TerminalShop::Util.suppress(ArgumentError) do
290
- Time.httpdate(retry_header) - Time.now
287
+ span = retry_header&.then do
288
+ Time.httpdate(_1) - Time.now
289
+ rescue ArgumentError
290
+ nil
291
291
  end
292
292
  return span if span
293
293
 
@@ -399,7 +399,7 @@ module TerminalShop
399
399
  #
400
400
  # @option req [Hash{String=>Array<String>, String, nil}, nil] :query
401
401
  #
402
- # @option req [Hash{String=>String, nil}, nil] :headers
402
+ # @option req [Hash{String=>String, Integer, Array<String, Integer, nil>, nil}, nil] :headers
403
403
  #
404
404
  # @option req [Object, nil] :body
405
405
  #
@@ -442,7 +442,7 @@ module TerminalShop
442
442
  #
443
443
  # @option req [Hash{String=>Array<String>, String, nil}, nil] :query
444
444
  #
445
- # @option req [Hash{String=>String, nil}, nil] :headers
445
+ # @option req [Hash{String=>String, Integer, Array<String, Integer, nil>, nil}, nil] :headers
446
446
  #
447
447
  # @option req [Object, nil] :body
448
448
  #
@@ -153,10 +153,11 @@ module TerminalShop
153
153
  in [-> { _1 <= String }, Symbol]
154
154
  [true, value.to_s, 1]
155
155
  in [-> { _1 <= Date || _1 <= Time }, String]
156
- TerminalShop::Util.suppress(ArgumentError, Date::Error) do
157
- return [true, target.parse(value), 1]
156
+ Kernel.then do
157
+ [true, target.parse(value), 1]
158
+ rescue ArgumentError, Date::Error
159
+ [false, false, 0]
158
160
  end
159
- [false, false, 0]
160
161
  in [_, ^target]
161
162
  [true, value, 1]
162
163
  else
@@ -22,6 +22,9 @@ module TerminalShop
22
22
  # @return [String]
23
23
  attr_reader :bearer_token
24
24
 
25
+ # @return [String, nil]
26
+ attr_reader :app_id
27
+
25
28
  # @return [TerminalShop::Resources::Product]
26
29
  attr_reader :product
27
30
 
@@ -78,6 +81,8 @@ module TerminalShop
78
81
  #
79
82
  # @param bearer_token [String, nil] Defaults to `ENV["TERMINAL_BEARER_TOKEN"]`
80
83
  #
84
+ # @param app_id [String, nil]
85
+ #
81
86
  # @param max_retries [Integer] Max number of retries to attempt after a failed retryable request.
82
87
  #
83
88
  # @param timeout [Float]
@@ -90,6 +95,7 @@ module TerminalShop
90
95
  environment: nil,
91
96
  base_url: nil,
92
97
  bearer_token: ENV["TERMINAL_BEARER_TOKEN"],
98
+ app_id: nil,
93
99
  max_retries: DEFAULT_MAX_RETRIES,
94
100
  timeout: DEFAULT_TIMEOUT_IN_SECONDS,
95
101
  initial_retry_delay: DEFAULT_INITIAL_RETRY_DELAY,
@@ -110,6 +116,10 @@ module TerminalShop
110
116
  raise ArgumentError.new("bearer_token is required")
111
117
  end
112
118
 
119
+ headers = {
120
+ "x-terminal-app-id" => (@app_id = app_id&.to_s)
121
+ }
122
+
113
123
  @bearer_token = bearer_token.to_s
114
124
 
115
125
  super(
@@ -117,7 +127,8 @@ module TerminalShop
117
127
  timeout: timeout,
118
128
  max_retries: max_retries,
119
129
  initial_retry_delay: initial_retry_delay,
120
- max_retry_delay: max_retry_delay
130
+ max_retry_delay: max_retry_delay,
131
+ headers: headers
121
132
  )
122
133
 
123
134
  @product = TerminalShop::Resources::Product.new(client: self)
@@ -35,8 +35,7 @@ module TerminalShop
35
35
  #
36
36
  def calibrate_socket_timeout(conn, deadline)
37
37
  timeout = deadline - TerminalShop::Util.monotonic_secs
38
- (conn.open_timeout = timeout) unless conn.started?
39
- conn.read_timeout = conn.write_timeout = conn.continue_timeout = timeout
38
+ conn.open_timeout = conn.read_timeout = conn.write_timeout = conn.continue_timeout = timeout
40
39
  end
41
40
 
42
41
  # @private
@@ -134,9 +133,10 @@ module TerminalShop
134
133
  eof = false
135
134
  enum = Enumerator.new do |y|
136
135
  with_pool(url) do |conn|
137
- conn.start unless conn.started?
138
136
  self.class.calibrate_socket_timeout(conn, deadline)
137
+ conn.start unless conn.started?
139
138
 
139
+ self.class.calibrate_socket_timeout(conn, deadline)
140
140
  conn.request(req) do |rsp|
141
141
  y << [conn, rsp]
142
142
  rsp.read_body do |bytes|