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
+222-4Lines changed: 222 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,17 +7,235 @@ 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/) node package.
16
+
This ensures all API methods, request shapes, and response shapes are
17
+
accurate and fully typed.
11
18
12
19
## Installation
13
20
14
-
Add this as a dependency to your project using [Bundler] with
21
+
Add this as a dependency to your project using [Bundler](https://bundler.io/) with:
15
22
16
-
```
23
+
```bash
17
24
$ bundle add seam
18
25
```
19
26
20
-
[bundler]: https://bundler.io/
27
+
## Usage
28
+
29
+
### Examples
30
+
31
+
**Note:**_These examples assume `SEAM_API_KEY` is set in your environment._
32
+
33
+
#### List devices
34
+
35
+
```ruby
36
+
require'seam'
37
+
38
+
seam =Seam.new
39
+
devices = seam.devices.list
40
+
```
41
+
42
+
#### Unlock a door
43
+
44
+
```ruby
45
+
require'seam'
46
+
47
+
seam =Seam.new
48
+
lock = seam.locks.get(name:"Front Door")
49
+
seam.locks.unlock_door(device_id: lock.device_id)
50
+
```
51
+
52
+
### Authentication Method
53
+
54
+
The SDK supports API key and personal access token authentication mechanisms.
55
+
Authentication may be configured by passing the corresponding options directly to the `Seam` constructor, or with the more ergonomic static factory methods.
56
+
57
+
#### API Key
58
+
59
+
An API key is scoped to a single workspace and should only be used on the server.
60
+
Obtain one from the Seam Console.
61
+
62
+
```ruby
63
+
# Set the `SEAM_API_KEY` environment variable
64
+
seam =Seam.new
65
+
66
+
# Pass as a keyword argument to the constructor
67
+
seam =Seam.new(api_key:"your-api-key")
68
+
69
+
# Use the factory method
70
+
seam =Seam.from_api_key("your-api-key")
71
+
```
72
+
73
+
#### Personal Access Token
74
+
75
+
A Personal Access Token is scoped to a Seam Console user.
76
+
Obtain one from the Seam Console.
77
+
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:
120
+
121
+
```ruby
122
+
seam.action_attempts.get(
123
+
action_attempt_id: action_attempt_id,
124
+
wait_for_action_attempt:false
125
+
)
126
+
```
127
+
128
+
To disable this behavior, set the default option for the client:
129
+
130
+
```ruby
131
+
seam =Seam.new(
132
+
api_key:"your-api-key",
133
+
wait_for_action_attempt:false
134
+
)
135
+
136
+
seam.locks.unlock_door(device_id: device_id)
137
+
```
138
+
139
+
or the behavior may be configured per-request:
140
+
141
+
```ruby
142
+
seam.locks.unlock_door(
143
+
device_id: device_id,
144
+
wait_for_action_attempt:false
145
+
)
146
+
```
147
+
148
+
The `polling_interval` and `timeout` may be configured for the client or per-request.
149
+
For example:
150
+
151
+
```ruby
152
+
require'seam'
153
+
154
+
seam =Seam.new("your-api-key")
155
+
156
+
locks = seam.locks.list
157
+
158
+
if locks.empty?
159
+
raise"No locks in this workspace"
160
+
end
161
+
162
+
lock = locks.first
163
+
164
+
begin
165
+
seam.locks.unlock_door(
166
+
device_id: lock.device_id,
167
+
wait_for_action_attempt: {
168
+
timeout:5.0,
169
+
polling_interval:1.0
170
+
}
171
+
)
172
+
173
+
puts"Door unlocked"
174
+
rescueSeam::ActionAttemptFailedError
175
+
puts"Could not unlock the door"
176
+
rescueSeam::ActionAttemptTimeoutError
177
+
puts"Door took too long to unlock"
178
+
end
179
+
```
180
+
181
+
### Interacting with Multiple Workspaces
182
+
183
+
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.
184
+
185
+
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
195
+
workspaces = seam.workspaces.list
196
+
```
197
+
198
+
### Webhooks
199
+
200
+
The Seam API implements webhooks using [Svix](https://www.svix.com). This SDK exports a thin wrapper `Seam::Webhook` around the svix package. Use it to parse and validate Seam webhook events.
201
+
202
+
Refer to the [Svix docs on Consuming Webhooks](https://docs.svix.com/receiving/introduction) for an in-depth guide on best-practices for handling webhooks in your application.
0 commit comments