loggr-rb 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 98e339fe00cf34424a665fe0250612f6509e02ce
4
+ data.tar.gz: 8e6c552788838fafa3be7e26f33551e5fae40fca
5
+ SHA512:
6
+ metadata.gz: 8053f0b79832a8041910dab912b67bf6605fac93cc85827c2723274633173f905a295945271e21a937a37555f5d4d33d28749722b4566f7dc9eb0883a6a847a2
7
+ data.tar.gz: aad8198258aa69fce8573db0f7cd92b28982fc7ef585e83488b725fdc0f4e6880793c0a525d35de76648134efd7bae1dc28ed4dd8244517cc45794e32774a4b9
@@ -50,16 +50,15 @@ module Loggr
50
50
  class FluentEvent
51
51
 
52
52
  def initialize(callback=nil)
53
- @callback = callback
53
+ @callback = callback
54
54
  @event = Event.new()
55
55
  end
56
56
 
57
57
  def post(async=true)
58
- if !@callback.nil?
59
- @callback.call(self)
60
- end
61
- client = LogClient.new()
62
- client.post(@event, async)
58
+ if !@callback.nil?
59
+ @callback.call(self)
60
+ end
61
+ LogClient.post(@event,async)
63
62
  end
64
63
 
65
64
  def text(text)
@@ -4,7 +4,7 @@ module Loggr
4
4
  end
5
5
 
6
6
  def self.test
7
- Loggr::Events.create().text("Test event").tags("test").source("loggr-rb-#{Loggr::VERSION}").post()
7
+ Loggr::Events.create().text("Test event").tags("test").source("loggr-rb-#{Loggr::VERSION}").post(false)
8
8
  puts "Test Event sent. Please login to http://loggr.net to see it!"
9
9
  end
10
10
  end
@@ -1,63 +1,91 @@
1
+ require 'sucker_punch'
1
2
  require 'loggr-rb/http'
2
3
  require 'uri'
3
4
 
4
5
  module Loggr
6
+
5
7
  class LogClient
6
- def post(e, async=true)
8
+
9
+ def self.post(e,async)
10
+ if async
11
+ LogEventJob.new.async.perform(e)
12
+ else
13
+ LogClient.new.post(e)
14
+ end
15
+ end
16
+
17
+ def post(e)
7
18
  logkey = ::Loggr::Config.log_key
8
- if async == true
9
- call_remote_async("post.loggr.net", "/1/logs/#{logkey}/events", create_params(e))
10
- else
11
- call_remote("post.loggr.net", "/1/logs/#{logkey}/events", create_params(e))
19
+ call_remote("post.loggr.net", "/1/logs/#{logkey}/events", create_params(e))
20
+ end
21
+
22
+ def self.track_user(username,page = nil, async = true)
23
+ if async
24
+ TrackUserJob.new.async.perform(username,page)
25
+ else
26
+ LogClient.new.track_user(username,page)
12
27
  end
13
28
  end
14
29
 
15
- def create_params(e)
30
+ def track_user(username,page = nil)
31
+ logkey = ::Loggr::Config.log_key
32
+ call_remote("post.loggr.net", "/1/logs/#{logkey}/users",{
33
+ "apikey" => Loggr::Config.api_key,
34
+ "username" => username,
35
+ "page" => page
36
+ })
37
+ end
38
+
39
+
40
+ def create_params(e)
16
41
  apikey = ::Loggr::Config.api_key
17
- params = {"apikey" => apikey, "text" => e.text}
18
- params = params.merge({"link" => e.link}) if !e.link.nil?
19
- params = params.merge({"tags" => e.tags}) if !e.tags.nil?
20
- params = params.merge({"source" => e.source}) if !e.source.nil?
21
- params = params.merge({"geo" => e.geo}) if !e.geo.nil?
22
- params = params.merge({"value" => e.value}) if !e.value.nil?
23
- if e.datatype == DataType::HTML
24
- params = params.merge({"data" => sprintf("@html\r\n%s", e.data)}) if !e.data.nil?
25
- else
26
- params = params.merge({"data" => e.data}) if !e.data.nil?
27
- end
28
- return params
29
- end
42
+ params = {"apikey" => apikey, "text" => e.text}
43
+ params = params.merge({"link" => e.link}) if !e.link.nil?
44
+ params = params.merge({"tags" => e.tags}) if !e.tags.nil?
45
+ params = params.merge({"source" => e.source}) if !e.source.nil?
46
+ params = params.merge({"geo" => e.geo}) if !e.geo.nil?
47
+ params = params.merge({"value" => e.value}) if !e.value.nil?
48
+ if e.datatype == DataType::HTML
49
+ params = params.merge({"data" => sprintf("@html\r\n%s", e.data)}) if !e.data.nil?
50
+ else
51
+ params = params.merge({"data" => e.data}) if !e.data.nil?
52
+ end
53
+ return params
54
+ end
30
55
 
31
56
  def call_remote(host, path, params)
32
- http = Net::HTTP.new(host)
33
- req = Net::HTTP::Get.new(path)
34
- data = params.collect { |k, v| "#{k}=#{v}&" }.join
35
- http.start
57
+ uri = URI("http://#{host}#{path}?#{URI.encode_www_form(params)}")
58
+ req = Net::HTTP::Get.new(uri)
59
+ req['Accept-Encoding'] = nil
36
60
  begin
37
- http.request_async(req, data)
38
- res = http.read_response(req)
61
+ res = Net::HTTP.start(uri.host,uri.port) { |http|
62
+ http.request(req)
63
+ }
39
64
  rescue Exception => e
40
- Loggr.logger.error('Problem notifying Loggr about the event')
65
+ Loggr.logger.error("Problem notifying Loggr about the event")
41
66
  Loggr.logger.error(e)
42
- ensure
43
- http.finish
44
67
  end
45
- res.value # raise if error
46
68
  end
47
69
 
48
- def call_remote_async(host, path, params)
49
- http = Net::HTTP.new(host)
50
- req = Net::HTTP::Get.new(path)
51
- data = params.collect { |k, v| "#{k}=#{v}&" }.join
52
- http.start
53
- begin
54
- http.request_async(req, data)
55
- rescue Exception => e
56
- Loggr.logger.error('Problem notifying Loggr about the event')
57
- Loggr.logger.error(e)
58
- ensure
59
- http.finish
60
- end
70
+ end
71
+
72
+ class LogEventJob
73
+ include SuckerPunch::Job
74
+
75
+ def perform(event)
76
+ LogClient.new.post(event)
77
+ end
78
+
79
+ end
80
+
81
+ class TrackUserJob
82
+ include SuckerPunch::Job
83
+
84
+ def perform(username,page)
85
+ LogClient.new.track_user(username,page)
61
86
  end
87
+
62
88
  end
63
- end
89
+
90
+
91
+ end
@@ -1,3 +1,3 @@
1
1
  module Loggr
2
- VERSION = '1.0.6'
2
+ VERSION = '1.0.7'
3
3
  end
@@ -14,4 +14,5 @@ Gem::Specification.new do |gem|
14
14
  gem.executables << 'loggr'
15
15
  gem.requirements << ""
16
16
  gem.add_dependency 'rack'
17
+ gem.add_dependency 'sucker_punch'
17
18
  end
metadata CHANGED
@@ -1,93 +1,96 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: loggr-rb
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 0
8
- - 6
9
- version: 1.0.6
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.7
10
5
  platform: ruby
11
- authors:
6
+ authors:
12
7
  - Loggr.net
13
8
  autorequire:
14
9
  bindir: bin
15
10
  cert_chain: []
16
-
17
- date: 2011-07-25 00:00:00 -04:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
11
+ date: 2013-11-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
21
14
  name: rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
22
21
  prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- version: "0"
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sucker_punch
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
30
34
  type: :runtime
31
- version_requirements: *id001
32
- description: loggr-rb is the Ruby gem for communicating with http://loggr.net (hosted logging service).
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: loggr-rb is the Ruby gem for communicating with http://loggr.net (hosted
42
+ logging service).
33
43
  email: info@loggr.net
34
- executables:
44
+ executables:
35
45
  - loggr
36
46
  extensions: []
37
-
38
47
  extra_rdoc_files: []
39
-
40
- files:
41
- - lib/loggr-rb.rb
42
- - lib/loggr-rb/integration/tester.rb
43
- - lib/loggr-rb/integration/dj.rb
48
+ files:
49
+ - lib/loggr-rb/version.rb
50
+ - lib/loggr-rb/logfactory.rb
44
51
  - lib/loggr-rb/integration/rails.rb
45
- - lib/loggr-rb/integration/sinatra.rb
46
52
  - lib/loggr-rb/integration/rack_rails.rb
47
53
  - lib/loggr-rb/integration/rack.rb
48
- - lib/loggr-rb/config.rb
49
- - lib/loggr-rb/version.rb
50
- - lib/loggr-rb/logclient.rb
51
- - lib/loggr-rb/logfactory.rb
52
- - lib/loggr-rb/exceptiondata.rb
53
- - lib/loggr-rb/railtie.rb
54
+ - lib/loggr-rb/integration/sinatra.rb
55
+ - lib/loggr-rb/integration/dj.rb
56
+ - lib/loggr-rb/integration/tester.rb
57
+ - lib/loggr-rb/catcher.rb
54
58
  - lib/loggr-rb/events.rb
59
+ - lib/loggr-rb/exceptiondata.rb
55
60
  - lib/loggr-rb/http.rb
56
- - lib/loggr-rb/catcher.rb
61
+ - lib/loggr-rb/logclient.rb
62
+ - lib/loggr-rb/railtie.rb
63
+ - lib/loggr-rb/config.rb
64
+ - lib/loggr-rb.rb
57
65
  - lib/tasks/loggr_tasks.rake
58
66
  - rails/init.rb
59
- - init.rb
60
67
  - install.rb
68
+ - init.rb
61
69
  - loggr-rb.gemspec
62
- has_rdoc: true
70
+ - bin/loggr
63
71
  homepage: http://loggr.net/
64
72
  licenses: []
65
-
73
+ metadata: {}
66
74
  post_install_message:
67
75
  rdoc_options: []
68
-
69
- require_paths:
76
+ require_paths:
70
77
  - lib
71
- required_ruby_version: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- segments:
76
- - 0
77
- version: "0"
78
- required_rubygems_version: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- segments:
83
- - 0
84
- version: "0"
85
- requirements:
86
- - ""
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements:
89
+ - ''
87
90
  rubyforge_project:
88
- rubygems_version: 1.3.6
91
+ rubygems_version: 2.0.3
89
92
  signing_key:
90
- specification_version: 3
91
- summary: loggr.net is a hosted service for logging events in your Ruby/Rails/Rack apps
93
+ specification_version: 4
94
+ summary: loggr.net is a hosted service for logging events in your Ruby/Rails/Rack
95
+ apps
92
96
  test_files: []
93
-