korekuto 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 retr0h
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.
data/README.rdoc ADDED
@@ -0,0 +1,9 @@
1
+ = korekuto
2
+
3
+ == What?
4
+
5
+ == Why?
6
+
7
+ == Copyright
8
+
9
+ Copyright (c) 2009 retr0h. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "korekuto"
8
+ gem.summary = %Q{Data collector}
9
+ gem.description = %Q{Data collector}
10
+ gem.email = "john@dewey.ws"
11
+ gem.homepage = "http://github.com/retr0h/korekuto"
12
+ gem.authors = ["retr0h"]
13
+ gem.add_development_dependency "rspec"
14
+ %w[json macaddr httparty].each{|d| gem.add_dependency d}
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
19
+ end
20
+
21
+ require 'spec/rake/spectask'
22
+ Spec::Rake::SpecTask.new(:spec) do |spec|
23
+ spec.libs << 'lib' << 'spec'
24
+ spec.spec_files = FileList['spec/**/*_spec.rb']
25
+ end
26
+
27
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.pattern = 'spec/**/*_spec.rb'
30
+ spec.rcov = true
31
+ end
32
+
33
+ task :spec => :check_dependencies
34
+
35
+ task :default => :spec
36
+
37
+ require 'rake/rdoctask'
38
+ Rake::RDocTask.new do |rdoc|
39
+ if File.exist?('VERSION')
40
+ version = File.read('VERSION')
41
+ else
42
+ version = ""
43
+ end
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "korekuto #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/korekuto.gemspec ADDED
@@ -0,0 +1,62 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{korekuto}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["retr0h"]
12
+ s.date = %q{2009-10-10}
13
+ s.description = %q{Data collector}
14
+ s.email = %q{john@dewey.ws}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "korekuto.gemspec",
27
+ "lib/korekuto.rb",
28
+ "spec/korekuto_spec.rb",
29
+ "spec/spec_helper.rb"
30
+ ]
31
+ s.homepage = %q{http://github.com/retr0h/korekuto}
32
+ s.rdoc_options = ["--charset=UTF-8"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.3.5}
35
+ s.summary = %q{Data collector}
36
+ s.test_files = [
37
+ "spec/korekuto_spec.rb",
38
+ "spec/spec_helper.rb"
39
+ ]
40
+
41
+ if s.respond_to? :specification_version then
42
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
46
+ s.add_development_dependency(%q<rspec>, [">= 0"])
47
+ s.add_runtime_dependency(%q<json>, [">= 0"])
48
+ s.add_runtime_dependency(%q<macaddr>, [">= 0"])
49
+ s.add_runtime_dependency(%q<httparty>, [">= 0"])
50
+ else
51
+ s.add_dependency(%q<rspec>, [">= 0"])
52
+ s.add_dependency(%q<json>, [">= 0"])
53
+ s.add_dependency(%q<macaddr>, [">= 0"])
54
+ s.add_dependency(%q<httparty>, [">= 0"])
55
+ end
56
+ else
57
+ s.add_dependency(%q<rspec>, [">= 0"])
58
+ s.add_dependency(%q<json>, [">= 0"])
59
+ s.add_dependency(%q<macaddr>, [">= 0"])
60
+ s.add_dependency(%q<httparty>, [">= 0"])
61
+ end
62
+ end
data/lib/korekuto.rb ADDED
@@ -0,0 +1,40 @@
1
+ require 'rubygems'
2
+ require 'macaddr'
3
+ require 'json'
4
+ require 'httparty'
5
+
6
+ class Collector
7
+ include HTTParty
8
+
9
+ base_uri 'setsuju.heroku.com'
10
+ headers 'Content-Type' => 'application/json'
11
+ end
12
+
13
+ class PublicIp
14
+ include HTTParty
15
+
16
+ base_uri 'www.whatismyip.com'
17
+ end
18
+
19
+ module Korekuto
20
+ extend self
21
+
22
+ def submit
23
+ Collector.post('/collect', :body => collect.to_json, :timeout => 2)
24
+ rescue Timeout::Error
25
+ :timeout
26
+ end
27
+
28
+ private
29
+ ##
30
+ # Collect information about the dyno.
31
+ def collect
32
+ {
33
+ Mac.addr => {
34
+ :public_ip => PublicIp.get('/automation/n09230945.asp', :timeout => 2),
35
+ :local_ip => ENV['LOCAL_IP'],
36
+ :url => ENV['URL'],
37
+ }
38
+ }
39
+ end
40
+ end
@@ -0,0 +1,70 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ { 'collector' => 'setsuju.heroku.com', 'public_ip' => 'www.whatismyip.com' }.each do |k,v|
4
+ clazz = Kernel.const_get(k.split('_').map {|w| w.capitalize}.join)
5
+
6
+ describe clazz do
7
+ subject { clazz }
8
+
9
+ it "has included modules" do
10
+ subject.include?(HTTParty).should be_true
11
+ end
12
+
13
+ it "has a base_uri" do
14
+ subject.base_uri.should == "http://#{v}"
15
+ end
16
+
17
+ case clazz
18
+ when Collector
19
+ it "sets headers" do
20
+ subject.headers.should == {'Content-Type' => 'application/json'}
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ describe Korekuto do
27
+ describe :submit do
28
+ before(:each) do
29
+ @hash = {:foo => :bar}
30
+ Korekuto.stub!(:collect).and_return(@hash)
31
+ end
32
+
33
+ it "posts to the collector" do
34
+ Collector.should_receive(:post).with('/collect', :body => @hash.to_json, :timeout => 2)
35
+
36
+ Korekuto.submit
37
+ end
38
+
39
+ it "returns :timeout on timeout" do
40
+ Collector.should_receive(:post).and_raise(Timeout::Error.new(:rspec_timeout))
41
+
42
+ Korekuto.submit.should == :timeout
43
+ end
44
+ end
45
+
46
+ describe :collect do
47
+ before(:each) do
48
+ ENV['LOCAL_IP'] = '192.0.2.1'
49
+ ENV['URL'] = 'test.example.com'
50
+ end
51
+
52
+ it "returns a properly populated hash" do
53
+ PublicIp.should_receive(:get).with('/automation/n09230945.asp', :timeout => 2).and_return('192.0.2.0')
54
+ Mac.should_receive(:addr).and_return(:mac_address)
55
+
56
+ hash = Korekuto.send(:collect)[:mac_address]
57
+
58
+ hash[:public_ip].should == '192.0.2.0'
59
+ hash[:local_ip].should == '192.0.2.1'
60
+ hash[:url].should == 'test.example.com'
61
+ end
62
+
63
+ it "returns a properly populated hash on timeout" do
64
+ pending
65
+ #PublicIp.should_receive(:get).and_raise(Timeout::Error.new(:rspec_timeout))
66
+
67
+ #Korekuto.send(:collect)[:mac_address][:public_ip].should be_nil
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'korekuto'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: korekuto
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - retr0h
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-10 00:00:00 -07: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: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: json
27
+ type: :runtime
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: macaddr
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
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"
54
+ version:
55
+ description: Data collector
56
+ email: john@dewey.ws
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
+ - korekuto.gemspec
72
+ - lib/korekuto.rb
73
+ - spec/korekuto_spec.rb
74
+ - spec/spec_helper.rb
75
+ has_rdoc: true
76
+ homepage: http://github.com/retr0h/korekuto
77
+ licenses: []
78
+
79
+ post_install_message:
80
+ rdoc_options:
81
+ - --charset=UTF-8
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: "0"
89
+ version:
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: "0"
95
+ version:
96
+ requirements: []
97
+
98
+ rubyforge_project:
99
+ rubygems_version: 1.3.5
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: Data collector
103
+ test_files:
104
+ - spec/korekuto_spec.rb
105
+ - spec/spec_helper.rb