Module: WhenAUser
- Defined in:
- lib/whenauser.rb,
lib/whenauser/helpers.rb,
lib/whenauser/version.rb,
lib/whenauser/pageviews.rb,
lib/whenauser/exceptions.rb,
lib/whenauser/memory_queue.rb,
lib/whenauser/girl_friday_queue.rb
Defined Under Namespace
Modules: Helpers
Classes: Exceptions, GirlFridayQueue, MemoryQueue, Pageviews, Rack
Constant Summary
collapse
- VERSION =
'0.7.1'
Class Method Summary
collapse
Class Method Details
.current_user(env) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/whenauser.rb', line 41
def self.current_user(env)
if controller = env['action_controller.instance']
if current_user = controller.instance_variable_get('@current_user') || controller.instance_eval('current_user')
[:login, :username, :email, :id].each do |field|
return current_user.send(field) if current_user.respond_to?(field)
end
end
end
nil
rescue
nil
end
|
.default_ignored_crawlers ⇒ Object
16
17
18
|
# File 'lib/whenauser.rb', line 16
def self.default_ignored_crawlers
%w(Baidu Gigabot Googlebot libwww-perl lwp-trivial msnbot SiteUptime Slurp WordPress ZIBB ZyBorg Yandex Jyxobot Huaweisymantecspider ApptusBot NewRelicPinger)
end
|
.flush(env = {}) ⇒ Object
24
25
26
27
28
29
|
# File 'lib/whenauser.rb', line 24
def self.flush(env={})
return if (events = WhenAUser.buffer).empty?
WhenAUser.buffer = []
WhenAUser.queue.push(:payload => events.map {|event| WhenAUser.prepare_event(event, env)})
end
|
.post_payload_to_token(payload, token) ⇒ Object
31
32
33
34
35
36
37
38
39
|
# File 'lib/whenauser.rb', line 31
def self.post_payload_to_token(payload, token)
uri = URI(WhenAUser.webhook_url + token)
req = Net::HTTP::Post.new(uri.path)
req.body = payload.to_json
req.content_type = 'application/json'
Net::HTTP.start(uri.host, uri.port) do |http|
http.request(req)
end
end
|
.send_event(event) ⇒ Object
20
21
22
|
# File 'lib/whenauser.rb', line 20
def self.send_event(event)
buffer << event
end
|