scout_scout 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Jesse Newland
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,28 @@
1
+ = scout_scout
2
+
3
+ Get your data out of Scout:
4
+
5
+ require 'scout_scout'
6
+ scout = ScoutScout.new('youraccountname', 'your@awesome.com', 'sekret')
7
+ #all your servers
8
+ clients = scout.clients
9
+ #one specific server
10
+ ram_hungry = scout.client(1234)
11
+ #details on that server's plugins
12
+ ram_hungry_plugins = scout.plugins(1234)
13
+ #details about the plugin with id 5678 in account 1234
14
+ data = scout.plugin_data(1234,5678)
15
+
16
+ == Note on Patches/Pull Requests
17
+
18
+ * Fork the project.
19
+ * Make your feature addition or bug fix.
20
+ * Add tests for it. This is important so I don't break it in a
21
+ future version unintentionally.
22
+ * Commit, do not mess with rakefile, version, or history.
23
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
24
+ * Send me a pull request. Bonus points for topic branches.
25
+
26
+ == Copyright
27
+
28
+ Copyright (c) 2010 Jesse Newland. See LICENSE for details.
@@ -0,0 +1,50 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "scout_scout"
8
+ gem.summary = %Q{API wrapper for scout.com}
9
+ gem.description = %Q{API wrapper for scout.com}
10
+ gem.email = "jnewland@gmail.com"
11
+ gem.homepage = "http://github.com/jnewland/scout_scout"
12
+ gem.authors = ["Jesse Newland"]
13
+ gem.add_development_dependency "rspec", "= 1.3.0"
14
+ gem.add_development_dependency "fakeweb"
15
+ gem.add_dependency "hashie", "~> 0.1.8"
16
+ gem.add_dependency "httparty", "~> 0.5.0"
17
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
+ end
19
+ Jeweler::GemcutterTasks.new
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
+ end
23
+
24
+ require 'spec/rake/spectask'
25
+ Spec::Rake::SpecTask.new(:spec) do |spec|
26
+ spec.libs << 'lib' << 'spec'
27
+ spec.spec_files = FileList['spec/**/*_spec.rb']
28
+ end
29
+
30
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
31
+ spec.libs << 'lib' << 'spec'
32
+ spec.pattern = 'spec/**/*_spec.rb'
33
+ spec.rcov = true
34
+ end
35
+
36
+ task :spec => :check_dependencies
37
+
38
+ task :default => :spec
39
+
40
+ require 'rake/rdoctask'
41
+ $LOAD_PATH.unshift 'lib'
42
+ require 'scout_scout/version'
43
+ Rake::RDocTask.new do |rdoc|
44
+ version = ScoutScout::VERSION
45
+
46
+ rdoc.rdoc_dir = 'rdoc'
47
+ rdoc.title = "scout_scout #{version}"
48
+ rdoc.rdoc_files.include('README*')
49
+ rdoc.rdoc_files.include('lib/**/*.rb')
50
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,60 @@
1
+ require 'hashie'
2
+ require 'httparty'
3
+ require 'scout_scout/version'
4
+
5
+ class ScoutScout
6
+ include HTTParty
7
+ base_uri 'https://scoutapp.com'
8
+ format :xml
9
+ mattr_inheritable :account
10
+
11
+ def initialize(acct, user, pass)
12
+ self.class.account = acct
13
+ self.class.basic_auth user, pass
14
+ end
15
+
16
+ def alerts(id = nil)
17
+ if id.nil?
18
+ response = self.class.get("/#{self.class.account}/activities.xml")
19
+ response['alerts'].map { |alert| Hashie::Mash.new(alert) }
20
+ else
21
+ response = self.class.get("/#{self.class.account}/clients/#{id}/activities.xml")
22
+ response['alerts'].map { |alert| Hashie::Mash.new(alert) }
23
+ end
24
+ end
25
+
26
+ def clients
27
+ response = self.class.get("/#{self.class.account}/clients.xml")
28
+ response['clients'].map { |client| Hashie::Mash.new(client) }
29
+ end
30
+
31
+ def client(id)
32
+ response = self.class.get("/#{self.class.account}/clients/#{id}.xml")
33
+ Hashie::Mash.new(response['client'])
34
+ end
35
+
36
+ def plugins(id)
37
+ response = self.class.get("/#{self.class.account}/clients/#{id}/plugins.xml")
38
+ response['plugins'].map { |plugin| Hashie::Mash.new(plugin) }
39
+ end
40
+
41
+ def plugin_data(client, id)
42
+ require 'nokogiri'
43
+ html = self.class.get("/#{self.class.account}/clients/#{client}/plugins/#{id}", :format => :html)
44
+ plugin_doc = Nokogiri::HTML(html)
45
+ table = plugin_doc.css('table.list.spaced').first
46
+ data = []
47
+ table.css('tr').each do |row|
48
+ if (columns = row.css('td')).length == 2
49
+ link = columns.first.css('a').first
50
+ descriptor = {}
51
+ descriptor[:name] = link.content
52
+ descriptor[:data] = columns[1].content.strip
53
+ descriptor[:id] = link.attribute('href').to_s.gsub(/.*=/,'').to_i
54
+ descriptor[:graph] = "#{self.class.base_uri}/#{self.class.account}/descriptors/#{descriptor[:id]}/graph"
55
+ data << Hashie::Mash.new(descriptor)
56
+ end
57
+ end
58
+ data
59
+ end
60
+ end
@@ -0,0 +1,3 @@
1
+ class ScoutScout
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,95 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "ScoutScout" do
4
+ before(:each) do
5
+ @scout_scout = ScoutScout.new('account', 'username', 'password')
6
+ end
7
+ it "should provide a version constant" do
8
+ ScoutScout::VERSION.should be_instance_of(String)
9
+ end
10
+ it "should set the client and basic auth parameters when initialized" do
11
+ @scout_scout.class.account.should == 'account'
12
+ @scout_scout.class.default_options[:basic_auth].should == { :username => 'username', :password => 'password' }
13
+ end
14
+ describe "global" do
15
+ describe "client list" do
16
+ before(:each) do
17
+ stub_http_response_with('clients.xml')
18
+ @clients = @scout_scout.clients
19
+ end
20
+ it 'should list all clients' do
21
+ @clients.size.should == 2
22
+ end
23
+ it "should include active alerts" do
24
+ @clients.last.active_alerts.first.title.should =~ /Passenger/
25
+ end
26
+ end
27
+ describe 'alert log' do
28
+ before(:each) do
29
+ stub_http_response_with('activities.xml')
30
+ @activities = @scout_scout.alerts
31
+ end
32
+ it "should be accessable" do
33
+ @activities.size.should == 2
34
+ @activities.each do |activity|
35
+ activity.title.should =~ /Passenger/
36
+ end
37
+ end
38
+ end
39
+ end
40
+ describe 'individual clients' do
41
+ describe '' do
42
+ before(:each) do
43
+ stub_http_response_with('client.xml')
44
+ @client = @scout_scout.client(1234)
45
+ end
46
+ it "should be accessable" do
47
+ @client.key.should == 'FOOBAR'
48
+ end
49
+ end
50
+ describe 'alert log' do
51
+ before(:each) do
52
+ stub_http_response_with('activities.xml')
53
+ @activities = @scout_scout.alerts(1234)
54
+ end
55
+ it "should be accessable" do
56
+ @activities.size.should == 2
57
+ @activities.each do |activity|
58
+ activity.title.should =~ /Passenger/
59
+ end
60
+ end
61
+ end
62
+ describe 'plugins' do
63
+ describe '' do
64
+ before(:each) do
65
+ stub_http_response_with('plugins.xml')
66
+ @plugins = @scout_scout.plugins(1234)
67
+ end
68
+ it "should be accessable" do
69
+ @plugins.size.should == 4
70
+ @plugins.each do |plugin|
71
+ plugin.code.should =~ /Scout::Plugin/
72
+ end
73
+ end
74
+ end
75
+ describe 'data' do
76
+ before(:each) do
77
+ stub_http_response_with('plugin.html')
78
+ @plugin_data = @scout_scout.plugin_data(1234,5678)
79
+ end
80
+ it "should be accessable" do
81
+ @plugin_data.size.should == 13
82
+ end
83
+ it "should include data" do
84
+ @plugin_data.first.data.should == '6 MB'
85
+ end
86
+ it "should include graph URLs" do
87
+ @plugin_data.first.graph.should == 'https://scoutapp.com/account/descriptors/368241/graph'
88
+ end
89
+ it "should include name" do
90
+ @plugin_data.first.name.should == 'Swap Used'
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,23 @@
1
+ require 'scout_scout'
2
+ require 'spec'
3
+ require 'spec/autorun'
4
+ require 'fakeweb'
5
+
6
+ FakeWeb.allow_net_connect = false
7
+
8
+ def file_fixture(filename)
9
+ open(File.join(File.dirname(__FILE__), 'fixtures', "#{filename.to_s}")).read
10
+ end
11
+
12
+ def stub_http_response_with(filename)
13
+ format = filename.split('.').last.intern
14
+ data = file_fixture(filename)
15
+
16
+ response = Net::HTTPOK.new("1.1", 200, "Content for you")
17
+ response.stub!(:body).and_return(data)
18
+
19
+ http_request = HTTParty::Request.new(Net::HTTP::Get, 'http://localhost', :format => format)
20
+ http_request.stub!(:perform_actual_request).and_return(response)
21
+
22
+ HTTParty::Request.should_receive(:new).and_return(http_request)
23
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scout_scout
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jesse Newland
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-21 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - "="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.3.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: fakeweb
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: hashie
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 0.1.8
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: httparty
47
+ type: :runtime
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.5.0
54
+ version:
55
+ description: API wrapper for scout.com
56
+ email: jnewland@gmail.com
57
+ executables: []
58
+
59
+ extensions: []
60
+
61
+ extra_rdoc_files:
62
+ - LICENSE
63
+ - README.rdoc
64
+ files:
65
+ - .document
66
+ - .gitignore
67
+ - LICENSE
68
+ - README.rdoc
69
+ - Rakefile
70
+ - VERSION
71
+ - lib/scout_scout.rb
72
+ - lib/scout_scout/version.rb
73
+ - spec/scout_scout_spec.rb
74
+ - spec/spec.opts
75
+ - spec/spec_helper.rb
76
+ has_rdoc: true
77
+ homepage: http://github.com/jnewland/scout_scout
78
+ licenses: []
79
+
80
+ post_install_message:
81
+ rdoc_options:
82
+ - --charset=UTF-8
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: "0"
90
+ version:
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: "0"
96
+ version:
97
+ requirements: []
98
+
99
+ rubyforge_project:
100
+ rubygems_version: 1.3.5
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: API wrapper for scout.com
104
+ test_files:
105
+ - spec/scout_scout_spec.rb
106
+ - spec/spec_helper.rb