Class: Loggr::LogClient
- Inherits:
-
Object
- Object
- Loggr::LogClient
- Defined in:
- lib/loggr-rb/logclient.rb
Class Method Summary collapse
Instance Method Summary collapse
- #call_remote(host, path, params) ⇒ Object
- #create_params(e) ⇒ Object
- #post(e) ⇒ Object
- #track_user(username, page = nil) ⇒ Object
Class Method Details
.post(e, async) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/loggr-rb/logclient.rb', line 9 def self.post(e,async) if async LogEventJob.new.async.perform(e) else LogClient.new.post(e) end end |
.track_user(username, page = nil, async = true) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/loggr-rb/logclient.rb', line 22 def self.track_user(username,page = nil, async = true) if async TrackUserJob.new.async.perform(username,page) else LogClient.new.track_user(username,page) end end |
Instance Method Details
#call_remote(host, path, params) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/loggr-rb/logclient.rb', line 56 def call_remote(host, path, params) uri = URI("http://#{host}#{path}?#{URI.encode_www_form(params)}") req = Net::HTTP::Get.new(uri) req['Accept-Encoding'] = nil begin res = Net::HTTP.start(uri.host,uri.port) { |http| http.request(req) } rescue Exception => e Loggr.logger.error("Problem notifying Loggr about the event") Loggr.logger.error(e) end end |
#create_params(e) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/loggr-rb/logclient.rb', line 40 def create_params(e) apikey = ::Loggr::Config.api_key params = {"apikey" => apikey, "text" => e.text} params = params.merge({"link" => e.link}) if !e.link.nil? params = params.merge({"tags" => e.}) if !e..nil? params = params.merge({"source" => e.source}) if !e.source.nil? params = params.merge({"geo" => e.geo}) if !e.geo.nil? params = params.merge({"value" => e.value}) if !e.value.nil? if e.datatype == DataType::HTML params = params.merge({"data" => sprintf("@html\r\n%s", e.data)}) if !e.data.nil? else params = params.merge({"data" => e.data}) if !e.data.nil? end return params end |
#post(e) ⇒ Object
17 18 19 20 |
# File 'lib/loggr-rb/logclient.rb', line 17 def post(e) logkey = ::Loggr::Config.log_key call_remote("post.loggr.net", "/1/logs/#{logkey}/events", create_params(e)) end |
#track_user(username, page = nil) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/loggr-rb/logclient.rb', line 30 def track_user(username,page = nil) logkey = ::Loggr::Config.log_key call_remote("post.loggr.net", "/1/logs/#{logkey}/users",{ "apikey" => Loggr::Config.api_key, "username" => username, "page" => page }) end |