Class: Shark::DoubleOptIn::Execution
- Extended by:
- Resource
- Defined in:
- lib/shark/double_opt_in/execution.rb
Instance Attribute Summary collapse
-
#payload ⇒ Object
Returns the value of attribute payload.
-
#recipient ⇒ Object
Returns the value of attribute recipient.
-
#request_type ⇒ Object
Returns the value of attribute request_type.
Class Method Summary collapse
- .caused_by_error_code?(errors, error_code) ⇒ Boolean
- .find(verification_token) ⇒ Object
- .terminate(verification_token) ⇒ Object
- .verify(verification_token) ⇒ Object
Instance Method Summary collapse
-
#initialize(data) ⇒ Execution
constructor
A new instance of Execution.
Methods inherited from Base
Constructor Details
#initialize(data) ⇒ Execution
Returns a new instance of Execution.
39 40 41 42 43 |
# File 'lib/shark/double_opt_in/execution.rb', line 39 def initialize(data) %w[payload request_type recipient].each do |key| public_send("#{key}=", data['attributes'][key]) end end |
Instance Attribute Details
#payload ⇒ Object
Returns the value of attribute payload.
8 9 10 |
# File 'lib/shark/double_opt_in/execution.rb', line 8 def payload @payload end |
#recipient ⇒ Object
Returns the value of attribute recipient.
8 9 10 |
# File 'lib/shark/double_opt_in/execution.rb', line 8 def recipient @recipient end |
#request_type ⇒ Object
Returns the value of attribute request_type.
8 9 10 |
# File 'lib/shark/double_opt_in/execution.rb', line 8 def request_type @request_type end |
Class Method Details
.caused_by_error_code?(errors, error_code) ⇒ Boolean
45 46 47 |
# File 'lib/shark/double_opt_in/execution.rb', line 45 def self.caused_by_error_code?(errors, error_code) errors.detect { |error| error['code'] == error_code } end |
.find(verification_token) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/shark/double_opt_in/execution.rb', line 23 def self.find(verification_token) response = connection.run(:get, "/executions/#{verification_token}") new(response.body['data']) rescue UnprocessableEntity => e if caused_by_error_code?(e.errors, 'requested_unverified_execution') raise RequestedUnverifiedExecutionError end raise e end |
.terminate(verification_token) ⇒ Object
34 35 36 37 |
# File 'lib/shark/double_opt_in/execution.rb', line 34 def self.terminate(verification_token) response = connection.run(:delete, "/executions/#{verification_token}") new(response.body['data']) end |
.verify(verification_token) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/shark/double_opt_in/execution.rb', line 10 def self.verify(verification_token) response = connection.run(:post, "/executions/#{verification_token}/verify") new(response.body['data']) rescue UnprocessableEntity => e if caused_by_error_code?(e.errors, 'exceeded_number_of_verification_requests') raise ExceededNumberOfVerificationRequestsError end raise VerificationExpiredError if caused_by_error_code?(e.errors, 'verification_expired') raise e end |