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

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: b9c9d4d0d855f9efb7d17ece8f3146f44c37931771161692ba1b5a300d1554e5
4
+ data.tar.gz: adc5f6e291d1236cd3ed0413719e9723c134a03a3c885711aff315f54bafc6ae
5
5
  SHA512:
6
- metadata.gz: d47c80cc764a70c4d04ce0ec5f0f82c7a374976334608d0bc2579cf58db62637f0c3def0a701756aef8b81817a840c78e7e6236cc52b48e81921fbd537ddf1c0
7
- data.tar.gz: 0daab830e1738889aa702da0b82b02b9bc5750c0b36dc7bf0e7a6c932e4430926b29047e038a335c3a3fc199b0547bd9f045e4d57b4fff7edd4370ad51896b7a
6
+ metadata.gz: c53cdb0cb66a612e7011afa8142555dbdde8de69c524df7374f3cf3b97d0c1ab2c25c3a5b88cf178c9a34042ca5f55c47a0e645b506c01bdc3581e8cae4927fa
7
+ data.tar.gz: b24e9ab0c30622e874a80461fe84589f07afb94657be500051b3535bc76cd2cbe4997d1ae500bd0dbaefafd8c3bd7a0b96855895d4d4e568693eabefe4c63786
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]
@@ -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
 
@@ -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|