seamapi 0.0.2 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 897bff52e2534e4e660e4e14b9848d88d6c76bd9c555e85eb5349daa37ec13ad
4
- data.tar.gz: 64c3d78b0f55d9f3591ad29af3fee82c1f11eaa7f5d9332a01141880865cc00b
3
+ metadata.gz: 2701dd6d8a0491f971b8f0cf731573aae6d646130e9d95d2e1032cf71247e259
4
+ data.tar.gz: '093249dc1556f023740781aba9689ac65bf278b6eb5228441bc2e6a622cbb8c5'
5
5
  SHA512:
6
- metadata.gz: dba07dabd2fcb9aca06be18fd69511667b69aa3d9dd43b64acf0268e33a0a2146b42b1737082a9e7e60e95c0d7a2c81cad379551a18ec3b75eeabeaa7dc9ed4a
7
- data.tar.gz: 5df04ce74120a3faa29c4a42c48f1e96a2a07b4c6e5590b6b5dd26189b4ed012ca5c3f62be832d6456f76f1e656b4af35f10fc292bfd9b9204d597d96ddd820b
6
+ metadata.gz: 6d7de1b232698cad62e72f83de8d5b05224deeadfff5a0e9e0045a2e99e3c3ee19169b042196da729a05acf48ab811cf88db77d68ba485636513410499d56421
7
+ data.tar.gz: 9ee3ad5a781a7d532eb07c86a25f9e1316c8a11aa5636e565c49dad00b94c809d602c4675376fc22c96f179cd7b96a41076a9377d1f554d6164d2a137dffa262
data/.rubocop.yml CHANGED
@@ -24,3 +24,9 @@ Gemspec/RequireMFA:
24
24
 
25
25
  Metrics/AbcSize:
26
26
  Enabled: false
27
+
28
+ Style/BlockDelimiters:
29
+ Enabled: false
30
+
31
+ Metrics/MethodLength:
32
+ Enabled: false
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- seamapi (0.0.2)
4
+ seamapi (0.0.5)
5
5
  http (~> 5.0.0)
6
6
 
7
7
  GEM
data/lib/seam/client.rb CHANGED
@@ -47,7 +47,7 @@ module Seam
47
47
 
48
48
  data = response[inner_object]
49
49
 
50
- klass.load_from_response(data, @client)
50
+ klass.load_from_response(data, self)
51
51
  end
52
52
 
53
53
  def request_seam(method, path, config = {})
@@ -13,7 +13,9 @@ module Seam
13
13
  )
14
14
  end
15
15
 
16
- def list(device_id)
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
+
17
19
  request_seam_object(
18
20
  :get,
19
21
  "/access_codes/list",
@@ -47,6 +49,24 @@ module Seam
47
49
  action_attempt.wait_until_finished
48
50
  action_attempt
49
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
50
70
  end
51
71
  end
52
72
  end
@@ -12,6 +12,10 @@ module Seam
12
12
  def request_seam_object(*attrs)
13
13
  client.request_seam_object(*attrs)
14
14
  end
15
+
16
+ def request_seam(*attrs)
17
+ client.request_seam(*attrs)
18
+ end
15
19
  end
16
20
  end
17
21
  end
@@ -3,13 +3,29 @@
3
3
  module Seam
4
4
  module Clients
5
5
  class ConnectedAccounts < BaseClient
6
- def get(connected_account_id = nil)
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
+
7
13
  request_seam_object(
8
14
  :get,
9
15
  "/connected_accounts/get",
10
16
  Seam::ConnectedAccount,
11
17
  "connected_account",
12
- params: { connected_account_id: connected_account_id }
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
13
29
  )
14
30
  end
15
31
  end
@@ -40,7 +40,7 @@ module Seam
40
40
  :get,
41
41
  "/locks/list",
42
42
  Seam::Device,
43
- "devices",
43
+ "locks",
44
44
  params: params
45
45
  )
46
46
  end
@@ -50,7 +50,7 @@ module Seam
50
50
  :get,
51
51
  "/locks/get",
52
52
  Seam::Device,
53
- "device",
53
+ "lock",
54
54
  params: {
55
55
  device_id: device_id(device_or_id)
56
56
  }
@@ -23,12 +23,11 @@ module Seam
23
23
  )
24
24
  end
25
25
 
26
- def reset_sandbox
27
- Seam::Request.new(
28
- @client.api_key,
29
- @client.base_uri
30
- ).perform(
31
- :post, "/workspaces/reset_sandbox", {}
26
+ def reset_sandbox(workspace_id)
27
+ request_seam(
28
+ :post,
29
+ "/workspaces/reset_sandbox",
30
+ params: { workspace_id: workspace_id }
32
31
  )
33
32
  end
34
33
  end
@@ -2,6 +2,8 @@
2
2
 
3
3
  module Seam
4
4
  class AccessCode < BaseResource
5
- attr_reader :access_code_id, :name, :starts_at, :ends_at, :type, :created_at, :code
5
+ attr_reader :access_code_id, :name, :type, :code
6
+
7
+ date_accessor :starts_at, :ends_at
6
8
  end
7
9
  end
@@ -4,17 +4,29 @@ module Seam
4
4
  class ActionAttempt < BaseResource
5
5
  attr_accessor :action_attempt_id, :action_type, :status, :result
6
6
 
7
+ SLEEP_TIME = 0.2
8
+ MAX_ATTEMPTS = 10
9
+
7
10
  def wait_until_finished
8
11
  while @status == "pending"
9
- res = Seam::Request.new(@client.api_key, @client.base_uri).perform(
10
- :get,
11
- "/action_attempts/get",
12
- params: { action_attempt_id: @action_attempt_id }
13
- )
14
- update_from_response(res["action_attempt"])
15
- sleep(0.2)
12
+ update!
13
+
14
+ sleep(SLEEP_TIME)
16
15
  end
16
+
17
17
  self
18
18
  end
19
+
20
+ def update!
21
+ response = @client.request_seam(
22
+ :get,
23
+ "/action_attempts/get",
24
+ params: {
25
+ action_attempt_id: action_attempt_id
26
+ }
27
+ )
28
+
29
+ update_from_response(response["action_attempt"])
30
+ end
19
31
  end
20
32
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Seam
4
4
  class BaseResource
5
- attr_accessor :data
5
+ attr_accessor :data, :client
6
6
 
7
7
  def initialize(data, client = nil)
8
8
  @data = data
@@ -36,5 +36,23 @@ module Seam
36
36
  .map { |k| " #{k}=#{send(k).inspect}" }
37
37
  .join("\n") + ">"
38
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
39
57
  end
40
58
  end
@@ -3,7 +3,9 @@
3
3
  module Seam
4
4
  class ConnectWebview < BaseResource
5
5
  attr_accessor :connect_webview_id, :custom_redirect_url, :url, :workspace_id, :device_selection_mode,
6
- :accepted_providers, :accepted_devices, :any_provider_allowed, :any_device_allowed, :created_at,
6
+ :accepted_providers, :accepted_devices, :any_provider_allowed, :any_device_allowed,
7
7
  :login_successful, :status
8
+
9
+ date_accessor :created_at
8
10
  end
9
11
  end
@@ -2,6 +2,8 @@
2
2
 
3
3
  module Seam
4
4
  class ConnectedAccount < BaseResource
5
- attr_accessor :connected_account_id, :created_at, :user_identifier, :account_type
5
+ attr_accessor :connected_account_id, :user_identifier, :account_type
6
+
7
+ date_accessor :created_at
6
8
  end
7
9
  end
@@ -3,5 +3,7 @@
3
3
  module Seam
4
4
  class Device < BaseResource
5
5
  attr_accessor :device_id, :device_type, :properties
6
+
7
+ date_accessor :created_at
6
8
  end
7
9
  end
data/lib/seam/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Seam
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.5"
5
5
  end
File without changes
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: 0.0.2
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abimael Martell
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-07 00:00:00.000000000 Z
11
+ date: 2022-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -52,7 +52,6 @@ files:
52
52
  - Gemfile.lock
53
53
  - README.md
54
54
  - Rakefile
55
- - lib/seam.rb
56
55
  - lib/seam/client.rb
57
56
  - lib/seam/clients/access_codes.rb
58
57
  - lib/seam/clients/action_attempts.rb
@@ -72,6 +71,7 @@ files:
72
71
  - lib/seam/resources/device.rb
73
72
  - lib/seam/resources/workspace.rb
74
73
  - lib/seam/version.rb
74
+ - lib/seamapi.rb
75
75
  - seamapi.gemspec
76
76
  - sig/seamapi.rbs
77
77
  homepage: https://github.com/seamapi/ruby