seam 2.0.0b5 → 2.0.0.prerelease.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +53 -49
  3. data/README.md +3 -323
  4. data/Rakefile +1 -4
  5. data/lib/seam/client.rb +129 -0
  6. data/lib/seam/clients/access_codes.rb +95 -0
  7. data/lib/seam/clients/access_codes_simulate.rb +17 -0
  8. data/lib/seam/clients/access_codes_unmanaged.rb +57 -0
  9. data/lib/seam/clients/acs.rb +35 -0
  10. data/lib/seam/clients/acs_access_groups.rb +57 -0
  11. data/lib/seam/clients/acs_credential_pools.rb +17 -0
  12. data/lib/seam/clients/acs_credential_provisioning_automations.rb +17 -0
  13. data/lib/seam/clients/acs_credentials.rb +77 -0
  14. data/lib/seam/clients/acs_entrances.rb +47 -0
  15. data/lib/seam/clients/acs_systems.rb +27 -0
  16. data/lib/seam/clients/acs_users.rb +117 -0
  17. data/lib/seam/clients/action_attempts.rb +30 -0
  18. data/lib/seam/clients/base_client.rb +21 -0
  19. data/lib/seam/clients/client_sessions.rb +77 -0
  20. data/lib/seam/clients/connect_webviews.rb +47 -0
  21. data/lib/seam/clients/connected_accounts.rb +47 -0
  22. data/lib/seam/clients/devices.rb +65 -0
  23. data/lib/seam/clients/devices_simulate.rb +17 -0
  24. data/lib/seam/clients/devices_unmanaged.rb +37 -0
  25. data/lib/seam/clients/events.rb +27 -0
  26. data/lib/seam/clients/locks.rb +53 -0
  27. data/lib/seam/clients/networks.rb +27 -0
  28. data/lib/seam/clients/noise_sensors.rb +15 -0
  29. data/lib/seam/clients/noise_sensors_noise_thresholds.rb +57 -0
  30. data/lib/seam/clients/noise_sensors_simulate.rb +17 -0
  31. data/lib/seam/clients/phones.rb +31 -0
  32. data/lib/seam/clients/phones_simulate.rb +17 -0
  33. data/lib/seam/clients/thermostats.rb +106 -0
  34. data/lib/seam/clients/thermostats_climate_setting_schedules.rb +57 -0
  35. data/lib/seam/clients/user_identities.rb +131 -0
  36. data/lib/seam/clients/user_identities_enrollment_automations.rb +47 -0
  37. data/lib/seam/clients/webhooks.rb +57 -0
  38. data/lib/seam/clients/workspaces.rb +50 -0
  39. data/lib/seam/logger.rb +12 -0
  40. data/lib/seam/request.rb +51 -84
  41. data/lib/seam/resources/access_code.rb +12 -0
  42. data/lib/seam/resources/acs_access_group.rb +9 -0
  43. data/lib/seam/resources/acs_credential.rb +12 -0
  44. data/lib/seam/resources/acs_credential_pool.rb +9 -0
  45. data/lib/seam/resources/acs_credential_provisioning_automation.rb +9 -0
  46. data/lib/seam/resources/acs_entrance.rb +9 -0
  47. data/lib/seam/resources/acs_system.rb +9 -0
  48. data/lib/seam/resources/acs_user.rb +9 -0
  49. data/lib/seam/resources/action_attempt.rb +46 -0
  50. data/lib/seam/resources/base_resource.rb +58 -0
  51. data/lib/seam/resources/client_session.rb +9 -0
  52. data/lib/seam/resources/climate_setting_schedule.rb +11 -0
  53. data/lib/seam/resources/connect_webview.rb +9 -0
  54. data/lib/seam/resources/connected_account.rb +12 -0
  55. data/lib/seam/resources/device.rb +12 -0
  56. data/lib/seam/resources/device_provider.rb +7 -0
  57. data/lib/seam/resources/enrollment_automation.rb +9 -0
  58. data/lib/seam/resources/event.rb +9 -0
  59. data/lib/seam/resources/network.rb +9 -0
  60. data/lib/seam/resources/noise_threshold.rb +7 -0
  61. data/lib/seam/resources/phone.rb +12 -0
  62. data/lib/seam/resources/resource_error.rb +9 -0
  63. data/lib/seam/resources/resource_errors_support.rb +9 -0
  64. data/lib/seam/resources/resource_warning.rb +9 -0
  65. data/lib/seam/resources/resource_warnings_support.rb +9 -0
  66. data/lib/seam/resources/service_health.rb +7 -0
  67. data/lib/seam/resources/unmanaged_access_code.rb +12 -0
  68. data/lib/seam/resources/unmanaged_device.rb +12 -0
  69. data/lib/seam/resources/user_identity.rb +9 -0
  70. data/lib/seam/resources/webhook.rb +7 -0
  71. data/lib/seam/resources/workspace.rb +7 -0
  72. data/lib/seam/version.rb +1 -1
  73. data/lib/seam.rb +68 -19
  74. metadata +71 -115
  75. data/lib/seam/auth.rb +0 -118
  76. data/lib/seam/base_resource.rb +0 -65
  77. data/lib/seam/deep_hash_accessor.rb +0 -37
  78. data/lib/seam/default_endpoint.rb +0 -5
  79. data/lib/seam/helpers/action_attempt.rb +0 -47
  80. data/lib/seam/http.rb +0 -52
  81. data/lib/seam/http_multi_workspace.rb +0 -66
  82. data/lib/seam/http_single_workspace.rb +0 -46
  83. data/lib/seam/options.rb +0 -64
  84. data/lib/seam/parse_options.rb +0 -23
  85. data/lib/seam/routes/clients/access_codes.rb +0 -74
  86. data/lib/seam/routes/clients/access_codes_simulate.rb +0 -18
  87. data/lib/seam/routes/clients/access_codes_unmanaged.rb +0 -42
  88. data/lib/seam/routes/clients/acs.rb +0 -44
  89. data/lib/seam/routes/clients/acs_access_groups.rb +0 -48
  90. data/lib/seam/routes/clients/acs_access_groups_unmanaged.rb +0 -24
  91. data/lib/seam/routes/clients/acs_credential_pools.rb +0 -18
  92. data/lib/seam/routes/clients/acs_credential_provisioning_automations.rb +0 -18
  93. data/lib/seam/routes/clients/acs_credentials.rb +0 -60
  94. data/lib/seam/routes/clients/acs_credentials_unmanaged.rb +0 -24
  95. data/lib/seam/routes/clients/acs_encoders.rb +0 -36
  96. data/lib/seam/routes/clients/acs_entrances.rb +0 -36
  97. data/lib/seam/routes/clients/acs_systems.rb +0 -30
  98. data/lib/seam/routes/clients/acs_users.rb +0 -78
  99. data/lib/seam/routes/clients/acs_users_unmanaged.rb +0 -24
  100. data/lib/seam/routes/clients/action_attempts.rb +0 -28
  101. data/lib/seam/routes/clients/client_sessions.rb +0 -54
  102. data/lib/seam/routes/clients/connect_webviews.rb +0 -36
  103. data/lib/seam/routes/clients/connected_accounts.rb +0 -36
  104. data/lib/seam/routes/clients/devices.rb +0 -50
  105. data/lib/seam/routes/clients/devices_simulate.rb +0 -30
  106. data/lib/seam/routes/clients/devices_unmanaged.rb +0 -30
  107. data/lib/seam/routes/clients/events.rb +0 -24
  108. data/lib/seam/routes/clients/index.rb +0 -38
  109. data/lib/seam/routes/clients/locks.rb +0 -42
  110. data/lib/seam/routes/clients/networks.rb +0 -24
  111. data/lib/seam/routes/clients/noise_sensors.rb +0 -26
  112. data/lib/seam/routes/clients/noise_sensors_noise_thresholds.rb +0 -42
  113. data/lib/seam/routes/clients/noise_sensors_simulate.rb +0 -18
  114. data/lib/seam/routes/clients/phones.rb +0 -28
  115. data/lib/seam/routes/clients/phones_simulate.rb +0 -18
  116. data/lib/seam/routes/clients/thermostats.rb +0 -108
  117. data/lib/seam/routes/clients/thermostats_schedules.rb +0 -42
  118. data/lib/seam/routes/clients/user_identities.rb +0 -88
  119. data/lib/seam/routes/clients/user_identities_enrollment_automations.rb +0 -36
  120. data/lib/seam/routes/clients/webhooks.rb +0 -42
  121. data/lib/seam/routes/clients/workspaces.rb +0 -40
  122. data/lib/seam/routes/resources/access_code.rb +0 -14
  123. data/lib/seam/routes/resources/acs_access_group.rb +0 -11
  124. data/lib/seam/routes/resources/acs_credential.rb +0 -14
  125. data/lib/seam/routes/resources/acs_credential_pool.rb +0 -11
  126. data/lib/seam/routes/resources/acs_credential_provisioning_automation.rb +0 -11
  127. data/lib/seam/routes/resources/acs_entrance.rb +0 -13
  128. data/lib/seam/routes/resources/acs_system.rb +0 -14
  129. data/lib/seam/routes/resources/acs_user.rb +0 -14
  130. data/lib/seam/routes/resources/action_attempt.rb +0 -9
  131. data/lib/seam/routes/resources/client_session.rb +0 -11
  132. data/lib/seam/routes/resources/connect_webview.rb +0 -11
  133. data/lib/seam/routes/resources/connected_account.rb +0 -14
  134. data/lib/seam/routes/resources/device.rb +0 -14
  135. data/lib/seam/routes/resources/device_provider.rb +0 -9
  136. data/lib/seam/routes/resources/enrollment_automation.rb +0 -11
  137. data/lib/seam/routes/resources/event.rb +0 -11
  138. data/lib/seam/routes/resources/index.rb +0 -33
  139. data/lib/seam/routes/resources/network.rb +0 -11
  140. data/lib/seam/routes/resources/noise_threshold.rb +0 -9
  141. data/lib/seam/routes/resources/phone.rb +0 -14
  142. data/lib/seam/routes/resources/resource_error.rb +0 -11
  143. data/lib/seam/routes/resources/resource_errors_support.rb +0 -11
  144. data/lib/seam/routes/resources/resource_warning.rb +0 -11
  145. data/lib/seam/routes/resources/resource_warnings_support.rb +0 -11
  146. data/lib/seam/routes/resources/service_health.rb +0 -9
  147. data/lib/seam/routes/resources/thermostat_schedule.rb +0 -13
  148. data/lib/seam/routes/resources/unmanaged_access_code.rb +0 -14
  149. data/lib/seam/routes/resources/unmanaged_device.rb +0 -14
  150. data/lib/seam/routes/resources/user_identity.rb +0 -11
  151. data/lib/seam/routes/resources/webhook.rb +0 -9
  152. data/lib/seam/routes/resources/workspace.rb +0 -9
  153. data/lib/seam/routes/routes.rb +0 -94
  154. data/lib/seam/token.rb +0 -53
  155. data/lib/seam/wait_for_action_attempt.rb +0 -32
  156. data/lib/seam/webhook.rb +0 -23
data/lib/seam/auth.rb DELETED
@@ -1,118 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "options"
4
- require_relative "token"
5
-
6
- module Seam
7
- module Http
8
- module Auth
9
- class SeamInvalidTokenError < StandardError
10
- def initialize(message)
11
- super("Seam received an invalid token: #{message}")
12
- end
13
- end
14
-
15
- def self.get_auth_headers(api_key: nil, personal_access_token: nil, workspace_id: nil)
16
- if Http::Options.seam_http_options_with_api_key?(api_key: api_key, personal_access_token: personal_access_token)
17
- return get_auth_headers_for_api_key(api_key)
18
- end
19
-
20
- if Http::Options.seam_http_options_with_personal_access_token?(personal_access_token: personal_access_token, api_key: api_key,
21
- workspace_id: workspace_id)
22
- return get_auth_headers_for_personal_access_token(personal_access_token, workspace_id)
23
- end
24
-
25
- raise Http::Options::SeamInvalidOptionsError.new(
26
- "Must specify an api_key or personal_access_token. " \
27
- "Attempted reading configuration from the environment, " \
28
- "but the environment variable SEAM_API_KEY is not set."
29
- )
30
- end
31
-
32
- def self.get_auth_headers_for_api_key(api_key)
33
- if Auth.client_session_token?(api_key)
34
- raise SeamInvalidTokenError.new(
35
- "A Client Session Token cannot be used as an api_key"
36
- )
37
- end
38
-
39
- raise SeamInvalidTokenError.new("A JWT cannot be used as an api_key") if Auth.jwt?(api_key)
40
-
41
- raise SeamInvalidTokenError.new("An Access Token cannot be used as an api_key") if Auth.access_token?(api_key)
42
-
43
- if Auth.publishable_key?(api_key)
44
- raise SeamInvalidTokenError.new(
45
- "A Publishable Key cannot be used as an api_key"
46
- )
47
- end
48
-
49
- unless Auth.seam_token?(api_key)
50
- raise SeamInvalidTokenError.new(
51
- "Unknown or invalid api_key format, expected token to start with #{Auth::TOKEN_PREFIX}"
52
- )
53
- end
54
-
55
- {"authorization" => "Bearer #{api_key}"}
56
- end
57
-
58
- def self.get_auth_headers_for_personal_access_token(personal_access_token, workspace_id)
59
- if Auth.jwt?(personal_access_token)
60
- raise SeamInvalidTokenError.new(
61
- "A JWT cannot be used as a personal_access_token"
62
- )
63
- end
64
-
65
- if Auth.client_session_token?(personal_access_token)
66
- raise SeamInvalidTokenError.new(
67
- "A Client Session Token cannot be used as a personal_access_token"
68
- )
69
- end
70
-
71
- if Auth.publishable_key?(personal_access_token)
72
- raise SeamInvalidTokenError.new(
73
- "A Publishable Key cannot be used as a personal_access_token"
74
- )
75
- end
76
-
77
- unless Auth.access_token?(personal_access_token)
78
- raise SeamInvalidTokenError.new(
79
- "Unknown or invalid personal_access_token format, expected token to start with #{Auth::ACCESS_TOKEN_PREFIX}"
80
- )
81
- end
82
-
83
- {
84
- "authorization" => "Bearer #{personal_access_token}",
85
- "seam-workspace" => workspace_id
86
- }
87
- end
88
-
89
- def self.get_auth_headers_for_multi_workspace_personal_access_token(personal_access_token)
90
- if Auth.jwt?(personal_access_token)
91
- raise SeamInvalidTokenError.new(
92
- "A JWT cannot be used as a personal_access_token"
93
- )
94
- end
95
-
96
- if Auth.client_session_token?(personal_access_token)
97
- raise SeamInvalidTokenError.new(
98
- "A Client Session Token cannot be used as a personal_access_token"
99
- )
100
- end
101
-
102
- if Auth.publishable_key?(personal_access_token)
103
- raise SeamInvalidTokenError.new(
104
- "A Publishable Key cannot be used as a personal_access_token"
105
- )
106
- end
107
-
108
- unless Auth.access_token?(personal_access_token)
109
- raise SeamInvalidTokenError.new(
110
- "Unknown or invalid personal_access_token format, expected token to start with #{Auth::ACCESS_TOKEN_PREFIX}"
111
- )
112
- end
113
-
114
- {"authorization" => "Bearer #{personal_access_token}"}
115
- end
116
- end
117
- end
118
- end
@@ -1,65 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "time"
4
- require_relative "deep_hash_accessor"
5
-
6
- module Seam
7
- module Resources
8
- class BaseResource
9
- attr_accessor :data, :client
10
-
11
- def initialize(data, client = nil)
12
- @data = data
13
- @client = client
14
-
15
- @data.each do |key, value|
16
- value = Seam::DeepHashAccessor.new(value) if value.is_a?(Hash)
17
- instance_variable_set(:"@#{key}", value)
18
- end
19
- end
20
-
21
- def update_from_response(data)
22
- @data = data
23
- @data.each do |key, value|
24
- value = Seam::DeepHashAccessor.new(value) if value.is_a?(Hash)
25
- instance_variable_set(:"@#{key}", value)
26
- end
27
- end
28
-
29
- def self.load_from_response(data, client = nil)
30
- if data.is_a?(Array)
31
- data.map { |d| new(d, client) }
32
- else
33
- new(data, client)
34
- end
35
- end
36
-
37
- def inspect
38
- "<#{self.class.name}:#{"0x00%x" % (object_id << 1)}\n" + # rubocop:disable Style/StringConcatenation, Style/FormatString
39
- instance_variables
40
- .map { |k| k.to_s.sub("@", "") }
41
- .filter { |k| k != "data" and k != "client" and respond_to? k }
42
- .map { |k| " #{k}=#{send(k).inspect}" }
43
- .join("\n") + ">"
44
- end
45
-
46
- def self.date_accessor(*attrs)
47
- attrs.each do |attr|
48
- define_method(attr) do
49
- value = instance_variable_get(:"@#{attr}")
50
-
51
- raise "No value for #{attr} set" if value.nil?
52
-
53
- parse_datetime(value)
54
- end
55
- end
56
- end
57
-
58
- protected
59
-
60
- def parse_datetime(value)
61
- Time.parse(value)
62
- end
63
- end
64
- end
65
- end
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "date"
4
-
5
- module Seam
6
- class DeepHashAccessor
7
- def initialize(data)
8
- @data = data
9
- create_accessor_methods
10
- end
11
-
12
- def [](key)
13
- instance_variable_get(:"@#{key}")
14
- end
15
-
16
- private
17
-
18
- def create_accessor_methods
19
- @data.each do |key, value|
20
- define_singleton_method(key) do
21
- process_value(value)
22
- end
23
- end
24
- end
25
-
26
- def process_value(value)
27
- case value
28
- when Hash
29
- DeepHashAccessor.new(value)
30
- when Array
31
- value.map { |v| process_value(v) }
32
- else
33
- value
34
- end
35
- end
36
- end
37
- end
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Seam
4
- DEFAULT_ENDPOINT = "https://connect.getseam.com"
5
- end
@@ -1,47 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../wait_for_action_attempt"
4
-
5
- module Seam
6
- module Helpers
7
- module ActionAttempt
8
- def self.decide_and_wait(action_attempt, client, wait_for_action_attempt)
9
- if wait_for_action_attempt == true
10
- return wait_until_finished(action_attempt, client)
11
- elsif wait_for_action_attempt.is_a?(Hash)
12
- return wait_until_finished(action_attempt, client, timeout: wait_for_action_attempt[:timeout],
13
- polling_interval: wait_for_action_attempt[:polling_interval])
14
- end
15
-
16
- action_attempt
17
- end
18
-
19
- def self.wait_until_finished(action_attempt, client, timeout: nil, polling_interval: nil)
20
- timeout = timeout.nil? ? 5.0 : timeout
21
- polling_interval = polling_interval.nil? ? 0.5 : polling_interval
22
-
23
- time_waiting = 0.0
24
-
25
- while action_attempt.status == "pending"
26
- sleep(polling_interval)
27
- time_waiting += polling_interval
28
-
29
- raise Seam::ActionAttemptTimeoutError.new(action_attempt, timeout) if time_waiting > timeout
30
-
31
- action_attempt = update_action_attempt(action_attempt, client)
32
- end
33
-
34
- raise Seam::ActionAttemptFailedError.new(action_attempt) if action_attempt.status == "error"
35
-
36
- action_attempt
37
- end
38
-
39
- def self.update_action_attempt(action_attempt, client)
40
- response = client.get("/action_attempts/get", {action_attempt_id: action_attempt.action_attempt_id})
41
-
42
- action_attempt.update_from_response(response.body["action_attempt"])
43
- action_attempt
44
- end
45
- end
46
- end
47
- end
data/lib/seam/http.rb DELETED
@@ -1,52 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "http_single_workspace"
4
-
5
- module Seam
6
- module Http
7
- def self.new(**args)
8
- Http::SingleWorkspace.new(**args)
9
- end
10
-
11
- def self.from_api_key(api_key, endpoint: nil, wait_for_action_attempt: false)
12
- Http::SingleWorkspace.from_api_key(api_key, endpoint: endpoint, wait_for_action_attempt: wait_for_action_attempt)
13
- end
14
-
15
- def self.from_personal_access_token(personal_access_token, workspace_id, endpoint: nil, wait_for_action_attempt: false)
16
- Http::SingleWorkspace.from_personal_access_token(personal_access_token, workspace_id, endpoint: endpoint,
17
- wait_for_action_attempt: wait_for_action_attempt)
18
- end
19
-
20
- class ApiError < StandardError
21
- attr_reader :code, :status_code, :request_id, :data
22
-
23
- def initialize(error, status_code, request_id)
24
- super(error[:message])
25
- @code = error[:type]
26
- @status_code = status_code
27
- @request_id = request_id
28
- @data = error[:data]
29
- end
30
- end
31
-
32
- class UnauthorizedError < ApiError
33
- def initialize(request_id)
34
- super({type: "unauthorized", message: "Unauthorized"}, 401, request_id)
35
- end
36
- end
37
-
38
- class InvalidInputError < ApiError
39
- attr_reader :validation_errors
40
-
41
- def initialize(error, status_code, request_id)
42
- super
43
- @code = "invalid_input"
44
- @validation_errors = error["validation_errors"] || {}
45
- end
46
-
47
- def get_validation_error_messages(param_name)
48
- @validation_errors.dig(param_name, "_errors") || []
49
- end
50
- end
51
- end
52
- end
@@ -1,66 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "request"
4
- require_relative "parse_options"
5
- require_relative "lts_version"
6
- require_relative "version"
7
- require_relative "auth"
8
- require_relative "routes/resources/index"
9
- require_relative "routes/clients/index"
10
- require_relative "routes/routes"
11
-
12
- module Seam
13
- module Http
14
- class MultiWorkspace
15
- attr_reader :client, :defaults
16
-
17
- def initialize(personal_access_token:, endpoint: nil, wait_for_action_attempt: true, faraday_options: {},
18
- faraday_retry_options: {})
19
- @wait_for_action_attempt = wait_for_action_attempt
20
- @defaults = {"wait_for_action_attempt" => wait_for_action_attempt}
21
- @endpoint = Http::Options.get_endpoint(endpoint)
22
- @auth_headers = Http::Auth.get_auth_headers_for_multi_workspace_personal_access_token(personal_access_token)
23
- @client = Http::Request.create_faraday_client(@endpoint, @auth_headers, faraday_options,
24
- faraday_retry_options)
25
- end
26
-
27
- def self.lts_version
28
- Seam::LTS_VERSION
29
- end
30
-
31
- def lts_version
32
- Seam::LTS_VERSION
33
- end
34
-
35
- def workspaces
36
- @workspaces ||= WorkspacesProxy.new(Seam::Clients::Workspaces.new(client: @client, defaults: @defaults))
37
- end
38
-
39
- def self.from_personal_access_token(personal_access_token, endpoint: nil, wait_for_action_attempt: true, faraday_options: {}, faraday_retry_options: {})
40
- new(
41
- personal_access_token: personal_access_token,
42
- endpoint: endpoint,
43
- wait_for_action_attempt: wait_for_action_attempt,
44
- faraday_options: faraday_options,
45
- faraday_retry_options: faraday_retry_options
46
- )
47
- end
48
- end
49
-
50
- class WorkspacesProxy
51
- def initialize(workspaces)
52
- @workspaces = workspaces
53
- end
54
-
55
- def list(**kwargs)
56
- @workspaces.list(**kwargs)
57
- end
58
-
59
- def create(**kwargs)
60
- @workspaces.create(**kwargs)
61
- end
62
- end
63
-
64
- private_constant :WorkspacesProxy
65
- end
66
- end
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "request"
4
- require_relative "parse_options"
5
- require_relative "routes/resources/index"
6
- require_relative "routes/clients/index"
7
- require_relative "routes/routes"
8
- require_relative "version"
9
- require_relative "deep_hash_accessor"
10
-
11
- module Seam
12
- module Http
13
- class SingleWorkspace
14
- include Seam::Routes
15
-
16
- attr_reader :client, :defaults
17
-
18
- def initialize(client: nil, api_key: nil, personal_access_token: nil, workspace_id: nil, endpoint: nil,
19
- wait_for_action_attempt: true, faraday_options: {}, faraday_retry_options: {})
20
- options = Http::Options.parse_options(api_key: api_key, personal_access_token: personal_access_token,
21
- workspace_id: workspace_id, endpoint: endpoint)
22
- @endpoint = options[:endpoint]
23
- @auth_headers = options[:auth_headers]
24
- @defaults = Seam::DeepHashAccessor.new({"wait_for_action_attempt" => wait_for_action_attempt})
25
- @client = client || Http::Request.create_faraday_client(@endpoint, @auth_headers, faraday_options,
26
- faraday_retry_options)
27
-
28
- initialize_routes(client: @client, defaults: @defaults)
29
- end
30
-
31
- def lts_version
32
- Seam::LTS_VERSION
33
- end
34
-
35
- def self.from_api_key(api_key, endpoint: nil, wait_for_action_attempt: false, faraday_options: {}, faraday_retry_options: {})
36
- new(api_key: api_key, endpoint: endpoint, wait_for_action_attempt: wait_for_action_attempt,
37
- faraday_options: faraday_options, faraday_retry_options: faraday_retry_options)
38
- end
39
-
40
- def self.from_personal_access_token(personal_access_token, workspace_id, endpoint: nil, wait_for_action_attempt: false, faraday_options: {}, faraday_retry_options: {})
41
- new(personal_access_token: personal_access_token, workspace_id: workspace_id, endpoint: endpoint,
42
- wait_for_action_attempt: wait_for_action_attempt, faraday_options: faraday_options, faraday_retry_options: faraday_retry_options)
43
- end
44
- end
45
- end
46
- end
data/lib/seam/options.rb DELETED
@@ -1,64 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "default_endpoint"
4
-
5
- module Seam
6
- module Http
7
- module Options
8
- def self.get_endpoint(endpoint = nil)
9
- endpoint || get_endpoint_from_env || Seam::DEFAULT_ENDPOINT
10
- end
11
-
12
- def self.get_endpoint_from_env
13
- seam_api_url = ENV["SEAM_API_URL"]
14
- seam_endpoint = ENV["SEAM_ENDPOINT"]
15
-
16
- if seam_api_url
17
- warn "\033[93mUsing the SEAM_API_URL environment variable is deprecated. Support will be removed in a later major version. Use SEAM_ENDPOINT instead.\033[0m"
18
- end
19
-
20
- if seam_api_url && seam_endpoint
21
- warn "\033[93mDetected both the SEAM_API_URL and SEAM_ENDPOINT environment variables. Using SEAM_ENDPOINT.\033[0m"
22
- end
23
-
24
- seam_endpoint || seam_api_url
25
- end
26
-
27
- class SeamInvalidOptionsError < StandardError
28
- def initialize(message)
29
- super("Seam received invalid options: #{message}")
30
- end
31
- end
32
-
33
- def self.seam_http_options_with_api_key?(api_key: nil, personal_access_token: nil)
34
- return false if api_key.nil?
35
-
36
- if personal_access_token
37
- raise SeamInvalidOptionsError.new(
38
- "The personal_access_token option cannot be used with the api_key option"
39
- )
40
- end
41
-
42
- true
43
- end
44
-
45
- def self.seam_http_options_with_personal_access_token?(personal_access_token: nil, api_key: nil, workspace_id: nil)
46
- return false if personal_access_token.nil?
47
-
48
- if api_key
49
- raise SeamInvalidOptionsError.new(
50
- "The api_key option cannot be used with the personal_access_token option"
51
- )
52
- end
53
-
54
- if workspace_id.nil?
55
- raise SeamInvalidOptionsError.new(
56
- "Must pass a workspace_id when using a personal_access_token"
57
- )
58
- end
59
-
60
- true
61
- end
62
- end
63
- end
64
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "auth"
4
- require_relative "options"
5
-
6
- module Seam
7
- module Http
8
- module Options
9
- def self.parse_options(api_key: nil, personal_access_token: nil, workspace_id: nil, endpoint: nil)
10
- api_key ||= ENV["SEAM_API_KEY"] if personal_access_token.nil?
11
-
12
- auth_headers = Http::Auth.get_auth_headers(
13
- api_key: api_key,
14
- personal_access_token: personal_access_token,
15
- workspace_id: workspace_id
16
- )
17
- endpoint = Http::Options.get_endpoint(endpoint)
18
-
19
- {auth_headers: auth_headers, endpoint: endpoint}
20
- end
21
- end
22
- end
23
- end
@@ -1,74 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Seam
4
- module Clients
5
- class AccessCodes
6
- def initialize(client:, defaults:)
7
- @client = client
8
- @defaults = defaults
9
- end
10
-
11
- def simulate
12
- @simulate ||= Seam::Clients::AccessCodesSimulate.new(client: @client, defaults: @defaults)
13
- end
14
-
15
- def unmanaged
16
- @unmanaged ||= Seam::Clients::AccessCodesUnmanaged.new(client: @client, defaults: @defaults)
17
- end
18
-
19
- def create(device_id:, allow_external_modification: nil, attempt_for_offline_device: nil, code: nil, common_code_key: nil, ends_at: nil, is_external_modification_allowed: nil, is_offline_access_code: nil, is_one_time_use: nil, max_time_rounding: nil, name: nil, prefer_native_scheduling: nil, preferred_code_length: nil, starts_at: nil, sync: nil, use_backup_access_code_pool: nil, use_offline_access_code: nil)
20
- res = @client.post("/access_codes/create", {device_id: device_id, allow_external_modification: allow_external_modification, attempt_for_offline_device: attempt_for_offline_device, code: code, common_code_key: common_code_key, ends_at: ends_at, is_external_modification_allowed: is_external_modification_allowed, is_offline_access_code: is_offline_access_code, is_one_time_use: is_one_time_use, max_time_rounding: max_time_rounding, name: name, prefer_native_scheduling: prefer_native_scheduling, preferred_code_length: preferred_code_length, starts_at: starts_at, sync: sync, use_backup_access_code_pool: use_backup_access_code_pool, use_offline_access_code: use_offline_access_code}.compact)
21
-
22
- Seam::Resources::AccessCode.load_from_response(res.body["access_code"])
23
- end
24
-
25
- def create_multiple(device_ids:, allow_external_modification: nil, attempt_for_offline_device: nil, behavior_when_code_cannot_be_shared: nil, code: nil, ends_at: nil, is_external_modification_allowed: nil, is_offline_access_code: nil, is_one_time_use: nil, max_time_rounding: nil, name: nil, prefer_native_scheduling: nil, preferred_code_length: nil, starts_at: nil, use_backup_access_code_pool: nil, use_offline_access_code: nil)
26
- res = @client.post("/access_codes/create_multiple", {device_ids: device_ids, allow_external_modification: allow_external_modification, attempt_for_offline_device: attempt_for_offline_device, behavior_when_code_cannot_be_shared: behavior_when_code_cannot_be_shared, code: code, ends_at: ends_at, is_external_modification_allowed: is_external_modification_allowed, is_offline_access_code: is_offline_access_code, is_one_time_use: is_one_time_use, max_time_rounding: max_time_rounding, name: name, prefer_native_scheduling: prefer_native_scheduling, preferred_code_length: preferred_code_length, starts_at: starts_at, use_backup_access_code_pool: use_backup_access_code_pool, use_offline_access_code: use_offline_access_code}.compact)
27
-
28
- Seam::Resources::AccessCode.load_from_response(res.body["access_codes"])
29
- end
30
-
31
- def delete(access_code_id:, device_id: nil, sync: nil)
32
- @client.post("/access_codes/delete", {access_code_id: access_code_id, device_id: device_id, sync: sync}.compact)
33
-
34
- nil
35
- end
36
-
37
- def generate_code(device_id:)
38
- res = @client.post("/access_codes/generate_code", {device_id: device_id}.compact)
39
-
40
- Seam::Resources::AccessCode.load_from_response(res.body["generated_code"])
41
- end
42
-
43
- def get(access_code_id: nil, code: nil, device_id: nil)
44
- res = @client.post("/access_codes/get", {access_code_id: access_code_id, code: code, device_id: device_id}.compact)
45
-
46
- Seam::Resources::AccessCode.load_from_response(res.body["access_code"])
47
- end
48
-
49
- def list(access_code_ids: nil, device_id: nil, user_identifier_key: nil)
50
- res = @client.post("/access_codes/list", {access_code_ids: access_code_ids, device_id: device_id, user_identifier_key: user_identifier_key}.compact)
51
-
52
- Seam::Resources::AccessCode.load_from_response(res.body["access_codes"])
53
- end
54
-
55
- def pull_backup_access_code(access_code_id:)
56
- res = @client.post("/access_codes/pull_backup_access_code", {access_code_id: access_code_id}.compact)
57
-
58
- Seam::Resources::AccessCode.load_from_response(res.body["backup_access_code"])
59
- end
60
-
61
- def update(access_code_id:, allow_external_modification: nil, attempt_for_offline_device: nil, code: nil, device_id: nil, ends_at: nil, is_external_modification_allowed: nil, is_managed: nil, is_offline_access_code: nil, is_one_time_use: nil, max_time_rounding: nil, name: nil, prefer_native_scheduling: nil, preferred_code_length: nil, starts_at: nil, sync: nil, type: nil, use_backup_access_code_pool: nil, use_offline_access_code: nil)
62
- @client.post("/access_codes/update", {access_code_id: access_code_id, allow_external_modification: allow_external_modification, attempt_for_offline_device: attempt_for_offline_device, code: code, device_id: device_id, ends_at: ends_at, is_external_modification_allowed: is_external_modification_allowed, is_managed: is_managed, is_offline_access_code: is_offline_access_code, is_one_time_use: is_one_time_use, max_time_rounding: max_time_rounding, name: name, prefer_native_scheduling: prefer_native_scheduling, preferred_code_length: preferred_code_length, starts_at: starts_at, sync: sync, type: type, use_backup_access_code_pool: use_backup_access_code_pool, use_offline_access_code: use_offline_access_code}.compact)
63
-
64
- nil
65
- end
66
-
67
- def update_multiple(common_code_key:, allow_external_modification: nil, code: nil, ends_at: nil, is_external_modification_allowed: nil, name: nil, prefer_native_scheduling: nil, starts_at: nil)
68
- @client.post("/access_codes/update_multiple", {common_code_key: common_code_key, allow_external_modification: allow_external_modification, code: code, ends_at: ends_at, is_external_modification_allowed: is_external_modification_allowed, name: name, prefer_native_scheduling: prefer_native_scheduling, starts_at: starts_at}.compact)
69
-
70
- nil
71
- end
72
- end
73
- end
74
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Seam
4
- module Clients
5
- class AccessCodesSimulate
6
- def initialize(client:, defaults:)
7
- @client = client
8
- @defaults = defaults
9
- end
10
-
11
- def create_unmanaged_access_code(code:, device_id:, name:)
12
- res = @client.post("/access_codes/simulate/create_unmanaged_access_code", {code: code, device_id: device_id, name: name}.compact)
13
-
14
- Seam::Resources::UnmanagedAccessCode.load_from_response(res.body["access_code"])
15
- end
16
- end
17
- end
18
- end
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Seam
4
- module Clients
5
- class AccessCodesUnmanaged
6
- def initialize(client:, defaults:)
7
- @client = client
8
- @defaults = defaults
9
- end
10
-
11
- def convert_to_managed(access_code_id:, allow_external_modification: nil, force: nil, is_external_modification_allowed: nil, sync: nil)
12
- @client.post("/access_codes/unmanaged/convert_to_managed", {access_code_id: access_code_id, allow_external_modification: allow_external_modification, force: force, is_external_modification_allowed: is_external_modification_allowed, sync: sync}.compact)
13
-
14
- nil
15
- end
16
-
17
- def delete(access_code_id:, sync: nil)
18
- @client.post("/access_codes/unmanaged/delete", {access_code_id: access_code_id, sync: sync}.compact)
19
-
20
- nil
21
- end
22
-
23
- def get(access_code_id: nil, code: nil, device_id: nil)
24
- res = @client.post("/access_codes/unmanaged/get", {access_code_id: access_code_id, code: code, device_id: device_id}.compact)
25
-
26
- Seam::Resources::UnmanagedAccessCode.load_from_response(res.body["access_code"])
27
- end
28
-
29
- def list(device_id:, user_identifier_key: nil)
30
- res = @client.post("/access_codes/unmanaged/list", {device_id: device_id, user_identifier_key: user_identifier_key}.compact)
31
-
32
- Seam::Resources::UnmanagedAccessCode.load_from_response(res.body["access_codes"])
33
- end
34
-
35
- def update(access_code_id:, is_managed:, allow_external_modification: nil, force: nil, is_external_modification_allowed: nil)
36
- @client.post("/access_codes/unmanaged/update", {access_code_id: access_code_id, is_managed: is_managed, allow_external_modification: allow_external_modification, force: force, is_external_modification_allowed: is_external_modification_allowed}.compact)
37
-
38
- nil
39
- end
40
- end
41
- end
42
- end