pingity 0.1.0
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.
- data/.document +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +20 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +20 -0
- data/Rakefile +35 -0
- data/VERSION +1 -0
- data/bin/pingity +60 -0
- data/lib/pingity.rb +90 -0
- data/lib/pingity/api_methods.rb +9 -0
- data/lib/pingity/config.rb +60 -0
- data/lib/pingity/exceptions.rb +7 -0
- data/pingity.gemspec +58 -0
- data/test/helper.rb +18 -0
- data/test/test_pingity.rb +7 -0
- metadata +85 -0
data/.document
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
git (1.2.5)
|
5
|
+
jeweler (1.8.3)
|
6
|
+
bundler (~> 1.0)
|
7
|
+
git (>= 1.2.5)
|
8
|
+
rake
|
9
|
+
rdoc
|
10
|
+
json (1.6.5)
|
11
|
+
rake (0.9.2.2)
|
12
|
+
rdoc (3.12)
|
13
|
+
json (~> 1.4)
|
14
|
+
|
15
|
+
PLATFORMS
|
16
|
+
ruby
|
17
|
+
|
18
|
+
DEPENDENCIES
|
19
|
+
bundler
|
20
|
+
jeweler
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011-2012 Scott Tadman, The Working Group Inc.
|
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,20 @@
|
|
1
|
+
= pingity
|
2
|
+
|
3
|
+
To install this as a gem:
|
4
|
+
|
5
|
+
gem install pingity
|
6
|
+
|
7
|
+
Using within an application:
|
8
|
+
|
9
|
+
Pingity.components['test.component:samples'].samples.push(8)
|
10
|
+
|
11
|
+
Using the command-line application:
|
12
|
+
|
13
|
+
pingity show components
|
14
|
+
|
15
|
+
pingity push <path.to.component:property> <value>
|
16
|
+
|
17
|
+
== Copyright
|
18
|
+
|
19
|
+
Copyright (c) 2011 - 2012 Scott Tadman, The Working Group Inc.
|
20
|
+
See LICENSE.txt for further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
|
6
|
+
begin
|
7
|
+
Bundler.setup(:default, :development)
|
8
|
+
rescue Bundler::BundlerError => e
|
9
|
+
$stderr.puts e.message
|
10
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
11
|
+
exit e.status_code
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'rake'
|
15
|
+
require 'jeweler'
|
16
|
+
|
17
|
+
Jeweler::Tasks.new do |gem|
|
18
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
19
|
+
gem.name = "pingity"
|
20
|
+
gem.homepage = "http://github.com/twg/pingity-ruby"
|
21
|
+
gem.license = "MIT"
|
22
|
+
gem.summary = %Q{Ruby Library for Pingity}
|
23
|
+
gem.description = %Q{A Ruby module for interfacing with Pingity}
|
24
|
+
gem.email = "scott@twg.ca"
|
25
|
+
gem.authors = [ "Scott Tadman" ]
|
26
|
+
# dependencies defined in Gemfile
|
27
|
+
end
|
28
|
+
Jeweler::RubygemsDotOrgTasks.new
|
29
|
+
|
30
|
+
require 'rake/testtask'
|
31
|
+
Rake::TestTask.new(:test) do |test|
|
32
|
+
test.libs << 'lib' << 'test'
|
33
|
+
test.pattern = 'test/**/test_*.rb'
|
34
|
+
test.verbose = true
|
35
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/pingity
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH << File.expand_path(File.join('..', 'lib'), File.dirname(__FILE__))
|
4
|
+
|
5
|
+
require 'pingity'
|
6
|
+
require 'optparse'
|
7
|
+
|
8
|
+
# == Constants ==============================================================
|
9
|
+
|
10
|
+
BANNER = "pingity Version #{Pingity.version} (API Version #{Pingity.api_version})".freeze
|
11
|
+
|
12
|
+
# == Support Methods ========================================================
|
13
|
+
|
14
|
+
def show_help
|
15
|
+
puts BANNER
|
16
|
+
end
|
17
|
+
|
18
|
+
# == Main ===================================================================
|
19
|
+
|
20
|
+
options = {
|
21
|
+
:verbose => false
|
22
|
+
}
|
23
|
+
|
24
|
+
op = OptionParser.new
|
25
|
+
|
26
|
+
op.on('-d', '--verbose') do
|
27
|
+
options[:verbose] = true
|
28
|
+
end
|
29
|
+
op.on('-v', '--version') do
|
30
|
+
puts BANNER
|
31
|
+
exit(0)
|
32
|
+
end
|
33
|
+
|
34
|
+
args = op.parse(ARGV)
|
35
|
+
|
36
|
+
Pingity.config(options)
|
37
|
+
|
38
|
+
command = args.shift
|
39
|
+
|
40
|
+
case (command)
|
41
|
+
when nil
|
42
|
+
show_help
|
43
|
+
else
|
44
|
+
method = command.to_sym
|
45
|
+
|
46
|
+
if (Pingity.api_method?(method))
|
47
|
+
begin
|
48
|
+
response = Pingity.send(method, *args)
|
49
|
+
|
50
|
+
if (response)
|
51
|
+
if (response['response_message'])
|
52
|
+
puts "Result: [#{response['response_code']}] #{response['response_message']}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
rescue Pingity::Exceptions::GeneralException => e
|
57
|
+
puts "Error: #{e.to_s}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/pingity.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'socket'
|
3
|
+
require 'net/http'
|
4
|
+
|
5
|
+
module Pingity
|
6
|
+
# == Submodules ===========================================================
|
7
|
+
|
8
|
+
autoload(:ApiMethods, 'pingity/api_methods')
|
9
|
+
autoload(:Config, 'pingity/config')
|
10
|
+
autoload(:Exceptions, 'pingity/exceptions')
|
11
|
+
|
12
|
+
# == Constants ============================================================
|
13
|
+
|
14
|
+
VERSION = File.read(File.expand_path(File.join('..', 'VERSION'), File.dirname(__FILE__))).chomp
|
15
|
+
API_VERSION = '1.0'.freeze
|
16
|
+
API_VERSION_FOR_URI = "v-#{API_VERSION.sub('.', '-')}".freeze
|
17
|
+
|
18
|
+
# == Module Methods =======================================================
|
19
|
+
|
20
|
+
def self.config(options = nil)
|
21
|
+
@config = nil if (options)
|
22
|
+
|
23
|
+
@config ||= Pingity::Config.new(options)
|
24
|
+
|
25
|
+
yield(@config) if (block_given?)
|
26
|
+
|
27
|
+
@config
|
28
|
+
end
|
29
|
+
class << self
|
30
|
+
alias_method :configure, :config
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.configured?
|
34
|
+
self.config.valid?
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.version
|
38
|
+
VERSION
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.api_version
|
42
|
+
API_VERSION
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.api_method?(method)
|
46
|
+
ApiMethods.instance_methods.include?(method)
|
47
|
+
end
|
48
|
+
|
49
|
+
extend Pingity::ApiMethods
|
50
|
+
|
51
|
+
protected
|
52
|
+
def self.api_call(method, options)
|
53
|
+
payload = JSON.dump(options.merge(:api_key => Pingity.config.api_key))
|
54
|
+
uri = URI("http://#{Pingity.config.api}/api/#{API_VERSION_FOR_URI}/#{method}.json")
|
55
|
+
|
56
|
+
response = nil
|
57
|
+
|
58
|
+
if (Pingity.config.verbose)
|
59
|
+
puts "Request:\n\t#{payload}"
|
60
|
+
end
|
61
|
+
|
62
|
+
case (Pingity.config.transport)
|
63
|
+
when :curb
|
64
|
+
else
|
65
|
+
Net::HTTP.start(uri.host, uri.port) do |http|
|
66
|
+
http_response = http.post(
|
67
|
+
uri.path,
|
68
|
+
payload,
|
69
|
+
'Content-Type' => 'application/json'
|
70
|
+
)
|
71
|
+
|
72
|
+
begin
|
73
|
+
response = JSON.load(http_response.body)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
puts response.inspect if (Pingity.config.verbose)
|
79
|
+
|
80
|
+
response
|
81
|
+
|
82
|
+
rescue SocketError => e
|
83
|
+
case (e.to_s)
|
84
|
+
when /nodename nor servname provided/
|
85
|
+
raise Pingity::Exceptions::NetworkError, "Hostname #{Pingity.config.api.inspect} could not be resolved, adjust 'api' configuration parameter or check DNS."
|
86
|
+
else
|
87
|
+
raise Pingity::Exceptions::NetworkError, "#{e}"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
class Pingity::Config
|
4
|
+
DEFAULT_OPTIONS = {
|
5
|
+
:config_path => "~/.pingityrc",
|
6
|
+
:api => 'api.pingity.com',
|
7
|
+
:api_key => nil,
|
8
|
+
:verbose => false
|
9
|
+
}.freeze
|
10
|
+
|
11
|
+
ENV_VARIABLE_PREFIX = /^PINGITY_/.freeze
|
12
|
+
|
13
|
+
def initialize(options = nil)
|
14
|
+
@options = DEFAULT_OPTIONS.dup
|
15
|
+
|
16
|
+
if (options)
|
17
|
+
@options.merge!(options)
|
18
|
+
end
|
19
|
+
|
20
|
+
ENV.each do |variable, value|
|
21
|
+
next unless (variable.match(ENV_VARIABLE_PREFIX))
|
22
|
+
|
23
|
+
key_name = variable.sub(ENV_VARIABLE_PREFIX, '').downcase
|
24
|
+
|
25
|
+
next if (key_name.empty?)
|
26
|
+
|
27
|
+
@options[key_name.to_sym] = value
|
28
|
+
end
|
29
|
+
|
30
|
+
config_path = File.expand_path(@options[:config_path])
|
31
|
+
|
32
|
+
if (config_path and !config_path.empty? and File.exist?(config_path))
|
33
|
+
config = YAML.load(File.read(config_path))
|
34
|
+
|
35
|
+
@options.merge!(Hash[
|
36
|
+
config.collect do |k, v|
|
37
|
+
[ k.to_sym, v ]
|
38
|
+
end
|
39
|
+
])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def valid?
|
44
|
+
!!(@api_key and !@api_key.empty?)
|
45
|
+
end
|
46
|
+
|
47
|
+
def transport
|
48
|
+
:net_http
|
49
|
+
end
|
50
|
+
|
51
|
+
DEFAULT_OPTIONS.keys.each do |name|
|
52
|
+
define_method(name) do
|
53
|
+
@options[name]
|
54
|
+
end
|
55
|
+
|
56
|
+
define_method(:"#{name}=") do |value|
|
57
|
+
@options[name] = value
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/pingity.gemspec
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
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 = "pingity"
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Scott Tadman"]
|
12
|
+
s.date = "2012-04-03"
|
13
|
+
s.description = "A Ruby module for interfacing with Pingity"
|
14
|
+
s.email = "scott@twg.ca"
|
15
|
+
s.executables = ["pingity"]
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE.txt",
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"bin/pingity",
|
29
|
+
"lib/pingity.rb",
|
30
|
+
"lib/pingity/api_methods.rb",
|
31
|
+
"lib/pingity/config.rb",
|
32
|
+
"lib/pingity/exceptions.rb",
|
33
|
+
"pingity.gemspec",
|
34
|
+
"test/helper.rb",
|
35
|
+
"test/test_pingity.rb"
|
36
|
+
]
|
37
|
+
s.homepage = "http://github.com/twg/pingity-ruby"
|
38
|
+
s.licenses = ["MIT"]
|
39
|
+
s.require_paths = ["lib"]
|
40
|
+
s.rubygems_version = "1.8.17"
|
41
|
+
s.summary = "Ruby Library for Pingity"
|
42
|
+
|
43
|
+
if s.respond_to? :specification_version then
|
44
|
+
s.specification_version = 3
|
45
|
+
|
46
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
47
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
48
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
49
|
+
else
|
50
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
51
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
52
|
+
end
|
53
|
+
else
|
54
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
55
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
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 'pingity-ruby'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pingity
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Scott Tadman
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: &2153048560 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2153048560
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: jeweler
|
27
|
+
requirement: &2153047240 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2153047240
|
36
|
+
description: A Ruby module for interfacing with Pingity
|
37
|
+
email: scott@twg.ca
|
38
|
+
executables:
|
39
|
+
- pingity
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE.txt
|
43
|
+
- README.rdoc
|
44
|
+
files:
|
45
|
+
- .document
|
46
|
+
- Gemfile
|
47
|
+
- Gemfile.lock
|
48
|
+
- LICENSE.txt
|
49
|
+
- README.rdoc
|
50
|
+
- Rakefile
|
51
|
+
- VERSION
|
52
|
+
- bin/pingity
|
53
|
+
- lib/pingity.rb
|
54
|
+
- lib/pingity/api_methods.rb
|
55
|
+
- lib/pingity/config.rb
|
56
|
+
- lib/pingity/exceptions.rb
|
57
|
+
- pingity.gemspec
|
58
|
+
- test/helper.rb
|
59
|
+
- test/test_pingity.rb
|
60
|
+
homepage: http://github.com/twg/pingity-ruby
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.8.17
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Ruby Library for Pingity
|
85
|
+
test_files: []
|