orb-billing 0.4.0 → 0.5.1
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/CHANGELOG.md +27 -0
- data/README.md +95 -55
- data/lib/orb/client.rb +4 -4
- data/lib/orb/internal/transport/pooled_net_requester.rb +3 -1
- data/lib/orb/internal/type/base_model.rb +8 -0
- data/lib/orb/version.rb +1 -1
- data/rbi/orb/internal/transport/pooled_net_requester.rbi +5 -1
- data/sig/orb/internal/transport/pooled_net_requester.rbs +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2311016a3b168d7ae7594ed94985d5675b04e4cb2aa3f345c294d4ff8f096f9b
|
4
|
+
data.tar.gz: e7af6660624adb5654be1cafd70a31ef4415a3f865c3eae87fa64fe2cf67e8be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b9ffd306787ad961c41d9a04bdd7d16ec200d9d7d54f30a9a1c8690ce54db8a4797862d3d19fbc1542e89833033c8b1cd2358ff459a2c6862dcbf336cbbb40a
|
7
|
+
data.tar.gz: c3f4946a78b0f15f20f93952b80cef972ebdbc41134cf7a93d0154191d522ca74180b7a65a250bce9fcf374a09a7da4abb24ec75081267d009c18766adcca169
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,32 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.5.1 (2025-05-20)
|
4
|
+
|
5
|
+
Full Changelog: [v0.5.0...v0.5.1](https://github.com/orbcorp/orb-ruby/compare/v0.5.0...v0.5.1)
|
6
|
+
|
7
|
+
### Chores
|
8
|
+
|
9
|
+
* **internal:** version bump ([7e334e0](https://github.com/orbcorp/orb-ruby/commit/7e334e07c272ab3a1e2d155a02b6eb7396afafe2))
|
10
|
+
* whitespaces ([8481024](https://github.com/orbcorp/orb-ruby/commit/848102400193de0f80cc1d0cd12471486e072162))
|
11
|
+
|
12
|
+
## 0.5.0 (2025-05-14)
|
13
|
+
|
14
|
+
Full Changelog: [v0.4.0...v0.5.0](https://github.com/orbcorp/orb-ruby/compare/v0.4.0...v0.5.0)
|
15
|
+
|
16
|
+
### Features
|
17
|
+
|
18
|
+
* bump default connection pool size limit to minimum of 99 ([79f9994](https://github.com/orbcorp/orb-ruby/commit/79f9994e2a77d786a7e1ffaa52c56916835b9b5f))
|
19
|
+
|
20
|
+
|
21
|
+
### Chores
|
22
|
+
|
23
|
+
* **internal:** version bump ([cfc1793](https://github.com/orbcorp/orb-ruby/commit/cfc17939f09ece0217ea7683991e509c30491e96))
|
24
|
+
|
25
|
+
|
26
|
+
### Documentation
|
27
|
+
|
28
|
+
* rewrite much of README.md for readability ([ac8a45d](https://github.com/orbcorp/orb-ruby/commit/ac8a45d8765183d41fbeaf23d1bd03c372908b45))
|
29
|
+
|
3
30
|
## 0.4.0 (2025-05-13)
|
4
31
|
|
5
32
|
Full Changelog: [v0.3.2...v0.4.0](https://github.com/orbcorp/orb-ruby/compare/v0.3.2...v0.4.0)
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Orb Ruby API library
|
2
2
|
|
3
|
-
The Orb Ruby library provides convenient access to the Orb REST API from any Ruby 3.2.0+ application.
|
3
|
+
The Orb Ruby library provides convenient access to the Orb REST API from any Ruby 3.2.0+ application. It ships with comprehensive types & docstrings in Yard, RBS, and RBI – [see below](https://github.com/orbcorp/orb-ruby#Sorbet) for usage with Sorbet. The standard library's `net/http` is used as the HTTP transport, with connection pooling via the `connection_pool` gem.
|
4
4
|
|
5
5
|
## Documentation
|
6
6
|
|
@@ -15,7 +15,7 @@ To use this gem, install via Bundler by adding the following to your application
|
|
15
15
|
<!-- x-release-please-start-version -->
|
16
16
|
|
17
17
|
```ruby
|
18
|
-
gem "orb-billing", "~> 0.
|
18
|
+
gem "orb-billing", "~> 0.5.1"
|
19
19
|
```
|
20
20
|
|
21
21
|
<!-- x-release-please-end -->
|
@@ -35,16 +35,6 @@ customer = orb.customers.create(email: "example-customer@withorb.com", name: "My
|
|
35
35
|
puts(customer.id)
|
36
36
|
```
|
37
37
|
|
38
|
-
## Sorbet
|
39
|
-
|
40
|
-
This library is written with [Sorbet type definitions](https://sorbet.org/docs/rbi). However, there is no runtime dependency on the `sorbet-runtime`.
|
41
|
-
|
42
|
-
When using sorbet, it is recommended to use model classes as below. This provides stronger type checking and tooling integration.
|
43
|
-
|
44
|
-
```ruby
|
45
|
-
orb.customers.create(email: "example-customer@withorb.com", name: "My Customer")
|
46
|
-
```
|
47
|
-
|
48
38
|
### Pagination
|
49
39
|
|
50
40
|
List methods in the Orb API are paginated.
|
@@ -64,15 +54,30 @@ page.auto_paging_each do |coupon|
|
|
64
54
|
end
|
65
55
|
```
|
66
56
|
|
67
|
-
|
57
|
+
Alternatively, you can use the `#next_page?` and `#next_page` methods for more granular control working with pages.
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
if page.next_page?
|
61
|
+
new_page = page.next_page
|
62
|
+
puts(new_page.data[0].id)
|
63
|
+
end
|
64
|
+
```
|
65
|
+
|
66
|
+
### Handling errors
|
68
67
|
|
69
68
|
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 `Orb::Errors::APIError` will be thrown:
|
70
69
|
|
71
70
|
```ruby
|
72
71
|
begin
|
73
72
|
customer = orb.customers.create(email: "example-customer@withorb.com", name: "My Customer")
|
74
|
-
rescue Orb::Errors::
|
75
|
-
puts(
|
73
|
+
rescue Orb::Errors::APIConnectionError => e
|
74
|
+
puts("The server could not be reached")
|
75
|
+
puts(e.cause) # an underlying Exception, likely raised within `net/http`
|
76
|
+
rescue Orb::Errors::RateLimitError => e
|
77
|
+
puts("A 429 status code was received; we should back off a bit.")
|
78
|
+
rescue Orb::Errors::APIStatusError => e
|
79
|
+
puts("Another non-200-range status code was received")
|
80
|
+
puts(e.status)
|
76
81
|
end
|
77
82
|
```
|
78
83
|
|
@@ -116,11 +121,7 @@ orb.customers.create(
|
|
116
121
|
|
117
122
|
### Timeouts
|
118
123
|
|
119
|
-
By default, requests will time out after 60 seconds.
|
120
|
-
|
121
|
-
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.
|
122
|
-
|
123
|
-
You can use the `timeout` option to configure or disable this:
|
124
|
+
By default, requests will time out after 60 seconds. You can use the timeout option to configure or disable this:
|
124
125
|
|
125
126
|
```ruby
|
126
127
|
# Configure the default for all requests:
|
@@ -136,40 +137,54 @@ orb.customers.create(
|
|
136
137
|
)
|
137
138
|
```
|
138
139
|
|
139
|
-
|
140
|
+
On timeout, `Orb::Errors::APITimeoutError` is raised.
|
140
141
|
|
141
|
-
|
142
|
+
Note that requests that time out are retried by default.
|
142
143
|
|
143
|
-
|
144
|
+
## Advanced concepts
|
144
145
|
|
145
|
-
|
146
|
+
### BaseModel
|
146
147
|
|
147
|
-
|
148
|
-
# This has tooling readability, for auto-completion, static analysis, and goto definition with supported language services
|
149
|
-
params = Orb::Models::CustomerCreateParams.new(email: "example-customer@withorb.com", name: "My Customer")
|
148
|
+
All parameter and response objects inherit from `Orb::Internal::Type::BaseModel`, which provides several conveniences, including:
|
150
149
|
|
151
|
-
|
152
|
-
params = {
|
153
|
-
email: "example-customer@withorb.com",
|
154
|
-
name: "My Customer"
|
155
|
-
}
|
156
|
-
```
|
150
|
+
1. All fields, including unknown ones, are accessible with `obj[:prop]` syntax, and can be destructured with `obj => {prop: prop}` or pattern-matching syntax.
|
157
151
|
|
158
|
-
|
152
|
+
2. Structural equivalence for equality; if two API calls return the same values, comparing the responses with == will return true.
|
159
153
|
|
160
|
-
|
154
|
+
3. Both instances and the classes themselves can be pretty-printed.
|
161
155
|
|
162
|
-
|
156
|
+
4. Helpers such as `#to_h`, `#deep_to_h`, `#to_json`, and `#to_yaml`.
|
157
|
+
|
158
|
+
### Making custom or undocumented requests
|
159
|
+
|
160
|
+
#### Undocumented properties
|
163
161
|
|
164
|
-
|
162
|
+
You can send undocumented parameters to any endpoint, and read undocumented response properties, like so:
|
163
|
+
|
164
|
+
Note: the `extra_` parameters of the same name overrides the documented parameters.
|
165
|
+
|
166
|
+
```ruby
|
167
|
+
customer =
|
168
|
+
orb.customers.create(
|
169
|
+
email: "example-customer@withorb.com",
|
170
|
+
name: "My Customer",
|
171
|
+
request_options: {
|
172
|
+
extra_query: {my_query_parameter: value},
|
173
|
+
extra_body: {my_body_parameter: value},
|
174
|
+
extra_headers: {"my-header": value}
|
175
|
+
}
|
176
|
+
)
|
177
|
+
|
178
|
+
puts(customer[:my_undocumented_property])
|
179
|
+
```
|
165
180
|
|
166
181
|
#### Undocumented request params
|
167
182
|
|
168
|
-
If you want to explicitly send an extra param, you can do so with the `extra_query`, `extra_body`, and `extra_headers` under the `request_options:` parameter when making a
|
183
|
+
If you want to explicitly send an extra param, you can do so with the `extra_query`, `extra_body`, and `extra_headers` under the `request_options:` parameter when making a request as seen in examples above.
|
169
184
|
|
170
185
|
#### Undocumented endpoints
|
171
186
|
|
172
|
-
To make requests to undocumented endpoints, you can make requests using `client.request
|
187
|
+
To make requests to undocumented endpoints while retaining the benefit of auth, retries, and so on, you can make requests using `client.request`, like so:
|
173
188
|
|
174
189
|
```ruby
|
175
190
|
response = client.request(
|
@@ -177,42 +192,67 @@ response = client.request(
|
|
177
192
|
path: '/undocumented/endpoint',
|
178
193
|
query: {"dog": "woof"},
|
179
194
|
headers: {"useful-header": "interesting-value"},
|
180
|
-
body: {"
|
195
|
+
body: {"hello": "world"}
|
181
196
|
)
|
182
197
|
```
|
183
198
|
|
184
199
|
### Concurrency & connection pooling
|
185
200
|
|
186
|
-
The `Orb::Client` instances are
|
201
|
+
The `Orb::Client` instances are threadsafe, but only are fork-safe when there are no in-flight HTTP requests.
|
202
|
+
|
203
|
+
Each instance of `Orb::Client` has its own HTTP connection pool with a default size of 99. As such, we recommend instantiating the client once per application in most settings.
|
187
204
|
|
188
|
-
When
|
205
|
+
When all available connections from the pool are checked out, requests wait for a new connection to become available, with queue time counting towards the request timeout.
|
189
206
|
|
190
207
|
Unless otherwise specified, other classes in the SDK do not have locks protecting their underlying data structure.
|
191
208
|
|
192
|
-
|
209
|
+
## Sorbet
|
193
210
|
|
194
|
-
|
211
|
+
This library provides comprehensive [RBI](https://sorbet.org/docs/rbi) definitions, and has no dependency on sorbet-runtime.
|
195
212
|
|
196
|
-
|
213
|
+
You can provide typesafe request parameters like so:
|
197
214
|
|
198
|
-
|
215
|
+
```ruby
|
216
|
+
orb.customers.create(email: "example-customer@withorb.com", name: "My Customer")
|
217
|
+
```
|
199
218
|
|
200
|
-
|
219
|
+
Or, equivalently:
|
201
220
|
|
202
221
|
```ruby
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
222
|
+
# Hashes work, but are not typesafe:
|
223
|
+
orb.customers.create(email: "example-customer@withorb.com", name: "My Customer")
|
224
|
+
|
225
|
+
# You can also splat a full Params class:
|
226
|
+
params = Orb::CustomerCreateParams.new(email: "example-customer@withorb.com", name: "My Customer")
|
227
|
+
orb.customers.create(**params)
|
207
228
|
```
|
208
229
|
|
209
|
-
|
230
|
+
### Enums
|
210
231
|
|
211
|
-
|
232
|
+
Since this library does not depend on `sorbet-runtime`, it cannot provide [`T::Enum`](https://sorbet.org/docs/tenum) instances. Instead, we provide "tagged symbols" instead, which is always a primitive at runtime:
|
212
233
|
|
213
234
|
```ruby
|
214
|
-
|
215
|
-
|
235
|
+
# :duplicate
|
236
|
+
puts(Orb::CreditNoteCreateParams::Reason::DUPLICATE)
|
237
|
+
|
238
|
+
# Revealed type: `T.all(Orb::CreditNoteCreateParams::Reason, Symbol)`
|
239
|
+
T.reveal_type(Orb::CreditNoteCreateParams::Reason::DUPLICATE)
|
240
|
+
```
|
241
|
+
|
242
|
+
Enum parameters have a "relaxed" type, so you can either pass in enum constants or their literal value:
|
243
|
+
|
244
|
+
```ruby
|
245
|
+
# Using the enum constants preserves the tagged type information:
|
246
|
+
orb.credit_notes.create(
|
247
|
+
reason: Orb::CreditNoteCreateParams::Reason::DUPLICATE,
|
248
|
+
# …
|
249
|
+
)
|
250
|
+
|
251
|
+
# Literal values is also permissible:
|
252
|
+
orb.credit_notes.create(
|
253
|
+
reason: :duplicate,
|
254
|
+
# …
|
255
|
+
)
|
216
256
|
```
|
217
257
|
|
218
258
|
## Versioning
|
data/lib/orb/client.rb
CHANGED
@@ -91,10 +91,10 @@ module Orb
|
|
91
91
|
def initialize(
|
92
92
|
api_key: ENV["ORB_API_KEY"],
|
93
93
|
base_url: ENV["ORB_BASE_URL"],
|
94
|
-
max_retries:
|
95
|
-
timeout:
|
96
|
-
initial_retry_delay:
|
97
|
-
max_retry_delay:
|
94
|
+
max_retries: self.class::DEFAULT_MAX_RETRIES,
|
95
|
+
timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS,
|
96
|
+
initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY,
|
97
|
+
max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY,
|
98
98
|
idempotency_header: "Idempotency-Key"
|
99
99
|
)
|
100
100
|
base_url ||= "https://api.withorb.com/v1"
|
@@ -11,6 +11,8 @@ module Orb
|
|
11
11
|
# https://github.com/golang/go/blob/c8eced8580028328fde7c03cbfcb720ce15b2358/src/net/http/transport.go#L49
|
12
12
|
KEEP_ALIVE_TIMEOUT = 30
|
13
13
|
|
14
|
+
DEFAULT_MAX_CONNECTIONS = [Etc.nprocessors, 99].max
|
15
|
+
|
14
16
|
class << self
|
15
17
|
# @api private
|
16
18
|
#
|
@@ -184,7 +186,7 @@ module Orb
|
|
184
186
|
# @api private
|
185
187
|
#
|
186
188
|
# @param size [Integer]
|
187
|
-
def initialize(size:
|
189
|
+
def initialize(size: self.class::DEFAULT_MAX_CONNECTIONS)
|
188
190
|
@mutex = Mutex.new
|
189
191
|
@size = size
|
190
192
|
@pools = {}
|
@@ -386,6 +386,14 @@ module Orb
|
|
386
386
|
# @param keys [Array<Symbol>, nil]
|
387
387
|
#
|
388
388
|
# @return [Hash{Symbol=>Object}]
|
389
|
+
#
|
390
|
+
# @example
|
391
|
+
# # `amount_discount` is a `Orb::AmountDiscount`
|
392
|
+
# amount_discount => {
|
393
|
+
# amount_discount: amount_discount,
|
394
|
+
# applies_to_price_ids: applies_to_price_ids,
|
395
|
+
# discount_type: discount_type
|
396
|
+
# }
|
389
397
|
def deconstruct_keys(keys)
|
390
398
|
(keys || self.class.known_fields.keys)
|
391
399
|
.filter_map do |k|
|
data/lib/orb/version.rb
CHANGED
@@ -22,6 +22,8 @@ module Orb
|
|
22
22
|
# https://github.com/golang/go/blob/c8eced8580028328fde7c03cbfcb720ce15b2358/src/net/http/transport.go#L49
|
23
23
|
KEEP_ALIVE_TIMEOUT = 30
|
24
24
|
|
25
|
+
DEFAULT_MAX_CONNECTIONS = T.let(T.unsafe(nil), Integer)
|
26
|
+
|
25
27
|
class << self
|
26
28
|
# @api private
|
27
29
|
sig { params(url: URI::Generic).returns(Net::HTTP) }
|
@@ -66,7 +68,9 @@ module Orb
|
|
66
68
|
|
67
69
|
# @api private
|
68
70
|
sig { params(size: Integer).returns(T.attached_class) }
|
69
|
-
def self.new(
|
71
|
+
def self.new(
|
72
|
+
size: Orb::Internal::Transport::PooledNetRequester::DEFAULT_MAX_CONNECTIONS
|
73
|
+
)
|
70
74
|
end
|
71
75
|
end
|
72
76
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: orb-billing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Orb
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-05-
|
11
|
+
date: 2025-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: connection_pool
|