Class: Castle::Client
Overview
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#create_list, #delete_list, #get_all_lists, #get_list, #query_lists, #update_list
#archive_list_item, #count_list_items, #create_list_item, #get_list_item, #query_list_items, #unarchive_list_item, #update_list_item
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
18
19
20
21
22
23
|
# File 'lib/castle/client.rb', line 18
def initialize(options = {})
options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
@do_not_track = options.fetch(:do_not_track, false)
@timestamp = options.fetch(:timestamp) { Castle::Utils::GetTimestamp.call }
@context = options.fetch(:context) { {} }
end
|
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
15
16
17
|
# File 'lib/castle/client.rb', line 15
def context
@context
end
|
Class Method Details
.from_request(request, options = {}) ⇒ Object
10
11
12
|
# File 'lib/castle/client.rb', line 10
def from_request(request, options = {})
new(options.merge(context: Castle::Context::Prepare.call(request, options)))
end
|
Instance Method Details
#authenticate(options = {}) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/castle/client.rb', line 26
def authenticate(options = {})
options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
return generate_do_not_track_response(options[:user_id]) unless tracked?
add_timestamp_if_necessary(options)
new_context = Castle::Context::Merge.call(@context, options[:context])
Castle::API::Authenticate.call(options.merge(context: new_context, no_symbolize: true))
end
|
#disable_tracking ⇒ Object
112
113
114
|
# File 'lib/castle/client.rb', line 112
def disable_tracking
@do_not_track = true
end
|
#enable_tracking ⇒ Object
116
117
118
|
# File 'lib/castle/client.rb', line 116
def enable_tracking
@do_not_track = false
end
|
#end_impersonation(options = {}) ⇒ Object
#filter(options = {}) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/castle/client.rb', line 52
def filter(options = {})
options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
return generate_do_not_track_response(options[:user][:id]) unless tracked?
add_timestamp_if_necessary(options)
new_context = Castle::Context::Merge.call(@context, options[:context])
Castle::API::Filter.call(options.merge(context: new_context, no_symbolize: true))
end
|
#log(options = {}) ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/castle/client.rb', line 78
def log(options = {})
options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
return generate_do_not_track_response(options[:user][:id]) unless tracked?
add_timestamp_if_necessary(options)
new_context = Castle::Context::Merge.call(@context, options[:context])
Castle::API::Log.call(options.merge(context: new_context, no_symbolize: true))
end
|
#risk(options = {}) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/castle/client.rb', line 65
def risk(options = {})
options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
return generate_do_not_track_response(options[:user][:id]) unless tracked?
add_timestamp_if_necessary(options)
new_context = Castle::Context::Merge.call(@context, options[:context])
Castle::API::Risk.call(options.merge(context: new_context, no_symbolize: true))
end
|
#start_impersonation(options = {}) ⇒ Object
#track(options = {}) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/castle/client.rb', line 39
def track(options = {})
options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
return unless tracked?
add_timestamp_if_necessary(options)
new_context = Castle::Context::Merge.call(@context, options[:context])
Castle::API::Track.call(options.merge(context: new_context, no_symbolize: true))
end
|
#tracked? ⇒ Boolean
121
122
123
|
# File 'lib/castle/client.rb', line 121
def tracked?
!@do_not_track
end
|