seam 2.141.0 → 2.141.1

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: 67761c76f072fe523b56a8ee78b3112bcccd5c2da40cdd6a38c623e251a66861
4
- data.tar.gz: 17eb707e5799d5b97c05d18abb5ce0224411a9cb5f06d00166a791de0e342c66
3
+ metadata.gz: e99e4c607a0b5f8714d0067e093f8ab93766a3af4cd069f26988e483da203943
4
+ data.tar.gz: db6cd5c445363a9bdc119946829dac7a44aaf0ff7a278063e818133680e1edea
5
5
  SHA512:
6
- metadata.gz: dda63b3fe99166377d432246a928f10da2f337cd8633da0df34055efb453afcffbdda6392b3ad94d4951ed12badf293dfb0bb94f5e2dd16dd8f36ef0ffe58f78
7
- data.tar.gz: 03233cc7ee5e3136c92e3274410539c0642e69352538797198e2a2dfaebfd9d3187a6fa1e15cfbd744b36c3c8ab12e490631f6513020fd8298e295d5b3fbce34
6
+ metadata.gz: 418154fb53f041f8682566396ecfae077473c5d64993afb5208d2eee316b60e508362de340b6ce83d68058b2098bf76347f70042ea023215c15a5d921916cea9
7
+ data.tar.gz: b58f492190db82e6be16f4f65a968a40d8569278781aa1238dec0c70c88e4241394ffff34b2ce9e6c662b048d635581e57eadb32b54a589b3513e683bac1b802
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- seam (2.141.0)
4
+ seam (2.141.1)
5
5
  faraday (~> 2.7)
6
6
  faraday-retry (~> 2.2)
7
7
  svix (~> 1.30)
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "wait_for_action_attempt"
4
+
5
+ module Seam
6
+ class ActionAttemptResolver
7
+ def self.resolve(action_attempt, client, wait_for_action_attempt)
8
+ return wait_until_resolved(action_attempt, client) if wait_for_action_attempt == true
9
+
10
+ options = wait_options(wait_for_action_attempt)
11
+ return action_attempt if options.nil?
12
+
13
+ wait_until_resolved(action_attempt, client, timeout: options[:timeout],
14
+ polling_interval: options[:polling_interval])
15
+ end
16
+
17
+ # The client wraps its defaults in a DeepHashAccessor, so the hash form of
18
+ # this option reaches here as an accessor when it comes from the client
19
+ # and as a plain Hash when it comes from the method call.
20
+ def self.wait_options(wait_for_action_attempt)
21
+ case wait_for_action_attempt
22
+ when Hash then wait_for_action_attempt
23
+ when Seam::DeepHashAccessor then wait_for_action_attempt.to_h
24
+ end
25
+ end
26
+
27
+ def self.wait_until_resolved(action_attempt, client, timeout: nil, polling_interval: nil)
28
+ timeout = timeout.nil? ? 5.0 : timeout
29
+ polling_interval = polling_interval.nil? ? 0.5 : polling_interval
30
+
31
+ time_waiting = 0.0
32
+
33
+ while action_attempt.status == "pending"
34
+ sleep(polling_interval)
35
+ time_waiting += polling_interval
36
+
37
+ raise Seam::ActionAttemptTimeoutError.new(action_attempt, timeout) if time_waiting > timeout
38
+
39
+ action_attempt = update_action_attempt(action_attempt, client)
40
+ end
41
+
42
+ raise Seam::ActionAttemptFailedError.new(action_attempt) if action_attempt.status == "error"
43
+
44
+ action_attempt
45
+ end
46
+
47
+ def self.update_action_attempt(action_attempt, client)
48
+ response = client.get("/action_attempts/get", {action_attempt_id: action_attempt.action_attempt_id})
49
+
50
+ action_attempt.update_from_response(response.body["action_attempt"])
51
+ action_attempt
52
+ end
53
+ end
54
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "seam/helpers/action_attempt"
3
+ require "seam/action_attempt_resolver"
4
4
 
5
5
  module Seam
6
6
  module Clients
@@ -23,7 +23,7 @@ module Seam
23
23
 
24
24
  wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt
25
25
 
26
- Helpers::ActionAttempt.decide_and_wait(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
26
+ Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
27
27
  end
28
28
 
29
29
  # Deletes an access method.
@@ -50,7 +50,7 @@ module Seam
50
50
 
51
51
  wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt
52
52
 
53
- Helpers::ActionAttempt.decide_and_wait(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
53
+ Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
54
54
  end
55
55
 
56
56
  # Gets an access method.
@@ -102,7 +102,7 @@ module Seam
102
102
 
103
103
  wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt
104
104
 
105
- Helpers::ActionAttempt.decide_and_wait(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
105
+ Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
106
106
  end
107
107
  end
108
108
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "seam/helpers/action_attempt"
3
+ require "seam/action_attempt_resolver"
4
4
 
5
5
  module Seam
6
6
  module Clients
@@ -24,7 +24,7 @@ module Seam
24
24
 
25
25
  wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt
26
26
 
27
- Helpers::ActionAttempt.decide_and_wait(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
27
+ Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
28
28
  end
29
29
 
30
30
  # Returns a specified [encoder](https://docs.seam.co/low-level-apis/access-systems/working-with-card-encoders-and-scanners).
@@ -58,7 +58,7 @@ module Seam
58
58
 
59
59
  wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt
60
60
 
61
- Helpers::ActionAttempt.decide_and_wait(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
61
+ Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
62
62
  end
63
63
 
64
64
  # Scans a physical card placed on the specified [encoder](https://docs.seam.co/low-level-apis/access-systems/working-with-card-encoders-and-scanners) and assigns the scanned credential to an ACS user. Provide either an `acs_user_id` or a `user_identity_id`.
@@ -72,7 +72,7 @@ module Seam
72
72
 
73
73
  wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt
74
74
 
75
- Helpers::ActionAttempt.decide_and_wait(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
75
+ Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
76
76
  end
77
77
  end
78
78
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "seam/helpers/action_attempt"
3
+ require "seam/action_attempt_resolver"
4
4
 
5
5
  module Seam
6
6
  module Clients
@@ -69,7 +69,7 @@ module Seam
69
69
 
70
70
  wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt
71
71
 
72
- Helpers::ActionAttempt.decide_and_wait(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
72
+ Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
73
73
  end
74
74
  end
75
75
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "seam/helpers/action_attempt"
3
+ require "seam/action_attempt_resolver"
4
4
 
5
5
  module Seam
6
6
  module Clients
@@ -18,7 +18,7 @@ module Seam
18
18
 
19
19
  wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt
20
20
 
21
- Helpers::ActionAttempt.decide_and_wait(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
21
+ Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
22
22
  end
23
23
 
24
24
  # Returns a list of the [action attempts](https://docs.seam.co/core-concepts/action-attempts) that you specify as an array of `action_attempt_id`s.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "seam/helpers/action_attempt"
3
+ require "seam/action_attempt_resolver"
4
4
 
5
5
  module Seam
6
6
  module Clients
@@ -24,7 +24,7 @@ module Seam
24
24
 
25
25
  wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt
26
26
 
27
- Helpers::ActionAttempt.decide_and_wait(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
27
+ Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
28
28
  end
29
29
 
30
30
  # Returns a specified [lock](https://docs.seam.co/low-level-apis/smart-locks).
@@ -64,7 +64,7 @@ module Seam
64
64
 
65
65
  wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt
66
66
 
67
- Helpers::ActionAttempt.decide_and_wait(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
67
+ Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
68
68
  end
69
69
 
70
70
  # Unlocks a [lock](https://docs.seam.co/low-level-apis/smart-locks). See also [Locking and Unlocking Smart Locks](https://docs.seam.co/low-level-apis/smart-locks/lock-and-unlock).
@@ -75,7 +75,7 @@ module Seam
75
75
 
76
76
  wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt
77
77
 
78
- Helpers::ActionAttempt.decide_and_wait(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
78
+ Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
79
79
  end
80
80
  end
81
81
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "seam/helpers/action_attempt"
3
+ require "seam/action_attempt_resolver"
4
4
 
5
5
  module Seam
6
6
  module Clients
@@ -19,7 +19,7 @@ module Seam
19
19
 
20
20
  wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt
21
21
 
22
- Helpers::ActionAttempt.decide_and_wait(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
22
+ Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
23
23
  end
24
24
 
25
25
  # Simulates a manual lock action using a keypad. You can only perform this action for [August](https://docs.seam.co/device-and-system-integration-guides/august-locks) devices within [sandbox workspaces](https://docs.seam.co/core-concepts/workspaces#sandbox-workspaces).
@@ -30,7 +30,7 @@ module Seam
30
30
 
31
31
  wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt
32
32
 
33
- Helpers::ActionAttempt.decide_and_wait(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
33
+ Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
34
34
  end
35
35
  end
36
36
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "seam/helpers/action_attempt"
3
+ require "seam/action_attempt_resolver"
4
4
 
5
5
  module Seam
6
6
  module Clients
@@ -31,7 +31,7 @@ module Seam
31
31
 
32
32
  wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt
33
33
 
34
- Helpers::ActionAttempt.decide_and_wait(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
34
+ Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
35
35
  end
36
36
 
37
37
  # Sets a specified [thermostat](https://docs.seam.co/capability-guides/thermostats) to [cool mode](https://docs.seam.co/capability-guides/thermostats/configure-current-climate-settings).
@@ -44,7 +44,7 @@ module Seam
44
44
 
45
45
  wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt
46
46
 
47
- Helpers::ActionAttempt.decide_and_wait(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
47
+ Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
48
48
  end
49
49
 
50
50
  # Creates a [climate preset](https://docs.seam.co/capability-guides/thermostats/creating-and-managing-climate-presets) for a specified [thermostat](https://docs.seam.co/capability-guides/thermostats).
@@ -88,7 +88,7 @@ module Seam
88
88
 
89
89
  wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt
90
90
 
91
- Helpers::ActionAttempt.decide_and_wait(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
91
+ Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
92
92
  end
93
93
 
94
94
  # Sets a specified [thermostat](https://docs.seam.co/capability-guides/thermostats) to [heat-cool ("auto") mode](https://docs.seam.co/capability-guides/thermostats/configure-current-climate-settings).
@@ -103,7 +103,7 @@ module Seam
103
103
 
104
104
  wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt
105
105
 
106
- Helpers::ActionAttempt.decide_and_wait(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
106
+ Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
107
107
  end
108
108
 
109
109
  # Returns a list of all [thermostats](https://docs.seam.co/capability-guides/thermostats).
@@ -128,7 +128,7 @@ module Seam
128
128
 
129
129
  wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt
130
130
 
131
- Helpers::ActionAttempt.decide_and_wait(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
131
+ Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
132
132
  end
133
133
 
134
134
  # Sets a specified [climate preset](https://docs.seam.co/capability-guides/thermostats/creating-and-managing-climate-presets) as the ["fallback"](https://docs.seam.co/capability-guides/thermostats/creating-and-managing-climate-presets/setting-the-fallback-climate-preset) preset for a specified [thermostat](https://docs.seam.co/capability-guides/thermostats).
@@ -152,7 +152,7 @@ module Seam
152
152
 
153
153
  wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt
154
154
 
155
- Helpers::ActionAttempt.decide_and_wait(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
155
+ Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
156
156
  end
157
157
 
158
158
  # Sets the [HVAC mode](https://docs.seam.co/capability-guides/thermostats/configure-current-climate-settings) for a specified [thermostat](https://docs.seam.co/capability-guides/thermostats).
@@ -168,7 +168,7 @@ module Seam
168
168
 
169
169
  wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt
170
170
 
171
- Helpers::ActionAttempt.decide_and_wait(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
171
+ Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
172
172
  end
173
173
 
174
174
  # Sets a [temperature threshold](https://docs.seam.co/capability-guides/thermostats/setting-and-monitoring-temperature-thresholds) for a specified thermostat. Seam emits a `thermostat.temperature_threshold_exceeded` event and adds a warning on a thermostat if it reports a temperature outside the threshold range.
@@ -220,7 +220,7 @@ module Seam
220
220
 
221
221
  wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt
222
222
 
223
- Helpers::ActionAttempt.decide_and_wait(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
223
+ Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
224
224
  end
225
225
  end
226
226
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "seam/helpers/action_attempt"
3
+ require "seam/action_attempt_resolver"
4
4
 
5
5
  module Seam
6
6
  module Clients
@@ -40,7 +40,7 @@ module Seam
40
40
 
41
41
  wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt
42
42
 
43
- Helpers::ActionAttempt.decide_and_wait(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
43
+ Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
44
44
  end
45
45
  end
46
46
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "seam/helpers/action_attempt"
3
+ require "seam/action_attempt_resolver"
4
4
 
5
5
  module Seam
6
6
  module Clients
@@ -56,7 +56,7 @@ module Seam
56
56
 
57
57
  wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt
58
58
 
59
- Helpers::ActionAttempt.decide_and_wait(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
59
+ Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["action_attempt"]), @client, wait_for_action_attempt)
60
60
  end
61
61
 
62
62
  # Updates the [workspace](https://docs.seam.co/core-concepts/workspaces) associated with the authentication value.
data/lib/seam/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Seam
4
- VERSION = "2.141.0"
4
+ VERSION = "2.141.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seam
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.141.0
4
+ version: 2.141.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seam Labs, Inc.
@@ -189,11 +189,11 @@ files:
189
189
  - README.md
190
190
  - Rakefile
191
191
  - lib/seam.rb
192
+ - lib/seam/action_attempt_resolver.rb
192
193
  - lib/seam/auth.rb
193
194
  - lib/seam/base_resource.rb
194
195
  - lib/seam/deep_hash_accessor.rb
195
196
  - lib/seam/defaults.rb
196
- - lib/seam/helpers/action_attempt.rb
197
197
  - lib/seam/http.rb
198
198
  - lib/seam/http_single_workspace.rb
199
199
  - lib/seam/http_without_workspace.rb
@@ -1,56 +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
- return wait_until_finished(action_attempt, client) if wait_for_action_attempt == true
10
-
11
- options = wait_options(wait_for_action_attempt)
12
- return action_attempt if options.nil?
13
-
14
- wait_until_finished(action_attempt, client, timeout: options[:timeout],
15
- polling_interval: options[:polling_interval])
16
- end
17
-
18
- # The client wraps its defaults in a DeepHashAccessor, so the hash form of
19
- # this option reaches here as an accessor when it comes from the client
20
- # and as a plain Hash when it comes from the method call.
21
- def self.wait_options(wait_for_action_attempt)
22
- case wait_for_action_attempt
23
- when Hash then wait_for_action_attempt
24
- when Seam::DeepHashAccessor then wait_for_action_attempt.to_h
25
- end
26
- end
27
-
28
- def self.wait_until_finished(action_attempt, client, timeout: nil, polling_interval: nil)
29
- timeout = timeout.nil? ? 5.0 : timeout
30
- polling_interval = polling_interval.nil? ? 0.5 : polling_interval
31
-
32
- time_waiting = 0.0
33
-
34
- while action_attempt.status == "pending"
35
- sleep(polling_interval)
36
- time_waiting += polling_interval
37
-
38
- raise Seam::ActionAttemptTimeoutError.new(action_attempt, timeout) if time_waiting > timeout
39
-
40
- action_attempt = update_action_attempt(action_attempt, client)
41
- end
42
-
43
- raise Seam::ActionAttemptFailedError.new(action_attempt) if action_attempt.status == "error"
44
-
45
- action_attempt
46
- end
47
-
48
- def self.update_action_attempt(action_attempt, client)
49
- response = client.get("/action_attempts/get", {action_attempt_id: action_attempt.action_attempt_id})
50
-
51
- action_attempt.update_from_response(response.body["action_attempt"])
52
- action_attempt
53
- end
54
- end
55
- end
56
- end