loggly 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ require "autotest/bundler"
data/.rspec ADDED
File without changes
data/Gemfile CHANGED
@@ -1,13 +1,16 @@
1
1
  source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
5
2
 
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
3
+ gem 'rest-client', ">=1.6"
4
+ gem 'resque', ">=1.1"
5
+
6
+ gem 'json'
7
+
8
8
  group :development do
9
+ gem 'resque_unit'
9
10
  gem "shoulda", ">= 0"
10
11
  gem "bundler", "~> 1.0.0"
11
12
  gem "jeweler", "~> 1.6.4"
12
13
  gem "rcov", ">= 0"
14
+ gem "rspec"
15
+ gem "fakeweb"
13
16
  end
@@ -1,20 +1,61 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
+ diff-lcs (1.1.3)
5
+ fakeweb (1.3.0)
4
6
  git (1.2.5)
5
7
  jeweler (1.6.4)
6
8
  bundler (~> 1.0)
7
9
  git (>= 1.2.5)
8
10
  rake
11
+ json (1.6.1)
12
+ mime-types (1.17.2)
13
+ multi_json (1.0.3)
14
+ rack (1.3.5)
15
+ rack-protection (1.1.4)
16
+ rack
9
17
  rake (0.9.2)
10
18
  rcov (0.9.9)
19
+ redis (2.2.2)
20
+ redis-namespace (1.0.3)
21
+ redis (< 3.0.0)
22
+ resque (1.19.0)
23
+ multi_json (~> 1.0)
24
+ redis-namespace (~> 1.0.2)
25
+ sinatra (>= 0.9.2)
26
+ vegas (~> 0.1.2)
27
+ resque_unit (0.4.1)
28
+ json (>= 1.4.6)
29
+ rest-client (1.6.7)
30
+ mime-types (>= 1.16)
31
+ rspec (2.7.0)
32
+ rspec-core (~> 2.7.0)
33
+ rspec-expectations (~> 2.7.0)
34
+ rspec-mocks (~> 2.7.0)
35
+ rspec-core (2.7.1)
36
+ rspec-expectations (2.7.0)
37
+ diff-lcs (~> 1.1.2)
38
+ rspec-mocks (2.7.0)
11
39
  shoulda (2.11.3)
40
+ sinatra (1.3.1)
41
+ rack (~> 1.3, >= 1.3.4)
42
+ rack-protection (~> 1.1, >= 1.1.2)
43
+ tilt (~> 1.3, >= 1.3.3)
44
+ tilt (1.3.3)
45
+ vegas (0.1.8)
46
+ rack (>= 1.0.0)
12
47
 
13
48
  PLATFORMS
14
49
  ruby
15
50
 
16
51
  DEPENDENCIES
17
52
  bundler (~> 1.0.0)
53
+ fakeweb
18
54
  jeweler (~> 1.6.4)
55
+ json
19
56
  rcov
57
+ resque (>= 1.1)
58
+ resque_unit
59
+ rest-client (>= 1.6)
60
+ rspec
20
61
  shoulda
@@ -1,6 +1,35 @@
1
1
  = loggly
2
2
 
3
- Description goes here.
3
+ It sends messages to the Loggly API. We do this using resque or without it.
4
+
5
+ == INSTALL
6
+
7
+ gem install loggly
8
+
9
+ == USAGE
10
+
11
+ You must sublcass from Loggly and add a class method call token that return the input you get from Loggly
12
+
13
+ === For example:
14
+
15
+ class TicketLoggly < Loggly
16
+ def self.token
17
+ 'token_you_get_from_loggly'
18
+ end
19
+ end
20
+
21
+
22
+ TicketLoggly.record("This the message")
23
+
24
+ You can also pass in an optional parameter like:
25
+
26
+ TicketLoggly.record("This is cool", Time.now.to_s)
27
+
28
+
29
+ If you have resque installed, you can send messages using it by doing:
30
+
31
+ TicketLogglt.async_record("This will be send using resque")
32
+
4
33
 
5
34
  == Contributing to loggly
6
35
 
data/Rakefile CHANGED
@@ -27,16 +27,16 @@ end
27
27
  Jeweler::RubygemsDotOrgTasks.new
28
28
 
29
29
  require 'rake/testtask'
30
- Rake::TestTask.new(:test) do |test|
31
- test.libs << 'lib' << 'test'
32
- test.pattern = 'test/**/test_*.rb'
33
- test.verbose = true
30
+ Rake::TestTask.new(:test) do |ttestest|
31
+ # test.libs << 'lib' << 'spec'
32
+ # test.pattern = 'spec/**/*_spec.rb'
33
+ # test.verbose = true
34
34
  end
35
35
 
36
36
  require 'rcov/rcovtask'
37
37
  Rcov::RcovTask.new do |test|
38
- test.libs << 'test'
39
- test.pattern = 'test/**/test_*.rb'
38
+ test.libs << 'spec'
39
+ test.pattern = 'spec/**/*_spec.rb'
40
40
  test.verbose = true
41
41
  test.rcov_opts << '--exclude "gems/*"'
42
42
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.1.0
@@ -0,0 +1,96 @@
1
+ require 'restclient'
2
+
3
+
4
+ #
5
+ # We use resque to send messages to loggly
6
+ #
7
+
8
+ class LogglyResque
9
+
10
+ @queue = :loggly
11
+
12
+ def self.perform(klass,message, time=nil)
13
+ klass.send(:send_to_loggly, message, time)
14
+ end
15
+ end
16
+
17
+ #
18
+ # THIS CLASS AS AN ABSTRACT BASE CLASS TO SEND EVENTS TO LOGGLY.COM
19
+ # events on this content are anything that happends in the app. Not an event were people to to have fun
20
+ #
21
+ class Loggly
22
+
23
+ #
24
+ # THIS IS THE ENDPOINT URL FOR LOGGLY
25
+ #
26
+ @@endpoint = 'http://logs.loggly.com/inputs/'
27
+
28
+ #
29
+ # Contructing a full URL. It has the endpoint + the token we generate at:
30
+ # https://venuedriver.loggly.com/inputs
31
+ #
32
+ def self.url
33
+ @@endpoint + self.token
34
+ end
35
+
36
+ def self.token
37
+ # Add the token in the subclasses.
38
+ # This method must return a string
39
+ # The idea is to have a subclass for each of the inputs that we create in loggly
40
+ # URL to get the token from: https://venuedriver.loggly.com/inputs
41
+ end
42
+
43
+
44
+ # Public
45
+ # This method sends a message to the Loggly API.
46
+ #
47
+ #
48
+ # BEAWARE: That Loggle.new is an abstract class and lacks the token to authenticate with loggly.
49
+ # You should subclass loggly and add a method named token that returns a string with the appropiate token.
50
+ # SEE the method token on this class to know more about it
51
+ #
52
+ # EXAMPLES
53
+ # USAGE: Let's say you have a class named TicketLoggly that subclasses Loggly.
54
+ #
55
+ # TicketLoggly.record("This works")
56
+ #
57
+ # You can also send a timestamp. For example:
58
+ #
59
+ # TicketLoggly.record("With a Timestamp", Time.now)
60
+ #
61
+ # Or you can get creative like:
62
+ #
63
+ # TicketLoggly.record(Event.last.attributes.to_json ,Time.now )
64
+
65
+ def self.record(message, time=nil)
66
+ self.send_to_loggly(message, time)
67
+ end
68
+
69
+ # Public
70
+ #
71
+ # This method behaves the same as record, but uses resque to send the message.
72
+ #
73
+ def self.async_record(message, time=nil)
74
+ begin
75
+ Resque.enqueue(LogglyResque, self.class, message, time)
76
+ rescue => e
77
+ puts e
78
+ puts "There was an error cueing loggly"
79
+ end
80
+ end
81
+
82
+
83
+ private
84
+
85
+ # Private
86
+ # We use this method internally to send messages to loggly.
87
+ # It is used by the Resque worker and by the record method.
88
+ def self.send_to_loggly(message, time=nil)
89
+ begin
90
+ RestClient.post(self.url, (message + " | Time : " + time.to_s))
91
+ rescue => e
92
+ puts e
93
+ puts "There was a problem making the HTTP call to Loggly"
94
+ end
95
+ end
96
+ end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{loggly}
8
- s.version = "0.0.0"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ivan Acosta-Rubio"]
@@ -17,7 +17,9 @@ Gem::Specification.new do |s|
17
17
  "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
+ ".autotest",
20
21
  ".document",
22
+ ".rspec",
21
23
  "Gemfile",
22
24
  "Gemfile.lock",
23
25
  "LICENSE.txt",
@@ -26,8 +28,7 @@ Gem::Specification.new do |s|
26
28
  "VERSION",
27
29
  "lib/loggly.rb",
28
30
  "loggly.gemspec",
29
- "test/helper.rb",
30
- "test/test_loggly.rb"
31
+ "spec/loggly_spec.rb"
31
32
  ]
32
33
  s.homepage = %q{http://github.com/ivanacostarubio/loggly}
33
34
  s.licenses = ["MIT"]
@@ -40,21 +41,39 @@ Gem::Specification.new do |s|
40
41
  s.specification_version = 3
41
42
 
42
43
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
44
+ s.add_runtime_dependency(%q<rest-client>, [">= 1.6"])
45
+ s.add_runtime_dependency(%q<resque>, [">= 1.1"])
46
+ s.add_runtime_dependency(%q<json>, [">= 0"])
47
+ s.add_development_dependency(%q<resque_unit>, [">= 0"])
43
48
  s.add_development_dependency(%q<shoulda>, [">= 0"])
44
49
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
45
50
  s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
46
51
  s.add_development_dependency(%q<rcov>, [">= 0"])
52
+ s.add_development_dependency(%q<rspec>, [">= 0"])
53
+ s.add_development_dependency(%q<fakeweb>, [">= 0"])
47
54
  else
55
+ s.add_dependency(%q<rest-client>, [">= 1.6"])
56
+ s.add_dependency(%q<resque>, [">= 1.1"])
57
+ s.add_dependency(%q<json>, [">= 0"])
58
+ s.add_dependency(%q<resque_unit>, [">= 0"])
48
59
  s.add_dependency(%q<shoulda>, [">= 0"])
49
60
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
50
61
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
51
62
  s.add_dependency(%q<rcov>, [">= 0"])
63
+ s.add_dependency(%q<rspec>, [">= 0"])
64
+ s.add_dependency(%q<fakeweb>, [">= 0"])
52
65
  end
53
66
  else
67
+ s.add_dependency(%q<rest-client>, [">= 1.6"])
68
+ s.add_dependency(%q<resque>, [">= 1.1"])
69
+ s.add_dependency(%q<json>, [">= 0"])
70
+ s.add_dependency(%q<resque_unit>, [">= 0"])
54
71
  s.add_dependency(%q<shoulda>, [">= 0"])
55
72
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
56
73
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
57
74
  s.add_dependency(%q<rcov>, [">= 0"])
75
+ s.add_dependency(%q<rspec>, [">= 0"])
76
+ s.add_dependency(%q<fakeweb>, [">= 0"])
58
77
  end
59
78
  end
60
79
 
@@ -0,0 +1,43 @@
1
+ require Dir.pwd + '/lib/loggly'
2
+
3
+ require 'resque'
4
+ require 'fakeweb'
5
+ require 'rspec'
6
+ require 'resque_unit'
7
+
8
+ #Resque.inline = true
9
+
10
+ class TestLoggly < Loggly
11
+ def self.token
12
+ 'test'
13
+ end
14
+ end
15
+
16
+ ok_response = "{\"response\":\"ok\"}"
17
+ bad_response = "There was a problem making the HTTP call to Loggly"
18
+
19
+ def mock_url_with(url, response)
20
+ FakeWeb.register_uri(:post, url, :body => response)
21
+ end
22
+
23
+ mock_url_with("http://logs.loggly.com/inputs/test", ok_response)
24
+
25
+ describe Loggly do
26
+
27
+ include ResqueUnit::Assertions
28
+ include Test::Unit::Assertions
29
+
30
+ it "sends the message to loggly" do
31
+ TestLoggly.record("This is a test").should == ok_response
32
+ end
33
+
34
+ it "can send an optional parameters" do
35
+ TestLoggly.record("Our message", Time.now.to_s).should == ok_response
36
+ end
37
+
38
+ it "can send the message async" do
39
+ TestLoggly.async_record("sk")
40
+ assert_queued(LogglyResque)
41
+ end
42
+
43
+ end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
+ - 1
7
8
  - 0
8
- - 0
9
- version: 0.0.0
9
+ version: 0.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ivan Acosta-Rubio
@@ -17,23 +17,73 @@ cert_chain: []
17
17
  date: 2011-11-19 00:00:00 -06:00
18
18
  default_executable:
19
19
  dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ prerelease: false
22
+ type: :runtime
23
+ name: rest-client
24
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 1
30
+ - 6
31
+ version: "1.6"
32
+ requirement: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ prerelease: false
35
+ type: :runtime
36
+ name: resque
37
+ version_requirements: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 1
44
+ version: "1.1"
45
+ requirement: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ prerelease: false
48
+ type: :runtime
49
+ name: json
50
+ version_requirements: &id003 !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ requirement: *id003
58
+ - !ruby/object:Gem::Dependency
59
+ prerelease: false
60
+ type: :development
61
+ name: resque_unit
62
+ version_requirements: &id004 !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ segments:
67
+ - 0
68
+ version: "0"
69
+ requirement: *id004
20
70
  - !ruby/object:Gem::Dependency
21
71
  prerelease: false
22
72
  type: :development
23
73
  name: shoulda
24
- version_requirements: &id001 !ruby/object:Gem::Requirement
74
+ version_requirements: &id005 !ruby/object:Gem::Requirement
25
75
  requirements:
26
76
  - - ">="
27
77
  - !ruby/object:Gem::Version
28
78
  segments:
29
79
  - 0
30
80
  version: "0"
31
- requirement: *id001
81
+ requirement: *id005
32
82
  - !ruby/object:Gem::Dependency
33
83
  prerelease: false
34
84
  type: :development
35
85
  name: bundler
36
- version_requirements: &id002 !ruby/object:Gem::Requirement
86
+ version_requirements: &id006 !ruby/object:Gem::Requirement
37
87
  requirements:
38
88
  - - ~>
39
89
  - !ruby/object:Gem::Version
@@ -42,12 +92,12 @@ dependencies:
42
92
  - 0
43
93
  - 0
44
94
  version: 1.0.0
45
- requirement: *id002
95
+ requirement: *id006
46
96
  - !ruby/object:Gem::Dependency
47
97
  prerelease: false
48
98
  type: :development
49
99
  name: jeweler
50
- version_requirements: &id003 !ruby/object:Gem::Requirement
100
+ version_requirements: &id007 !ruby/object:Gem::Requirement
51
101
  requirements:
52
102
  - - ~>
53
103
  - !ruby/object:Gem::Version
@@ -56,19 +106,43 @@ dependencies:
56
106
  - 6
57
107
  - 4
58
108
  version: 1.6.4
59
- requirement: *id003
109
+ requirement: *id007
60
110
  - !ruby/object:Gem::Dependency
61
111
  prerelease: false
62
112
  type: :development
63
113
  name: rcov
64
- version_requirements: &id004 !ruby/object:Gem::Requirement
114
+ version_requirements: &id008 !ruby/object:Gem::Requirement
65
115
  requirements:
66
116
  - - ">="
67
117
  - !ruby/object:Gem::Version
68
118
  segments:
69
119
  - 0
70
120
  version: "0"
71
- requirement: *id004
121
+ requirement: *id008
122
+ - !ruby/object:Gem::Dependency
123
+ prerelease: false
124
+ type: :development
125
+ name: rspec
126
+ version_requirements: &id009 !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ segments:
131
+ - 0
132
+ version: "0"
133
+ requirement: *id009
134
+ - !ruby/object:Gem::Dependency
135
+ prerelease: false
136
+ type: :development
137
+ name: fakeweb
138
+ version_requirements: &id010 !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ segments:
143
+ - 0
144
+ version: "0"
145
+ requirement: *id010
72
146
  description: " We send messages to Loggly using resque or not"
73
147
  email: ivan@bakedweb.net
74
148
  executables: []
@@ -79,7 +153,9 @@ extra_rdoc_files:
79
153
  - LICENSE.txt
80
154
  - README.rdoc
81
155
  files:
156
+ - .autotest
82
157
  - .document
158
+ - .rspec
83
159
  - Gemfile
84
160
  - Gemfile.lock
85
161
  - LICENSE.txt
@@ -88,8 +164,7 @@ files:
88
164
  - VERSION
89
165
  - lib/loggly.rb
90
166
  - loggly.gemspec
91
- - test/helper.rb
92
- - test/test_loggly.rb
167
+ - spec/loggly_spec.rb
93
168
  has_rdoc: true
94
169
  homepage: http://github.com/ivanacostarubio/loggly
95
170
  licenses:
@@ -1,18 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
10
- require 'test/unit'
11
- require 'shoulda'
12
-
13
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
- $LOAD_PATH.unshift(File.dirname(__FILE__))
15
- require 'loggly'
16
-
17
- class Test::Unit::TestCase
18
- end
@@ -1,7 +0,0 @@
1
- require 'helper'
2
-
3
- class TestLoggly < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
7
- end