seamapi 1.2.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/seam/client.rb +4 -0
- data/lib/seam/clients/access_codes.rb +72 -0
- data/lib/seam/clients/action_attempts.rb +17 -0
- data/lib/seam/clients/connect_webviews.rb +37 -0
- data/lib/seam/clients/connected_accounts.rb +33 -0
- data/lib/seam/clients/devices.rb +27 -0
- data/lib/seam/clients/events.rb +28 -0
- data/lib/seam/clients/locks.rb +67 -0
- data/lib/seam/clients/workspaces.rb +35 -0
- data/lib/seam/resources/access_code.rb +12 -0
- data/lib/seam/resources/base_resource.rb +58 -0
- data/lib/seam/resources/device.rb +12 -0
- data/lib/seam/resources/event.rb +9 -0
- data/lib/seam/resources/workspace.rb +7 -0
- data/lib/seam/version.rb +1 -1
- data/lib/seamapi.rb +2 -0
- metadata +15 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1201d5f8298e96925130f8e386e4df34a3d0bef7a17aa0152844755e23e0ba7
|
4
|
+
data.tar.gz: e9696958ff2d4456fe2189b84cf595dc1dab166894d46e40f39f3b5cf0957d41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96a1fa6d22023d1552a05a99e375879ca046297b6d66a95d2652d5c494040f15f35e529bf81391cdb848b16a833043806ba71a559b65997e1383cfe268118a67
|
7
|
+
data.tar.gz: cb3a6158e31b084aaf11117b3cc4fc9f45028bf48cd975e4a1093c1b08f6563958e31fc6477af8fd3020927e76fd713671f024281e960586d7e58d1791305b97
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -16,7 +16,7 @@ This library includes:
|
|
16
16
|
|
17
17
|
- A predefined set of classes for API resources that
|
18
18
|
initialize themselves dynamically from API responses.
|
19
|
-
- Methods for all [Seam API endpoints].
|
19
|
+
- Methods for all [Seam API endpoints](https://docs.seam.co/latest/api-clients/overview).
|
20
20
|
- Simplified asynchronous flows, e.g., listening for events or actions to finish.
|
21
21
|
|
22
22
|
[Seam API endpoints]: https://docs.seam.co/latest/api-endpoints/overview
|
data/lib/seam/client.rb
CHANGED
@@ -44,6 +44,10 @@ module Seam
|
|
44
44
|
@workspaces ||= Seam::Clients::Workspaces.new(self)
|
45
45
|
end
|
46
46
|
|
47
|
+
def events
|
48
|
+
@events ||= Seam::Clients::Events.new(self)
|
49
|
+
end
|
50
|
+
|
47
51
|
def request_seam_object(method, path, klass, inner_object, config = {})
|
48
52
|
response = request_seam(method, path, config)
|
49
53
|
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Seam
|
4
|
+
module Clients
|
5
|
+
class AccessCodes < BaseClient
|
6
|
+
def get(access_code_id)
|
7
|
+
request_seam_object(
|
8
|
+
:get,
|
9
|
+
"/access_codes/get",
|
10
|
+
Seam::AccessCode,
|
11
|
+
"access_code",
|
12
|
+
params: {access_code_id: access_code_id}
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
def list(device_or_id)
|
17
|
+
device_id = device_or_id.is_a?(Seam::Device) ? device_or_id.device_id : device_or_id
|
18
|
+
|
19
|
+
request_seam_object(
|
20
|
+
:get,
|
21
|
+
"/access_codes/list",
|
22
|
+
Seam::AccessCode,
|
23
|
+
"access_codes",
|
24
|
+
params: {device_id: device_id}
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
def create(device_id: nil, name: nil, code: nil, starts_at: nil, ends_at: nil)
|
29
|
+
action_attempt = request_seam_object(
|
30
|
+
:post,
|
31
|
+
"/access_codes/create",
|
32
|
+
Seam::ActionAttempt,
|
33
|
+
"action_attempt",
|
34
|
+
body: {device_id: device_id, code: code, starts_at: starts_at, ends_at: ends_at, name: name}.compact
|
35
|
+
)
|
36
|
+
action_attempt.wait_until_finished
|
37
|
+
# TODO: check if failed
|
38
|
+
Seam::AccessCode.new(action_attempt.result["access_code"], @client)
|
39
|
+
end
|
40
|
+
|
41
|
+
def delete(access_code_id)
|
42
|
+
action_attempt = request_seam_object(
|
43
|
+
:post,
|
44
|
+
"/access_codes/delete",
|
45
|
+
Seam::ActionAttempt,
|
46
|
+
"action_attempt",
|
47
|
+
body: {access_code_id: access_code_id}
|
48
|
+
)
|
49
|
+
action_attempt.wait_until_finished
|
50
|
+
action_attempt
|
51
|
+
end
|
52
|
+
|
53
|
+
def update(access_code_id: nil, name: nil, code: nil, starts_at: nil, ends_at: nil)
|
54
|
+
action_attempt = request_seam_object(
|
55
|
+
:post,
|
56
|
+
"/access_codes/update",
|
57
|
+
Seam::ActionAttempt,
|
58
|
+
"action_attempt",
|
59
|
+
body: {
|
60
|
+
access_code_id: access_code_id,
|
61
|
+
name: name,
|
62
|
+
code: code,
|
63
|
+
starts_at: starts_at,
|
64
|
+
ends_at: ends_at
|
65
|
+
}.compact
|
66
|
+
)
|
67
|
+
action_attempt.wait_until_finished
|
68
|
+
action_attempt
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Seam
|
4
|
+
module Clients
|
5
|
+
class ActionAttempts < BaseClient
|
6
|
+
def get(action_attempt_id)
|
7
|
+
request_seam_object(
|
8
|
+
:get,
|
9
|
+
"/action_attempts/get",
|
10
|
+
Seam::ActionAttempt,
|
11
|
+
"action_attempt",
|
12
|
+
params: {action_attempt_id: action_attempt_id}
|
13
|
+
)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Seam
|
4
|
+
module Clients
|
5
|
+
class ConnectWebviews < BaseClient
|
6
|
+
def get(connect_webview_id = nil)
|
7
|
+
request_seam_object(
|
8
|
+
:get,
|
9
|
+
"/connect_webviews/get",
|
10
|
+
Seam::ConnectWebview,
|
11
|
+
"connect_webview",
|
12
|
+
params: {connect_webview_id: connect_webview_id}
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
def list
|
17
|
+
request_seam_object(
|
18
|
+
:get,
|
19
|
+
"/connect_webviews/list",
|
20
|
+
Seam::ConnectWebview,
|
21
|
+
"connect_webviews",
|
22
|
+
params: {}
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
def create(accepted_providers: nil)
|
27
|
+
request_seam_object(
|
28
|
+
:post,
|
29
|
+
"/connect_webviews/create",
|
30
|
+
Seam::ConnectWebview,
|
31
|
+
"connect_webview",
|
32
|
+
body: {accepted_providers: accepted_providers}
|
33
|
+
)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Seam
|
4
|
+
module Clients
|
5
|
+
class ConnectedAccounts < BaseClient
|
6
|
+
def get(connected_account_id_or_params)
|
7
|
+
params = if connected_account_id_or_params.is_a?(String)
|
8
|
+
{connected_account_id: connected_account_id_or_params}
|
9
|
+
else
|
10
|
+
connected_account_id_or_params
|
11
|
+
end
|
12
|
+
|
13
|
+
request_seam_object(
|
14
|
+
:get,
|
15
|
+
"/connected_accounts/get",
|
16
|
+
Seam::ConnectedAccount,
|
17
|
+
"connected_account",
|
18
|
+
params: params
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
def list(params = {})
|
23
|
+
request_seam_object(
|
24
|
+
:get,
|
25
|
+
"/connected_accounts/list",
|
26
|
+
Seam::ConnectedAccount,
|
27
|
+
"connected_accounts",
|
28
|
+
params: params
|
29
|
+
)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Seam
|
4
|
+
module Clients
|
5
|
+
class Devices < BaseClient
|
6
|
+
def list(params = {})
|
7
|
+
request_seam_object(
|
8
|
+
:get,
|
9
|
+
"/devices/list",
|
10
|
+
Seam::Device,
|
11
|
+
"devices",
|
12
|
+
params: params
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
def get(device_id)
|
17
|
+
request_seam_object(
|
18
|
+
:get,
|
19
|
+
"/devices/get",
|
20
|
+
Seam::Device,
|
21
|
+
"device",
|
22
|
+
params: {device_id: device_id}
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Seam
|
4
|
+
module Clients
|
5
|
+
class Events < BaseClient
|
6
|
+
def get(event_id: nil, event_type: nil, device_id: nil)
|
7
|
+
request_seam_object(
|
8
|
+
:get,
|
9
|
+
"/events/get",
|
10
|
+
Seam::Event,
|
11
|
+
"event",
|
12
|
+
params: {event_id: event_id, event_type: event_type, device_id: device_id}.compact
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
def list(since: str, event_type: nil, event_types: nil, device_id: nil, device_ids: nil)
|
17
|
+
request_seam_object(
|
18
|
+
:get,
|
19
|
+
"/events/list",
|
20
|
+
Seam::Event,
|
21
|
+
"events",
|
22
|
+
params: {event_type: event_type, event_types: event_types, device_id: device_id,
|
23
|
+
device_ids: device_ids, since: since}.compact
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Seam
|
4
|
+
module Clients
|
5
|
+
class Locks < BaseClient
|
6
|
+
# Unlocks a door
|
7
|
+
#
|
8
|
+
# @param [String] device_id
|
9
|
+
# @return [Seam::ActionAttempt]
|
10
|
+
def unlock_door(device_or_id)
|
11
|
+
request_seam_object(
|
12
|
+
:post,
|
13
|
+
"/locks/unlock_door",
|
14
|
+
Seam::ActionAttempt,
|
15
|
+
"action_attempt",
|
16
|
+
body: {
|
17
|
+
device_id: device_id(device_or_id)
|
18
|
+
}
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Locks a door
|
23
|
+
#
|
24
|
+
# @param [String] device_id
|
25
|
+
# @return [Seam::ActionAttempt]
|
26
|
+
def lock_door(device_or_id)
|
27
|
+
request_seam_object(
|
28
|
+
:post,
|
29
|
+
"/locks/lock_door",
|
30
|
+
Seam::ActionAttempt,
|
31
|
+
"action_attempt",
|
32
|
+
body: {
|
33
|
+
device_id: device_id(device_or_id)
|
34
|
+
}
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
def list(params = {})
|
39
|
+
request_seam_object(
|
40
|
+
:get,
|
41
|
+
"/locks/list",
|
42
|
+
Seam::Device,
|
43
|
+
"locks",
|
44
|
+
params: params
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
def get(device_or_id)
|
49
|
+
request_seam_object(
|
50
|
+
:get,
|
51
|
+
"/locks/get",
|
52
|
+
Seam::Device,
|
53
|
+
"lock",
|
54
|
+
params: {
|
55
|
+
device_id: device_id(device_or_id)
|
56
|
+
}
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
protected
|
61
|
+
|
62
|
+
def device_id(device_or_id)
|
63
|
+
device_or_id.is_a?(Seam::Device) ? device_or_id.device_id : device_or_id
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Seam
|
4
|
+
module Clients
|
5
|
+
class Workspaces < BaseClient
|
6
|
+
def get(workspace_id = nil)
|
7
|
+
request_seam_object(
|
8
|
+
:get,
|
9
|
+
"/workspaces/get",
|
10
|
+
Seam::Workspace,
|
11
|
+
"workspace",
|
12
|
+
params: {workspace_id: workspace_id}
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
def list
|
17
|
+
request_seam_object(
|
18
|
+
:get,
|
19
|
+
"/workspaces/list",
|
20
|
+
Seam::Workspace,
|
21
|
+
"workspaces",
|
22
|
+
params: {}
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
def reset_sandbox(workspace_id)
|
27
|
+
request_seam(
|
28
|
+
:post,
|
29
|
+
"/workspaces/reset_sandbox",
|
30
|
+
params: {workspace_id: workspace_id}
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Seam
|
4
|
+
class AccessCode < BaseResource
|
5
|
+
attr_reader :access_code_id, :name, :type, :code
|
6
|
+
|
7
|
+
date_accessor :starts_at, :ends_at
|
8
|
+
|
9
|
+
include Seam::ResourceErrorsSupport
|
10
|
+
include Seam::ResourceWarningsSupport
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Seam
|
4
|
+
class BaseResource
|
5
|
+
attr_accessor :data, :client
|
6
|
+
|
7
|
+
def initialize(data, client = nil)
|
8
|
+
@data = data
|
9
|
+
@client = client
|
10
|
+
|
11
|
+
@data.each do |key, value|
|
12
|
+
instance_variable_set("@#{key}", value)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def update_from_response(data)
|
17
|
+
@data = data
|
18
|
+
@data.each do |key, value|
|
19
|
+
instance_variable_set("@#{key}", value)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.load_from_response(data, client = nil)
|
24
|
+
if data.is_a?(Array)
|
25
|
+
data.map { |d| new(d, client) }
|
26
|
+
else
|
27
|
+
new(data, client)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def inspect
|
32
|
+
"<#{self.class.name}:#{"0x00%x" % (object_id << 1)}\n" + # rubocop:disable Style/StringConcatenation, Style/FormatString
|
33
|
+
instance_variables
|
34
|
+
.map { |k| k.to_s.sub("@", "") }
|
35
|
+
.filter { |k| k != "data" and k != "client" and respond_to? k }
|
36
|
+
.map { |k| " #{k}=#{send(k).inspect}" }
|
37
|
+
.join("\n") + ">"
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.date_accessor(*attrs)
|
41
|
+
attrs.each do |attr|
|
42
|
+
define_method(attr) do
|
43
|
+
value = instance_variable_get("@#{attr}")
|
44
|
+
|
45
|
+
raise "No value for #{attr} set" if value.nil?
|
46
|
+
|
47
|
+
parse_datetime(value)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
protected
|
53
|
+
|
54
|
+
def parse_datetime(value)
|
55
|
+
Time.parse(value)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/seam/version.rb
CHANGED
data/lib/seamapi.rb
CHANGED
@@ -12,6 +12,7 @@ require_relative "seam/clients/connect_webviews"
|
|
12
12
|
require_relative "seam/clients/connected_accounts"
|
13
13
|
require_relative "seam/clients/access_codes"
|
14
14
|
require_relative "seam/clients/action_attempts"
|
15
|
+
require_relative "seam/clients/events"
|
15
16
|
require_relative "seam/resources/base_resource"
|
16
17
|
require_relative "seam/resources/resource_warning"
|
17
18
|
require_relative "seam/resources/resource_error"
|
@@ -23,6 +24,7 @@ require_relative "seam/resources/action_attempt"
|
|
23
24
|
require_relative "seam/resources/connect_webview"
|
24
25
|
require_relative "seam/resources/connected_account"
|
25
26
|
require_relative "seam/resources/workspace"
|
27
|
+
require_relative "seam/resources/event"
|
26
28
|
|
27
29
|
module Seam
|
28
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seamapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Seam Labs, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-12-
|
11
|
+
date: 2022-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -162,16 +162,29 @@ files:
|
|
162
162
|
- README.md
|
163
163
|
- Rakefile
|
164
164
|
- lib/seam/client.rb
|
165
|
+
- lib/seam/clients/access_codes.rb
|
166
|
+
- lib/seam/clients/action_attempts.rb
|
165
167
|
- lib/seam/clients/base_client.rb
|
168
|
+
- lib/seam/clients/connect_webviews.rb
|
169
|
+
- lib/seam/clients/connected_accounts.rb
|
170
|
+
- lib/seam/clients/devices.rb
|
171
|
+
- lib/seam/clients/events.rb
|
172
|
+
- lib/seam/clients/locks.rb
|
173
|
+
- lib/seam/clients/workspaces.rb
|
166
174
|
- lib/seam/logger.rb
|
167
175
|
- lib/seam/request.rb
|
176
|
+
- lib/seam/resources/access_code.rb
|
168
177
|
- lib/seam/resources/action_attempt.rb
|
178
|
+
- lib/seam/resources/base_resource.rb
|
169
179
|
- lib/seam/resources/connect_webview.rb
|
170
180
|
- lib/seam/resources/connected_account.rb
|
181
|
+
- lib/seam/resources/device.rb
|
182
|
+
- lib/seam/resources/event.rb
|
171
183
|
- lib/seam/resources/resource_error.rb
|
172
184
|
- lib/seam/resources/resource_errors_support.rb
|
173
185
|
- lib/seam/resources/resource_warning.rb
|
174
186
|
- lib/seam/resources/resource_warnings_support.rb
|
187
|
+
- lib/seam/resources/workspace.rb
|
175
188
|
- lib/seam/version.rb
|
176
189
|
- lib/seamapi.rb
|
177
190
|
homepage: https://github.com/seamapi/ruby
|