Class: Locked::Client
- Inherits:
-
Object
- Object
- Locked::Client
- Defined in:
- lib/locked/client.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
Class Method Summary collapse
- .failover_response_or_raise(failover_response, error) ⇒ Object
- .from_request(request, options = {}) ⇒ Object
- .to_context(request, options = {}) ⇒ Object
- .to_options(options = {}) ⇒ Object
Instance Method Summary collapse
- #authenticate(options = {}) ⇒ Object
- #failed_in_verification(token = {}) ⇒ Object
- #identify(options = {}) ⇒ Object
-
#initialize(context, options = {}) ⇒ Client
constructor
A new instance of Client.
- #succeeded_in_verification(token = {}) ⇒ Object
Constructor Details
#initialize(context, options = {}) ⇒ Client
Returns a new instance of Client.
32 33 34 35 |
# File 'lib/locked/client.rb', line 32 def initialize(context, = {}) @timestamp = [:timestamp] @context = context end |
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
30 31 32 |
# File 'lib/locked/client.rb', line 30 def context @context end |
Class Method Details
.failover_response_or_raise(failover_response, error) ⇒ Object
24 25 26 27 |
# File 'lib/locked/client.rb', line 24 def failover_response_or_raise(failover_response, error) return failover_response.generate unless Locked.config.failover_strategy == :throw raise error end |
.from_request(request, options = {}) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/locked/client.rb', line 6 def from_request(request, = {}) new( to_context(request, ), () ) end |
Instance Method Details
#authenticate(options = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/locked/client.rb', line 37 def authenticate( = {}) = Locked::Utils.deep_symbolize_keys( || {}) () command = Locked::Commands::Authenticate.new(@context).build() begin Locked::API.request(command).merge(failover: false, failover_reason: nil) rescue Locked::RequestError, Locked::InternalServerError => error self.class.failover_response_or_raise( Locked::FailoverResponse::Auth.new([:user_id], reason: error.to_s), error ) end end |
#failed_in_verification(token = {}) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/locked/client.rb', line 51 def failed_in_verification(token = {}) command = Locked::Commands::Verify.new(@context).build('deny_verification', token) begin response = Locked::API.request(command) response.merge(failover: false, failover_reason: nil) rescue Locked::RequestError, Locked::InternalServerError => error self.class.failover_response_or_raise( Locked::FailoverResponse::Verification.new(reason: error.to_s), error ) end end |
#identify(options = {}) ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/locked/client.rb', line 75 def identify( = {}) = Locked::Utils.deep_symbolize_keys( || {}) () command = Locked::Commands::Identify.new(@context).build() Locked::API.request(command) end |
#succeeded_in_verification(token = {}) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/locked/client.rb', line 63 def succeeded_in_verification(token = {}) command = Locked::Commands::Verify.new(@context).build('allow_verification', token) begin response = Locked::API.request(command) response.merge(failover: false, failover_reason: nil) rescue Locked::RequestError, Locked::InternalServerError => error self.class.failover_response_or_raise( Locked::FailoverResponse::Verification.new(reason: error.to_s), error ) end end |