Class: Castle::Client
- Inherits:
-
Object
- Object
- Castle::Client
- Defined in:
- lib/castle/client.rb
Instance Attribute Summary collapse
-
#api ⇒ Object
Returns the value of attribute api.
Instance Method Summary collapse
- #authenticate(options = {}) ⇒ Object
- #disable_tracking ⇒ Object
- #enable_tracking ⇒ Object
- #identify(options = {}) ⇒ Object
-
#initialize(request, options = {}) ⇒ Client
constructor
A new instance of Client.
- #track(options = {}) ⇒ Object
- #tracked? ⇒ Boolean
Constructor Details
#initialize(request, options = {}) ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 |
# File 'lib/castle/client.rb', line 7 def initialize(request, = {}) @do_not_track = default_tracking() @context = setup_context(request, [:cookies], [:context]) @api = API.new end |
Instance Attribute Details
#api ⇒ Object
Returns the value of attribute api.
5 6 7 |
# File 'lib/castle/client.rb', line 5 def api @api end |
Instance Method Details
#authenticate(options = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/castle/client.rb', line 13 def authenticate( = {}) = Castle::Utils.deep_symbolize_keys( || {}) if tracked? command = Castle::Commands::Authenticate.new(@context).build() begin @api.request(command).merge('failover' => false, 'failover_reason' => nil) rescue Castle::RequestError, Castle::InternalServerError => error failover_response_or_raise(FailoverAuthResponse.new([:user_id], reason: error.to_s), error) end else FailoverAuthResponse.new([:user_id], strategy: :allow, reason: 'Castle set to do not track.').generate end end |
#disable_tracking ⇒ Object
46 47 48 |
# File 'lib/castle/client.rb', line 46 def disable_tracking @do_not_track = true end |
#enable_tracking ⇒ Object
50 51 52 |
# File 'lib/castle/client.rb', line 50 def enable_tracking @do_not_track = false end |
#identify(options = {}) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/castle/client.rb', line 28 def identify( = {}) = Castle::Utils.deep_symbolize_keys( || {}) return unless tracked? command = Castle::Commands::Identify.new(@context).build() @api.request(command) end |
#track(options = {}) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/castle/client.rb', line 37 def track( = {}) = Castle::Utils.deep_symbolize_keys( || {}) return unless tracked? command = Castle::Commands::Track.new(@context).build() @api.request(command) end |
#tracked? ⇒ Boolean
54 55 56 |
# File 'lib/castle/client.rb', line 54 def tracked? !@do_not_track end |