You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+18Lines changed: 18 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,23 @@
1
1
# Changelog
2
2
3
+
## 0.5.0 (2025-05-14)
4
+
5
+
Full Changelog: [v0.4.0...v0.5.0](https://github.com/orbcorp/orb-ruby/compare/v0.4.0...v0.5.0)
6
+
7
+
### Features
8
+
9
+
* bump default connection pool size limit to minimum of 99 ([79f9994](https://github.com/orbcorp/orb-ruby/commit/79f9994e2a77d786a7e1ffaa52c56916835b9b5f))
10
+
11
+
12
+
### Chores
13
+
14
+
***internal:** version bump ([cfc1793](https://github.com/orbcorp/orb-ruby/commit/cfc17939f09ece0217ea7683991e509c30491e96))
15
+
16
+
17
+
### Documentation
18
+
19
+
* rewrite much of README.md for readability ([ac8a45d](https://github.com/orbcorp/orb-ruby/commit/ac8a45d8765183d41fbeaf23d1bd03c372908b45))
20
+
3
21
## 0.4.0 (2025-05-13)
4
22
5
23
Full Changelog: [v0.3.2...v0.4.0](https://github.com/orbcorp/orb-ruby/compare/v0.3.2...v0.4.0)
Copy file name to clipboardExpand all lines: README.md
+95-55Lines changed: 95 additions & 55 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -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.4.0"
18
+
gem "orb-billing", "~> 0.5.0"
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.
@@ -64,15 +54,30 @@ page.auto_paging_each do |coupon|
64
54
end
65
55
```
66
56
67
-
### Errors
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:
puts(e.cause) # an underlying Exception, likely raised within `net/http`
76
+
rescueOrb::Errors::RateLimitError => e
77
+
puts("A 429 status code was received; we should back off a bit.")
78
+
rescueOrb::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,83 +137,122 @@ orb.customers.create(
136
137
)
137
138
```
138
139
139
-
## Model DSL
140
+
On timeout, `Orb::Errors::APITimeoutError` is raised.
140
141
141
-
This library uses a simple DSL to represent request parameters and response shapes in `lib/orb/models`.
142
+
Note that requests that time out are retried by default.
142
143
143
-
With the right [editor plugins](https://shopify.github.io/ruby-lsp), you can ctrl-click on elements of the DSL to navigate around and explore the library.
144
+
## Advanced concepts
144
145
145
-
In all places where a `BaseModel` type is specified, vanilla Ruby `Hash` can also be used. For example, the following are interchangeable as arguments:
146
+
### BaseModel
146
147
147
-
```ruby
148
-
# This has tooling readability, for auto-completion, static analysis, and goto definition with supported language services
All parameter and response objects inherit from `Orb::Internal::Type::BaseModel`, which provides several conveniences, including:
150
149
151
-
# This also works
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
-
## Editor support
152
+
2. Structural equivalence for equality; if two API calls return the same values, comparing the responses with == will return true.
159
153
160
-
A combination of [Shopify LSP](https://shopify.github.io/ruby-lsp)and [Solargraph](https://solargraph.org/) is recommended for non-[Sorbet](https://sorbet.org) users. The former is especially good at go to definition, while the latter has much better auto-completion support.
154
+
3. Both instances and the classes themselves can be pretty-printed.
161
155
162
-
## Advanced concepts
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
-
### Making custom/undocumented requests
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 requests as seen in examples above.
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`. Options on the client will be respected (such as retries) when making this 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(
176
191
method::post,
177
192
path:'/undocumented/endpoint',
178
193
query: {"dog": "woof"},
179
194
headers: {"useful-header": "interesting-value"},
180
-
body: {"he": "llo"},
195
+
body: {"hello": "world"}
181
196
)
182
197
```
183
198
184
199
### Concurrency & connection pooling
185
200
186
-
The `Orb::Client` instances are thread-safe, and should be re-used across multiple threads. By default, each `Client` have their own HTTP connection pool, with a maximum number of connections equal to thread count.
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 the maximum number of connections has been checked out from the connection pool, the `Client` will wait for an in use connection to become available. The queue time for this mechanism is accounted for by the per-request timeout.
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
-
Currently, `Orb::Client` instances are only fork-safe if there are no in-flight HTTP requests.
209
+
## Sorbet
193
210
194
-
### Sorbet
211
+
This library provides comprehensive [RBI](https://sorbet.org/docs/rbi) definitions, and has no dependency on sorbet-runtime.
195
212
196
-
#### Enums
213
+
You can provide typesafe request parameters like so:
197
214
198
-
Sorbet's typed enums require sub-classing of the [`T::Enum` class](https://sorbet.org/docs/tenum) from the `sorbet-runtime` gem.
Since this library does not depend on `sorbet-runtime`, it uses a [`T.all` intersection type](https://sorbet.org/docs/intersection-types) with a ruby primitive type to construct a "tagged alias" instead.
219
+
Or, equivalently:
201
220
202
221
```ruby
203
-
moduleOrb::BillingCycleRelativeDate
204
-
# This alias aids language service driven navigation.
It is possible to pass a compatible model / parameter class to a method that expects keyword arguments by using the `**` splat operator.
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:
0 commit comments