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: README.md
+323-3Lines changed: 323 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,17 +7,337 @@ SDK for the Seam API written in Ruby.
7
7
8
8
## Description
9
9
10
-
TODO
10
+
[Seam](https://seam.co) makes it easy to integrate IoT devices with your applications.
11
+
This is an official SDK for the Seam API.
12
+
Please refer to the official [Seam Docs](https://docs.seam.co/latest/) to get started.
13
+
14
+
Parts of this SDK are generated from always up-to-date type information
15
+
provided by [@seamapi/types](https://github.com/seamapi/types/).
16
+
This ensures all API methods, request shapes, and response shapes are
17
+
accurate and fully typed.
18
+
19
+
<!-- toc -->
20
+
21
+
-[Installation](#installation)
22
+
-[Usage](#usage)
23
+
-[Examples](#examples)
24
+
-[List devices](#list-devices)
25
+
-[Unlock a door](#unlock-a-door)
26
+
-[Authentication Method](#authentication-method)
27
+
-[API Key](#api-key)
28
+
-[Personal Access Token](#personal-access-token)
29
+
-[Action Attempts](#action-attempts)
30
+
-[Interacting with Multiple Workspaces](#interacting-with-multiple-workspaces)
31
+
-[Webhooks](#webhooks)
32
+
-[Advanced Usage](#advanced-usage)
33
+
-[Additional Options](#additional-options)
34
+
-[Setting the endpoint](#setting-the-endpoint)
35
+
-[Configuring the Faraday Client](#configuring-the-faraday-client)
36
+
-[Using the Faraday Client](#using-the-faraday-client)
37
+
-[Overriding the Client](#overriding-the-client)
38
+
-[Development and Testing](#development-and-testing)
39
+
-[Quickstart](#quickstart)
40
+
-[Source code](#source-code)
41
+
-[Requirements](#requirements)
42
+
-[Publishing](#publishing)
43
+
-[Automatic](#automatic)
44
+
-[Manual](#manual)
45
+
-[GitHub Actions](#github-actions)
46
+
-[Secrets for Optional GitHub Actions](#secrets-for-optional-github-actions)
47
+
-[Contributing](#contributing)
48
+
-[License](#license)
49
+
-[Warranty](#warranty)
50
+
51
+
<!-- tocstop -->
11
52
12
53
## Installation
13
54
14
-
Add this as a dependency to your project using [Bundler] with
55
+
Add this as a dependency to your project using [Bundler] with:
15
56
16
57
```
17
58
$ bundle add seam
18
59
```
19
60
20
-
[bundler]: https://bundler.io/
61
+
[Bundler]: https://bundler.io/
62
+
63
+
## Usage
64
+
65
+
### Examples
66
+
67
+
> [!NOTE]
68
+
> These examples assume `SEAM_API_KEY` is set in your environment.
69
+
70
+
#### List devices
71
+
72
+
```ruby
73
+
require"seam"
74
+
75
+
seam =Seam.new
76
+
devices = seam.devices.list
77
+
```
78
+
79
+
#### Unlock a door
80
+
81
+
```ruby
82
+
require"seam"
83
+
84
+
seam =Seam.new
85
+
lock = seam.locks.get(name:"Front Door")
86
+
seam.locks.unlock_door(device_id: lock.device_id)
87
+
```
88
+
89
+
### Authentication Method
90
+
91
+
The SDK supports API key and personal access token authentication mechanisms.
92
+
Authentication may be configured by passing the corresponding options directly to the `Seam` constructor, or with the more ergonomic static factory methods.
93
+
94
+
#### API Key
95
+
96
+
An API key is scoped to a single workspace and should only be used on the server.
97
+
Obtain one from the Seam Console.
98
+
99
+
```ruby
100
+
# Set the `SEAM_API_KEY` environment variable
101
+
seam =Seam.new
102
+
103
+
# Pass as a keyword argument to the constructor
104
+
seam =Seam.new(api_key:"your-api-key")
105
+
106
+
# Use the factory method
107
+
seam =Seam.from_api_key("your-api-key")
108
+
```
109
+
110
+
#### Personal Access Token
111
+
112
+
A Personal Access Token is scoped to a Seam Console user.
113
+
Obtain one from the Seam Console.
114
+
A workspace ID must be provided when using this method and all requests will be scoped to that workspace.
Or, to get the current state of an action attempt by ID without waiting:
157
+
158
+
```ruby
159
+
seam.action_attempts.get(
160
+
action_attempt_id: action_attempt_id,
161
+
wait_for_action_attempt:false
162
+
)
163
+
```
164
+
165
+
To disable this behavior, set the default option for the client:
166
+
167
+
```ruby
168
+
seam =Seam.new(
169
+
api_key:"your-api-key",
170
+
wait_for_action_attempt:false
171
+
)
172
+
173
+
seam.locks.unlock_door(device_id: device_id)
174
+
```
175
+
176
+
or the behavior may be configured per-request:
177
+
178
+
```ruby
179
+
seam.locks.unlock_door(
180
+
device_id: device_id,
181
+
wait_for_action_attempt:false
182
+
)
183
+
```
184
+
185
+
The `polling_interval` and `timeout` may be configured for the client or per-request.
186
+
For example:
187
+
188
+
```ruby
189
+
require"seam"
190
+
191
+
seam =Seam.new("your-api-key")
192
+
193
+
locks = seam.locks.list
194
+
195
+
if locks.empty?
196
+
raise"No locks in this workspace"
197
+
end
198
+
199
+
lock = locks.first
200
+
201
+
begin
202
+
seam.locks.unlock_door(
203
+
device_id: lock.device_id,
204
+
wait_for_action_attempt: {
205
+
timeout:5.0,
206
+
polling_interval:1.0
207
+
}
208
+
)
209
+
210
+
puts"Door unlocked"
211
+
rescueSeam::ActionAttemptFailedError
212
+
puts"Could not unlock the door"
213
+
rescueSeam::ActionAttemptTimeoutError
214
+
puts"Door took too long to unlock"
215
+
end
216
+
```
217
+
218
+
### Interacting with Multiple Workspaces
219
+
220
+
Some Seam API endpoints interact with multiple workspaces. The `Seam::Http::SeamMultiWorkspace` client is not bound to a specific workspace and may use those endpoints with a personal access token authentication method.
221
+
222
+
A Personal Access Token is scoped to a Seam Console user. Obtain one from the Seam Console.
# List workspaces authorized for this Personal Access Token
232
+
workspaces = seam.workspaces.list
233
+
```
234
+
235
+
### Webhooks
236
+
237
+
The Seam API implements webhooks using [Svix](https://www.svix.com).This SDK exports a thin wrapper `Seam::Webhook` around the svix package.
238
+
Use it to parse and validate Seam webhook events.
239
+
240
+
> [!TIP]
241
+
> This example is for [Sinatra](https://sinatrarb.com/), see the [Svix docs for more examples in specific frameworks](https://docs.svix.com/receiving/verifying-payloads/how).
0 commit comments