Skip to content

Commit 6e04e50

Browse files
chore: documentation improvements
1 parent a94843b commit 6e04e50

File tree

3 files changed

+61
-58
lines changed

3 files changed

+61
-58
lines changed

README.md

Lines changed: 59 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ customer = orb.customers.create(email: "example-customer@withorb.com", name: "My
3535
puts(customer.id)
3636
```
3737

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+
3848
### Pagination
3949

4050
List methods in the Orb API are paginated.
@@ -126,61 +136,35 @@ orb.customers.create(
126136
)
127137
```
128138

129-
## LSP Support
130-
131-
### Solargraph
139+
## Editor support
132140

133-
This library includes [Solargraph](https://solargraph.org) support for both auto completion and go to definition.
141+
Some editor language services like [Solargraph](https://github.com/castwide/solargraph?tab=readme-ov-file#gem-support) or [Sorbet](https://sorbet.org/docs/rbi#the-hidden-definitions-rbi) require a manually triggered indexing step before functionalities like auto-completion and go to definition can operate.
134142

135-
```ruby
136-
gem "solargraph", group: :development
137-
```
143+
Please refer to their respective documentation for details. This library also includes a [short guide](https://github.com/orbcorp/orb-ruby/tree/main/CONTRIBUTING.md#editor-support) on how to set up various editor services for internal development.
138144

139-
After Solargraph is installed, **you must populate its index** either via the provided editor command, or by running the following in your terminal:
145+
## Advanced Concepts
140146

141-
```sh
142-
bundle exec solargraph gems
143-
```
147+
### Model DSL
144148

145-
Note: if you had installed the gem either using a `git:` or `github:` URL, or had vendored the gem using bundler, you will need to set up your [`.solargraph.yml`](https://solargraph.org/guides/configuration) to include the path to the gem's `lib` directory.
149+
This library uses a Model DSL to represent request parameters and response shapes in `lib/orb/models`.
146150

147-
```yaml
148-
include:
149-
- 'vendor/bundle/ruby/*/gems/orb-billing-*/lib/**/*.rb'
150-
```
151+
The model classes service as anchor points for both toolchain readable documentation, and language service assisted navigation links. This information also allows the SDK's internals to perform translation between plain and rich data types; e.g., conversion between a `Time` instance and an ISO8601 `String`, and vice versa.
151152

152-
Otherwise Solargraph will not be able to provide type information or auto-completion for any non-indexed libraries.
153-
154-
### Sorbet
155-
156-
This library is written with [Sorbet type definitions](https://sorbet.org/docs/rbi). However, there is no runtime dependency on the `sorbet-runtime`.
157-
158-
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.
159-
160-
Due to limitations with the Sorbet type system, where a method otherwise can take an instance of `Orb::BaseModel` class, you will need to use the `**` splat operator to pass the arguments:
161-
162-
Please follow Sorbet's [setup guides](https://sorbet.org/docs/adopting) for best experience.
153+
In all places where a `BaseModel` type is specified, vanilla Ruby `Hash` can also be used. For example, the following are interchangeable as arguments:
163154

164155
```ruby
156+
# This has tooling readability, for auto-completion, static analysis, and goto definition with supported language services
165157
params = Orb::Models::CustomerCreateParams.new(email: "example-customer@withorb.com", name: "My Customer")
166158

167-
orb.customers.create(**params)
159+
# This also works
160+
params = {
161+
email: "example-customer@withorb.com",
162+
name: "My Customer"
163+
}
168164
```
169165

170-
Note: **This library emits an intentional warning under the [`tapioca` toolchain](https://github.com/Shopify/tapioca)**. This is normal, and does not impact functionality.
171-
172-
### Ruby LSP
173-
174-
The Ruby LSP has [best effort support](https://shopify.github.io/ruby-lsp/#guessed-types) for inferring type information from Ruby code, and as such it may not always be able to provide accurate type information.
175-
176-
## Advanced
177-
178166
### Making custom/undocumented requests
179167

180-
This library is typed for convenient access to the documented API.
181-
182-
If you need to access undocumented endpoints, params, or response properties, the library can still be used.
183-
184168
#### Undocumented request params
185169

186170
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.
@@ -191,15 +175,15 @@ To make requests to undocumented endpoints, you can make requests using `client.
191175

192176
```ruby
193177
response = client.request(
194-
method: :post,
195-
path: '/undocumented/endpoint',
196-
query: {"dog": "woof"},
197-
headers: {"useful-header": "interesting-value"},
198-
body: {"he": "llo"},
199-
)
178+
method: :post,
179+
path: '/undocumented/endpoint',
180+
query: {"dog": "woof"},
181+
headers: {"useful-header": "interesting-value"},
182+
body: {"he": "llo"},
183+
)
200184
```
201185

202-
### Concurrency & Connection Pooling
186+
### Concurrency & connection pooling
203187

204188
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.
205189

@@ -209,6 +193,30 @@ Unless otherwise specified, other classes in the SDK do not have locks protectin
209193

210194
Currently, `Orb::Client` instances are only fork-safe if there are no in-flight HTTP requests.
211195

196+
### Sorbet
197+
198+
#### Enums
199+
200+
Sorbet's typed enums require sub-classing of the [`T::Enum` class](https://sorbet.org/docs/tenum) from the `sorbet-runtime` gem.
201+
202+
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.
203+
204+
```ruby
205+
module Orb::Models::BillingCycleRelativeDate
206+
# This alias aids language service driven navigation.
207+
TaggedSymbol = T.type_alias { T.all(Symbol, Orb::Models::BillingCycleRelativeDate) }
208+
end
209+
```
210+
211+
#### Argument passing trick
212+
213+
It is possible to pass a compatible model / parameter class to a method that expects keyword arguments by using the `**` splat operator.
214+
215+
```ruby
216+
params = Orb::Models::CustomerCreateParams.new(email: "example-customer@withorb.com", name: "My Customer")
217+
orb.customers.create(**params)
218+
```
219+
212220
## Versioning
213221

214222
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.
@@ -218,3 +226,7 @@ This package considers improvements to the (non-runtime) `*.rbi` and `*.rbs` typ
218226
## Requirements
219227

220228
Ruby 3.1.0 or higher.
229+
230+
## Contributing
231+
232+
See [the contributing documentation](https://github.com/orbcorp/orb-ruby/tree/main/CONTRIBUTING.md).

Rakefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ end
2121

2222
desc("Preview docs; use `PORT=<PORT>` to change the port")
2323
multitask(:"docs:preview") do
24-
sh(*%w[yard server --bind [::] --reload --quiet --port], ENV.fetch("PORT", "8808"))
24+
sh(*%w[yard server --reload --quiet --bind [::] --port], ENV.fetch("PORT", "8808"))
2525
end
2626

2727
desc("Run test suites; use `TEST=path/to/test.rb` to run a specific test file")
@@ -111,7 +111,7 @@ end
111111
desc("Typecheck everything")
112112
multitask(typecheck: [:"typecheck:steep", :"typecheck:sorbet"])
113113

114-
desc("Lint everything")
114+
desc("Lint and typecheck")
115115
multitask(lint: [:"lint:rubocop", :typecheck])
116116

117117
desc("Build yard docs")

lib/orb.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,6 @@
1919
# We already ship the preferred sorbet manifests in the package itself.
2020
# `tapioca` currently does not offer us a way to opt out of unnecessary compilation.
2121
if Object.const_defined?(:Tapioca) && caller.chain([$PROGRAM_NAME]).chain(ARGV).grep(/tapioca/)
22-
Warning.warn(
23-
<<~WARN
24-
\n
25-
⚠️ skipped loading of "orb" gem under `tapioca`.
26-
27-
This message is normal and expected if you are running a `tapioca` command, and does not impact `.rbi` generation.
28-
\n
29-
WARN
30-
)
3122
return
3223
end
3324

0 commit comments

Comments
 (0)