lib/seam/resources/action_attempt.rb in seamapi-0.0.2 vs lib/seam/resources/action_attempt.rb in seamapi-0.0.3

- old
+ new

@@ -2,19 +2,31 @@ module Seam class ActionAttempt < BaseResource attr_accessor :action_attempt_id, :action_type, :status, :result + SLEEP_TIME = 0.2 + MAX_ATTEMPTS = 10 + def wait_until_finished while @status == "pending" - res = Seam::Request.new(@client.api_key, @client.base_uri).perform( - :get, - "/action_attempts/get", - params: { action_attempt_id: @action_attempt_id } - ) - update_from_response(res["action_attempt"]) - sleep(0.2) + update! + + sleep(SLEEP_TIME) end + self + end + + def update! + response = @client.request_seam( + :get, + "/action_attempts/get", + params: { + action_attempt_id: action_attempt_id + } + ) + + update_from_response(response["action_attempt"]) end end end