Skip to content

Commit dbb3016

Browse files
razor-xseambot
andauthored
Remove helpers path (#554)
* Remove helpers path * ci: Generate code --------- Co-authored-by: Seam Bot <seambot@getseam.com>
1 parent 5111a49 commit dbb3016

14 files changed

Lines changed: 89 additions & 91 deletions

‎codegen/layouts/client.hbs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22
{{#if importActionAttempt}}
33

4-
require "seam/helpers/action_attempt"
4+
require "seam/action_attempt_resolver"
55
{{/if}}
66

77
module Seam

‎codegen/layouts/partials/client-method.hbs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt
2525

26-
Helpers::ActionAttempt.decide_and_wait(Seam::Resources::ActionAttempt.load_from_response(res.body["{{returnPath}}"]), @client, wait_for_action_attempt)
26+
Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["{{returnPath}}"]), @client, wait_for_action_attempt)
2727
{{/if}}
2828
{{#if isNil}}
2929

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

‎lib/seam/helpers/action_attempt.rb‎

Lines changed: 0 additions & 56 deletions
This file was deleted.

‎lib/seam/routes/access_methods.rb‎

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/seam/routes/acs_encoders.rb‎

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/seam/routes/acs_entrances.rb‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/seam/routes/action_attempts.rb‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/seam/routes/locks.rb‎

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/seam/routes/locks_simulate.rb‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)