Module: ThisData
- Defined in:
- lib/this_data/verbs.rb,
lib/this_data.rb,
lib/this_data/client.rb,
lib/this_data/version.rb,
lib/this_data/configuration.rb,
lib/this_data/track_request.rb,
lib/generators/this_data/install_generator.rb
Overview
Include ThisData::TrackRequest in your ApplicationController to get a handy track method which looks at the request and current_user variables to generate an event.
If you include this in a non-ActionController instance, you must respond to ‘request` and `ThisData.configuration.user_method`
Defined Under Namespace
Modules: TrackRequest
Classes: Client, Configuration, InstallGenerator, Verbs
Constant Summary
collapse
- VERSION =
"0.1.6"
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.configuration ⇒ Object
22
23
24
|
# File 'lib/this_data.rb', line 22
def configuration
@configuration ||= ThisData::Configuration.new
end
|
Class Method Details
.default_configuration ⇒ Object
26
27
28
|
# File 'lib/this_data.rb', line 26
def default_configuration
configuration.defaults
end
|
.error(message, prefix: true) ⇒ Object
65
66
67
|
# File 'lib/this_data.rb', line 65
def error(message, prefix: true)
log(message, level: 'error', prefix: prefix)
end
|
.log(message, level: 'info', prefix: true) ⇒ Object
56
57
58
59
60
61
|
# File 'lib/this_data.rb', line 56
def log(message, level: 'info', prefix: true)
if prefix
message = "[ThisData] " + message.to_s
end
configuration.logger.send(level, message) if configuration.logger
end
|
.setup {|configuration| ... } ⇒ Object
18
19
20
|
# File 'lib/this_data.rb', line 18
def setup
yield(configuration)
end
|
.track(event) ⇒ Object
Tracks an event. If ‘ThisData.configuration.async` is true, this action will be performed in a new Thread. Event must be a Hash When performed asynchronously, true is always returned. Otherwise an HTTPRequest is returned.
35
36
37
38
39
40
41
|
# File 'lib/this_data.rb', line 35
def track(event)
if ThisData.configuration.async
track_async(event)
else
track_with_response(event)
end
end
|
.track_login(ip: '', user: {}, user_agent: nil) ⇒ Object
A helper method to track a log-in event. Validates that the minimum required data is present.
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/this_data.rb', line 45
def track_login(ip: '', user: {}, user_agent: nil)
raise ArgumentError, "IP Address is required" unless ip.length
raise ArgumentError, "User needs ID value" unless user[:id].to_s.length
track({
verb: ThisData::Verbs::LOG_IN,
ip: ip,
user_agent: user_agent,
user: user
})
end
|
.warn(message, prefix: true) ⇒ Object
62
63
64
|
# File 'lib/this_data.rb', line 62
def warn(message, prefix: true)
log(message, level: 'warn', prefix: prefix)
end
|