ruby_loggly 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -9,19 +9,20 @@ rescue Bundler::BundlerError => e
9
9
  $stderr.puts "Run `bundle install` to install missing gems"
10
10
  exit e.status_code
11
11
  end
12
+ require 'rake/dsl_definition'
12
13
  require 'rake'
13
14
 
14
15
  require 'jeweler'
15
16
  Jeweler::Tasks.new do |gem|
16
17
  # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
18
  gem.name = "ruby_loggly"
18
- gem.homepage = "http://github.com/mitchel456/ruby_loggly"
19
+ gem.homepage = "http://github.com/LynchMarks/ruby_loggly"
19
20
  gem.license = "MIT"
20
21
  gem.summary = "Simple Ruby interface to Loggly"
21
22
  gem.description ="A simple Ruby interface to the Loggly API"
22
23
  gem.email = "mitchellryanj@gmail.com"
23
24
  gem.authors = ["Ryan Mitchell"]
24
- gem.version = "0.0.2"
25
+ gem.version = "0.0.3"
25
26
  # dependencies defined in Gemfile
26
27
  end
27
28
  Jeweler::RubygemsDotOrgTasks.new
data/lib/ruby_loggly.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'rest_client'
2
+ require 'json'
2
3
 
3
4
  class Loggly
4
-
5
5
  def initialize(options)
6
6
  @subdomain = options[:subdomain]
7
7
  @user = options[:user]
@@ -20,4 +20,45 @@ class Loggly
20
20
  yield response.to_str if block_given?
21
21
  end
22
22
 
23
+ def list_inputs
24
+ response = RestClient.get("https://#{@user}:#{@pass}@#{@subdomain}.loggly.com/api/inputs/")
25
+ response_array=JSON.parse(response.to_str)
26
+ yield response_array if block_given?
27
+ response_array
28
+ end
29
+ def get_input(options)
30
+ response = RestClient.get("https://#{@user}:#{@pass}@#{@subdomain}.loggly.com/api/inputs/#{options[:id]}")
31
+ input_hash=JSON.parse(response.to_str)
32
+ yield input_hash if block_given?
33
+ input_hash
34
+ end
35
+ def add_input(options)
36
+ response = RestClient.post("https://#{@user}:#{@pass}@#{@subdomain}.loggly.com/api/inputs/", :name=>options[:name],:description=> options[:description],:service=>options[:service])
37
+ response.code==201 ? true : false
38
+ end
39
+ def remove_input(options)
40
+ response = RestClient.delete("https://#{@user}:#{@pass}@#{@subdomain}.loggly.com/api/inputs/#{options[:id]}")
41
+ response.code==204 ? true : false
42
+ end
43
+ def list_devices
44
+ response = RestClient.get("https://#{@user}:#{@pass}@#{@subdomain}.loggly.com/api/devices/")
45
+ response_array=JSON.parse(response.to_str)
46
+ yield response_array if block_given?
47
+ response_array
48
+ end
49
+ def add_device(options)
50
+ response = RestClient.post("https://#{@user}:#{@pass}@#{@subdomain}.loggly.com/api/devices/",:ip=>options[:ip],:input_id=>options[:input_id])
51
+ response.code==201 ? true : false
52
+ end
53
+ def remove_device(options)
54
+ response = RestClient.delete("https://#{@user}:#{@pass}@#{@subdomain}.loggly.com/api/devices/#{options[:id]}")
55
+ response.code==204 ? true : false
56
+ end
57
+ def get_device(options)
58
+ response = RestClient.get("https://#{@user}:#{@pass}@#{@subdomain}.loggly.com/api/devices/#{options[:id]}")
59
+ device=nil
60
+ device_hash=JSON.parse(response.to_str)
61
+ yield device_hash if block_given?
62
+ device_hash
63
+ end
23
64
  end
data/ruby_loggly.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ruby_loggly}
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ryan Mitchell"]
12
- s.date = %q{2011-08-10}
12
+ s.date = %q{2011-12-13}
13
13
  s.description = %q{A simple Ruby interface to the Loggly API}
14
14
  s.email = %q{mitchellryanj@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -25,10 +25,12 @@ Gem::Specification.new do |s|
25
25
  "Rakefile",
26
26
  "lib/ruby_loggly.rb",
27
27
  "ruby_loggly.gemspec",
28
+ "spec/ruby_loggly_device_spec.rb",
29
+ "spec/ruby_loggly_input_spec.rb",
28
30
  "spec/ruby_loggly_spec.rb",
29
31
  "spec/spec_helper.rb"
30
32
  ]
31
- s.homepage = %q{http://github.com/mitchel456/ruby_loggly}
33
+ s.homepage = %q{http://github.com/LynchMarks/ruby_loggly}
32
34
  s.licenses = ["MIT"]
33
35
  s.require_paths = ["lib"]
34
36
  s.rubygems_version = %q{1.7.2}
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe Loggly do
4
+
5
+ before(:all) do
6
+ @test_subdomain = 'example'
7
+ @test_user = 'user'
8
+ @test_pass = 'pass'
9
+ @test_key = '123456'
10
+ @loggly = Loggly.new(
11
+ :subdomain => @test_subdomain,
12
+ :user => @test_user,
13
+ :pass => @test_pass,
14
+ :key => @test_key
15
+ )
16
+ end
17
+
18
+ describe "#device" do
19
+ describe "#list" do
20
+ it "should generate an appropriate RestClient GET" do
21
+ RestClient.should_receive(:get).with( "https://#{@test_user}:#{@test_pass}@#{@test_subdomain}.loggly.com/api/devices/" ).and_return(mock('response', :to_str=>"{}"))
22
+ @loggly.list_devices
23
+ end
24
+ it "should execute a callback when its provided" do
25
+ Kernel.should_receive(:print).with({})
26
+ RestClient.should_receive(:get).with( "https://#{@test_user}:#{@test_pass}@#{@test_subdomain}.loggly.com/api/devices/" ).and_return(mock('response', :to_str=>"{}"))
27
+ @loggly.list_devices{|data|Kernel.print data}
28
+ end
29
+ it "should return device data" do
30
+ RestClient.should_receive(:get).with( "https://#{@test_user}:#{@test_pass}@#{@test_subdomain}.loggly.com/api/devices/" ).and_return(mock('response', :to_str=>"{}"))
31
+ @loggly.list_devices.should == {}
32
+ end
33
+ end
34
+ describe "#get" do
35
+ it "should generate an appropriate RestClient GET" do
36
+ RestClient.should_receive(:get).with( "https://#{@test_user}:#{@test_pass}@#{@test_subdomain}.loggly.com/api/devices/1").and_return(mock('response', :to_str=>"{}"))
37
+ @loggly.get_device(:id=>1)
38
+ end
39
+ it "should execute a callback when its provided" do
40
+ Kernel.should_receive(:print).with({})
41
+ RestClient.should_receive(:get).with( "https://#{@test_user}:#{@test_pass}@#{@test_subdomain}.loggly.com/api/devices/1" ).and_return(mock('response', :to_str=>"{}"))
42
+ @loggly.get_device(:id=>1){|data|Kernel.print data}
43
+ end
44
+ it "should return data" do
45
+ RestClient.should_receive(:get).with( "https://#{@test_user}:#{@test_pass}@#{@test_subdomain}.loggly.com/api/devices/1" ).and_return(mock('response', :to_str=>"{}"))
46
+ @loggly.get_device(:id=>1).should == {}
47
+ end
48
+ end
49
+ describe "#add" do
50
+ it "should generate an appropriate RestClient POST" do
51
+ RestClient.should_receive(:post).with( "https://#{@test_user}:#{@test_pass}@#{@test_subdomain}.loggly.com/api/devices/",:ip=>'127.0.0.1',:input_id=>1).and_return(mock('response', :code=>201))
52
+ @loggly.add_device(:input_id=>1,:ip=>'127.0.0.1')
53
+ end
54
+ it "should return true for HTTP 201 requests" do
55
+ RestClient.should_receive(:post).with( "https://#{@test_user}:#{@test_pass}@#{@test_subdomain}.loggly.com/api/devices/",:ip=>'127.0.0.1',:input_id=>1).and_return(mock('response', :code=>201))
56
+ @loggly.add_device(:input_id=>1,:ip=>'127.0.0.1').should be_true
57
+ end
58
+ it "should return false for HTTP non 201 requests" do
59
+ RestClient.should_receive(:post).with( "https://#{@test_user}:#{@test_pass}@#{@test_subdomain}.loggly.com/api/devices/",:ip=>'127.0.0.1',:input_id=>1).and_return(mock('response', :code=>500))
60
+ @loggly.add_device(:input_id=>1,:ip=>'127.0.0.1').should be_false
61
+ end
62
+ end
63
+ describe "#remove" do
64
+ it "should generate an appropriate RestClient DELETE" do
65
+ RestClient.should_receive(:delete).with( "https://#{@test_user}:#{@test_pass}@#{@test_subdomain}.loggly.com/api/devices/1").and_return(mock('response', :code=>204))
66
+ @loggly.remove_device(:id=>1)
67
+ end
68
+ it "should return true for HTTP 204 calls" do
69
+ RestClient.should_receive(:delete).with( "https://#{@test_user}:#{@test_pass}@#{@test_subdomain}.loggly.com/api/devices/1").and_return(mock('response', :code=>204))
70
+ @loggly.remove_device(:id=>1).should be_true
71
+ end
72
+ it "should return true for HTTP non 204 calls" do
73
+ RestClient.should_receive(:delete).with( "https://#{@test_user}:#{@test_pass}@#{@test_subdomain}.loggly.com/api/devices/1").and_return(mock('response', :code=>400))
74
+ @loggly.remove_device(:id=>1).should be_false
75
+ end
76
+ end
77
+ end
78
+ end
79
+
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe Loggly do
4
+
5
+ before(:all) do
6
+ @test_subdomain = 'example'
7
+ @test_user = 'user'
8
+ @test_pass = 'pass'
9
+ @test_key = '123456'
10
+ @loggly = Loggly.new(
11
+ :subdomain => @test_subdomain,
12
+ :user => @test_user,
13
+ :pass => @test_pass,
14
+ :key => @test_key
15
+ )
16
+ end
17
+
18
+ describe "#input" do
19
+ describe "#list" do
20
+ it "should generate an appropriate RestClient GET" do
21
+ RestClient.should_receive(:get).with( "https://#{@test_user}:#{@test_pass}@#{@test_subdomain}.loggly.com/api/inputs/" ).and_return(mock('response', :to_str=>"{}"))
22
+ @loggly.list_inputs
23
+ end
24
+ it "should execute a callback when its provided" do
25
+ Kernel.should_receive(:print).with({})
26
+ RestClient.should_receive(:get).with( "https://#{@test_user}:#{@test_pass}@#{@test_subdomain}.loggly.com/api/inputs/" ).and_return(mock('response', :to_str=>"{}"))
27
+ @loggly.list_inputs{|data|Kernel.print data}
28
+ end
29
+ it "should return input data" do
30
+ RestClient.should_receive(:get).with( "https://#{@test_user}:#{@test_pass}@#{@test_subdomain}.loggly.com/api/inputs/" ).and_return(mock('response', :to_str=>"{}"))
31
+ @loggly.list_inputs.should == {}
32
+ end
33
+ end
34
+ describe "#get" do
35
+ it "should generate an appropriate RestClient GET" do
36
+ RestClient.should_receive(:get).with( "https://#{@test_user}:#{@test_pass}@#{@test_subdomain}.loggly.com/api/inputs/1").and_return(mock('response', :to_str=>"{}"))
37
+ @loggly.get_input(:id=>1)
38
+ end
39
+ it "should execute a callback when its provided" do
40
+ Kernel.should_receive(:print).with({})
41
+ RestClient.should_receive(:get).with( "https://#{@test_user}:#{@test_pass}@#{@test_subdomain}.loggly.com/api/inputs/1" ).and_return(mock('response', :to_str=>"{}"))
42
+ @loggly.get_input(:id=>1){|data|Kernel.print data}
43
+ end
44
+ it "should return data" do
45
+ RestClient.should_receive(:get).with( "https://#{@test_user}:#{@test_pass}@#{@test_subdomain}.loggly.com/api/inputs/1" ).and_return(mock('response', :to_str=>"{}"))
46
+ @loggly.get_input(:id=>1).should == {}
47
+ end
48
+ describe "#add" do
49
+ it "should generate an appropriate RestClient POST" do
50
+ RestClient.should_receive(:post).with( "https://#{@test_user}:#{@test_pass}@#{@test_subdomain}.loggly.com/api/inputs/",:name=>'test',:description=>'desc',:service=>'ser').and_return(mock('response', :code=>201))
51
+ @loggly.add_input(:name=>'test',:description=>'desc',:service=>'ser')
52
+ end
53
+ it "should return true for HTTP 201 requests" do
54
+ RestClient.should_receive(:post).with( "https://#{@test_user}:#{@test_pass}@#{@test_subdomain}.loggly.com/api/inputs/",:name=>'test',:description=>'desc',:service=>'ser').and_return(mock('response', :code=>201))
55
+ @loggly.add_input(:name=>'test',:description=>'desc',:service=>'ser').should be_true
56
+ end
57
+ it "should return false for HTTP non 201 requests" do
58
+ RestClient.should_receive(:post).with( "https://#{@test_user}:#{@test_pass}@#{@test_subdomain}.loggly.com/api/inputs/",:name=>'test',:description=>'desc',:service=>'ser').and_return(mock('response', :code=>500))
59
+ @loggly.add_input(:name=>'test',:description=>'desc',:service=>'ser').should be_false
60
+ end
61
+ end
62
+ describe "#remove" do
63
+ it "should generate an appropriate RestClient DELETE" do
64
+ RestClient.should_receive(:delete).with( "https://#{@test_user}:#{@test_pass}@#{@test_subdomain}.loggly.com/api/inputs/1").and_return(mock('response', :code=>204))
65
+ @loggly.remove_input(:id=>1)
66
+ end
67
+ it "should return true for HTTP 204 calls" do
68
+ RestClient.should_receive(:delete).with( "https://#{@test_user}:#{@test_pass}@#{@test_subdomain}.loggly.com/api/inputs/1").and_return(mock('response', :code=>204))
69
+ @loggly.remove_input(:id=>1).should be_true
70
+ end
71
+ it "should return true for HTTP non 204 calls" do
72
+ RestClient.should_receive(:delete).with( "https://#{@test_user}:#{@test_pass}@#{@test_subdomain}.loggly.com/api/inputs/1").and_return(mock('response', :code=>400))
73
+ @loggly.remove_input(:id=>1).should be_false
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+
@@ -16,12 +16,6 @@ describe Loggly do
16
16
  end
17
17
 
18
18
  describe "#search" do
19
-
20
- before(:each) do
21
- RestClient.stub!(:get)
22
- Kernel.stub!(:print)
23
- end
24
-
25
19
  it "should generate an appropriate RestClient GET" do
26
20
 
27
21
  search_string = "search string"
@@ -45,10 +39,6 @@ describe Loggly do
45
39
  end
46
40
 
47
41
  describe "#log" do
48
-
49
- before(:each) do
50
- RestClient.stub!(:post)
51
- end
52
42
 
53
43
  it "should generate an appropriate RestClient POST with a raw payload" do
54
44
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_loggly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-10 00:00:00.000000000Z
12
+ date: 2011-12-13 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
16
- requirement: &26754528 !ruby/object:Gem::Requirement
16
+ requirement: &27185160 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.6.3
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *26754528
24
+ version_requirements: *27185160
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &26754168 !ruby/object:Gem::Requirement
27
+ requirement: &27184872 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>'
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.3.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *26754168
35
+ version_requirements: *27184872
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &26753880 !ruby/object:Gem::Requirement
38
+ requirement: &27184572 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>'
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.0.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *26753880
46
+ version_requirements: *27184572
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &26753520 !ruby/object:Gem::Requirement
49
+ requirement: &27184248 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.6.4
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *26753520
57
+ version_requirements: *27184248
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rcov
60
- requirement: &26753160 !ruby/object:Gem::Requirement
60
+ requirement: &27183912 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *26753160
68
+ version_requirements: *27183912
69
69
  description: A simple Ruby interface to the Loggly API
70
70
  email: mitchellryanj@gmail.com
71
71
  executables: []
@@ -82,9 +82,11 @@ files:
82
82
  - Rakefile
83
83
  - lib/ruby_loggly.rb
84
84
  - ruby_loggly.gemspec
85
+ - spec/ruby_loggly_device_spec.rb
86
+ - spec/ruby_loggly_input_spec.rb
85
87
  - spec/ruby_loggly_spec.rb
86
88
  - spec/spec_helper.rb
87
- homepage: http://github.com/mitchel456/ruby_loggly
89
+ homepage: http://github.com/LynchMarks/ruby_loggly
88
90
  licenses:
89
91
  - MIT
90
92
  post_install_message:
@@ -99,7 +101,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
101
  version: '0'
100
102
  segments:
101
103
  - 0
102
- hash: 273334035
104
+ hash: -563236751
103
105
  required_rubygems_version: !ruby/object:Gem::Requirement
104
106
  none: false
105
107
  requirements: