Class: Castle::Client
- Inherits:
-
Object
- Object
- Castle::Client
- Defined in:
- lib/castle/client.rb
Overview
Castle’s client.
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
Class Method Summary collapse
Instance Method Summary collapse
- #authenticate(options = {}) ⇒ Object
- #disable_tracking ⇒ Object
- #enable_tracking ⇒ Object
- #end_impersonation(options = {}) ⇒ Object
- #filter(options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #log(options = {}) ⇒ Object
- #risk(options = {}) ⇒ Object
- #start_impersonation(options = {}) ⇒ Object
- #track(options = {}) ⇒ Object
- #tracked? ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
15 16 17 18 19 20 |
# File 'lib/castle/client.rb', line 15 def initialize( = {}) = Castle::Utils::DeepSymbolizeKeys.call( || {}) @do_not_track = .fetch(:do_not_track, false) @timestamp = .fetch(:timestamp) { Castle::Utils::GetTimestamp.call } @context = .fetch(:context) { {} } end |
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
12 13 14 |
# File 'lib/castle/client.rb', line 12 def context @context end |
Class Method Details
Instance Method Details
#authenticate(options = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/castle/client.rb', line 23 def authenticate( = {}) = Castle::Utils::DeepSymbolizeKeys.call( || {}) return generate_do_not_track_response([:user_id]) unless tracked? () new_context = Castle::Context::Merge.call(@context, [:context]) Castle::API::Authenticate.call(.merge(context: new_context, no_symbolize: true)) end |
#disable_tracking ⇒ Object
109 110 111 |
# File 'lib/castle/client.rb', line 109 def disable_tracking @do_not_track = true end |
#enable_tracking ⇒ Object
113 114 115 |
# File 'lib/castle/client.rb', line 113 def enable_tracking @do_not_track = false end |
#end_impersonation(options = {}) ⇒ Object
99 100 101 102 103 104 105 106 107 |
# File 'lib/castle/client.rb', line 99 def end_impersonation( = {}) = Castle::Utils::DeepSymbolizeKeys.call( || {}) () new_context = Castle::Context::Merge.call(@context, [:context]) Castle::API::EndImpersonation.call(.merge(context: new_context, no_symbolize: true)) end |
#filter(options = {}) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/castle/client.rb', line 49 def filter( = {}) = Castle::Utils::DeepSymbolizeKeys.call( || {}) return generate_do_not_track_response([:user][:id]) unless tracked? () new_context = Castle::Context::Merge.call(@context, [:context]) Castle::API::Filter.call(.merge(context: new_context, no_symbolize: true)) end |
#log(options = {}) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/castle/client.rb', line 75 def log( = {}) = Castle::Utils::DeepSymbolizeKeys.call( || {}) return generate_do_not_track_response([:user][:id]) unless tracked? () new_context = Castle::Context::Merge.call(@context, [:context]) Castle::API::Log.call(.merge(context: new_context, no_symbolize: true)) end |
#risk(options = {}) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/castle/client.rb', line 62 def risk( = {}) = Castle::Utils::DeepSymbolizeKeys.call( || {}) return generate_do_not_track_response([:user][:id]) unless tracked? () new_context = Castle::Context::Merge.call(@context, [:context]) Castle::API::Risk.call(.merge(context: new_context, no_symbolize: true)) end |
#start_impersonation(options = {}) ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/castle/client.rb', line 88 def start_impersonation( = {}) = Castle::Utils::DeepSymbolizeKeys.call( || {}) () new_context = Castle::Context::Merge.call(@context, [:context]) Castle::API::StartImpersonation.call(.merge(context: new_context, no_symbolize: true)) end |
#track(options = {}) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/castle/client.rb', line 36 def track( = {}) = Castle::Utils::DeepSymbolizeKeys.call( || {}) return unless tracked? () new_context = Castle::Context::Merge.call(@context, [:context]) Castle::API::Track.call(.merge(context: new_context, no_symbolize: true)) end |
#tracked? ⇒ Boolean
118 119 120 |
# File 'lib/castle/client.rb', line 118 def tracked? !@do_not_track end |