seamapi 0.0.1 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 173cc34127a115428d6d17298a4766932b8c27384528bbe2127d6afa581f2cae
4
- data.tar.gz: 91a107fa9a2e9b88dec0afd88cb1f0cb95ec17496903261738e50d103d656636
3
+ metadata.gz: fb9b5fc62548919c49b3e041cd434e724c29174a1daa15ad736185f7eb689a2c
4
+ data.tar.gz: 3a9177165da484078b1a14f54afc3846da4757809527c188b3453c936eb40d41
5
5
  SHA512:
6
- metadata.gz: 63dbdd58445cc484106ebeae1bd1c0a36638bbe01c66fef315bc79abb04ea50cdffd6cfbeb92d3776849abf1ed01894434bc1f688c23fe1e21cc2f65133fc587
7
- data.tar.gz: 5b5a89d6c4ab8944ac322db1f555c59bc4f199c9e440a806d74b79c6169dc6864612f886e67859766fc525bec0b6f6a59759b4c6597db6b00eecb7803de6d2f3
6
+ metadata.gz: d4f042c9d1f59f9eed7df5d769f693776f0627f85172515cc59bace00e6b0cbb4253767b6da114221fd66e92c847ab38de511ae4b2d3c5f3364a2d0cd325b729
7
+ data.tar.gz: 18791847ad1ac03910091bdf4a4525b9ac9cd86515bf0b169ad0d9c41e7d01beca978efe9bf642d5bd3545c9c90cf0e86fd2cfc5d2a042e687a48cd29babe855
data/.rubocop.yml CHANGED
@@ -21,3 +21,12 @@ Metrics/BlockLength:
21
21
 
22
22
  Gemspec/RequireMFA:
23
23
  Enabled: false
24
+
25
+ Metrics/AbcSize:
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.1.0)
4
+ seamapi (0.0.4)
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
@@ -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
@@ -27,5 +27,32 @@ module Seam
27
27
  new(data, client)
28
28
  end
29
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
30
57
  end
31
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.1"
4
+ VERSION = "0.0.4"
5
5
  end
File without changes
data/seamapi.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/seam/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "seamapi"
7
+ spec.version = Seam::VERSION
8
+ spec.authors = ["Abimael Martell"]
9
+ spec.email = ["abi@getseam.com"]
10
+
11
+ spec.summary = "Seam API Ruby Library"
12
+ spec.description = "seamapi is a Ruby gem that provides a simple interface to Seam Connect's API."
13
+ spec.homepage = "https://github.com/seamapi/ruby"
14
+ spec.required_ruby_version = ">= 2.6.0"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/seamapi/ruby"
18
+
19
+ spec.files = Dir.chdir(__dir__) do
20
+ `git ls-files -z`.split("\x0").reject do |f|
21
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
22
+ end
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_dependency "http", "~> 5.0.0"
29
+ spec.add_development_dependency "webmock", "~> 3.0.0"
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: 0.0.1
4
+ version: 0.0.4
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-07-26 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,8 @@ 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
+ - seamapi.gemspec
75
76
  - sig/seamapi.rbs
76
77
  homepage: https://github.com/seamapi/ruby
77
78
  licenses: []