diff --git a/Gemfile b/Gemfile index b92d7b4..b0bf70a 100644 --- a/Gemfile +++ b/Gemfile @@ -1,15 +1,15 @@ -source :rubygems +source 'https://rubygems.org' -gem "faraday", "~> 0.5.7" +gem "faraday", "~> 0.8.5" -gem "excon", "~> 0.5.6" +gem "excon" gem "yajl-ruby", "~> 0.8.1", :require => "yajl" gem "activesupport", "~> 3.0.4" gem "i18n", "~> 0.5.0" # ActiveSupport dependency group :development do - gem "bundler", "~> 1.0.0" - gem "rake", "~> 0.8.7" - gem "rspec", "2.1.0" + gem "bundler" + gem "rake", '~> 10.1.0' + gem "rspec", '~> 2.14.1' end diff --git a/Gemfile.lock b/Gemfile.lock index 12f340c..3e6c9a3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,37 +1,38 @@ GEM - remote: http://rubygems.org/ + remote: https://rubygems.org/ specs: - activesupport (3.0.4) - addressable (2.2.4) - diff-lcs (1.1.2) - excon (0.5.6) + activesupport (3.0.20) + addressable (2.2.8) + diff-lcs (1.2.4) + excon (0.27.0) faraday (0.5.7) addressable (~> 2.2.4) multipart-post (~> 1.1.0) rack (>= 1.1.0, < 2) + rack (>= 1.1.0, < 2) i18n (0.5.0) - multipart-post (1.1.0) - rack (1.2.1) - rake (0.8.7) - rspec (2.1.0) - rspec-core (~> 2.1.0) - rspec-expectations (~> 2.1.0) - rspec-mocks (~> 2.1.0) - rspec-core (2.1.0) - rspec-expectations (2.1.0) - diff-lcs (~> 1.1.2) - rspec-mocks (2.1.0) - yajl-ruby (0.8.1) + multipart-post (1.1.5) + rack (1.5.2) + rake (10.1.0) + rspec (2.14.1) + rspec-core (~> 2.14.0) + rspec-expectations (~> 2.14.0) + rspec-mocks (~> 2.14.0) + rspec-core (2.14.5) + rspec-expectations (2.14.3) + diff-lcs (>= 1.1.3, < 2.0) + rspec-mocks (2.14.3) + yajl-ruby (0.8.3) PLATFORMS ruby DEPENDENCIES activesupport (~> 3.0.4) - bundler (~> 1.0.0) - excon (~> 0.5.6) + bundler + excon faraday (~> 0.5.7) i18n (~> 0.5.0) - rake (~> 0.8.7) - rspec (= 2.1.0) + rake (~> 10.1.0) + rspec (~> 2.14.1) yajl-ruby (~> 0.8.1) diff --git a/README.md b/README.md index 7116c16..065d610 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # Pingdom RESTful API Client -Pingdom now offers a RESTful API, which gives us no reason not to make a decent, -non-SOAP API client for their services. +Pingdom RESTful API wrapper for Ruby. NOTE: This is a 3rd party gem and not an official product from Pingdom. @@ -28,13 +27,15 @@ NOTE: This is a 3rd party gem and not an official product from Pingdom. ## Contributors +* Updated for Ruby 1.9.x/2.0.0 by Jason Straughan ([jdstraughan](http://github.com/jdstraughan)) * Emily Price ([duien](http://github.com/duien)) +* Based on [pingom-client](https://github.com/mtodd/pingdom-client) by [Matt Todd](https://github.com/mtodd) ## License The MIT License -Copyright (c) 2011 Matt Todd. +Copyright (c) 2013 Jason Straughan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Rakefile b/Rakefile index a663587..0e4bde4 100644 --- a/Rakefile +++ b/Rakefile @@ -15,7 +15,7 @@ RSpec::Core::RakeTask.new do |t| end task :console do - exec %(ruby -rirb -rubygems -r bundler/setup -r lib/pingdom-client -e '$credentials = YAML.load_file("credentials.yml").with_indifferent_access; $client = Pingdom::Client.new($credentials); IRB.start') + exec %(ruby -rirb -rubygems -r bundler/setup -r lib/pingdom-ruby -e '$credentials = YAML.load_file("credentials.yml").with_indifferent_access; $client = Pingdom::Client.new($credentials); IRB.start') end task :default => :spec diff --git a/lib/pingdom-client.rb b/lib/pingdom-ruby.rb similarity index 94% rename from lib/pingdom-client.rb rename to lib/pingdom-ruby.rb index f4c6678..a64b4ff 100644 --- a/lib/pingdom-client.rb +++ b/lib/pingdom-ruby.rb @@ -16,6 +16,8 @@ require 'pingdom/client' require 'pingdom/base' require 'pingdom/check' +require 'pingdom/analysis' +require 'pingdom/rca' require 'pingdom/result' require 'pingdom/probe' require 'pingdom/contact' diff --git a/lib/pingdom/analysis.rb b/lib/pingdom/analysis.rb new file mode 100644 index 0000000..40d86c9 --- /dev/null +++ b/lib/pingdom/analysis.rb @@ -0,0 +1,15 @@ +module Pingdom + + # {"id"=>259103, "timefirsttest"=>203173, "timeconfirmtest"=>1298102416} + class Analysis < Base + def self.parse(client, response) + analysis = super + Array.wrap(analysis[:analysis]).map do |analysis_element| + new(client, response, analysis_element) + end + end + + attributes :timefirsttest => :time_start, + :timeconfirmtest => :time_confirm + end +end \ No newline at end of file diff --git a/lib/pingdom/client.rb b/lib/pingdom/client.rb index 2481d5e..274479a 100644 --- a/lib/pingdom/client.rb +++ b/lib/pingdom/client.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', 'pingdom-client') unless defined? Pingdom +require File.join(File.dirname(__FILE__), '..', 'pingdom-ruby') unless defined? Pingdom module Pingdom class Client @@ -41,6 +41,24 @@ def get(uri, params = {}, &block) response end + def put(uri, params = {}, data, &block) + response = @connection.put(@connection.build_url(uri, prepare_params(params)), data, "App-Key" => @options[:key], &block) + update_limits!(response.headers['req-limit-short'], response.headers['req-limit-long']) + response + end + + def post(uri, params = {}, data, &block) + response = @connection.post(@connection.build_url(uri, prepare_params(params)), data, "App-Key" => @options[:key], &block) + update_limits!(response.headers['req-limit-short'], response.headers['req-limit-long']) + response + end + + def delete(uri, &block) + response = @connection.delete(@connection.build_url(uri), "App-Key" => @options[:key], &block) + update_limits!(response.headers['req-limit-short'], response.headers['req-limit-long']) + response + end + def update_limits!(short, long) @limit ||= {} @limit[:short] = parse_limit(short) @@ -85,5 +103,12 @@ def summary(id) Summary.proxy(self, id) end + def analysis(id, options = {}) + Analysis.parse(self,get("analysis/#{id}", options)) + end + + def rca(check_id, analysis_id) + RCA.parse(self,get("analysis/#{check_id}/#{analysis_id}")) + end end end diff --git a/lib/pingdom/rca.rb b/lib/pingdom/rca.rb new file mode 100644 index 0000000..929363d --- /dev/null +++ b/lib/pingdom/rca.rb @@ -0,0 +1,9 @@ +module Pingdom + + class RCA < Base + def self.parse(client, response) + rca = super + new(client, response, rca) + end + end +end \ No newline at end of file diff --git a/pingdom-client.gemspec b/pingdom-client.gemspec deleted file mode 100644 index fd391e4..0000000 --- a/pingdom-client.gemspec +++ /dev/null @@ -1,78 +0,0 @@ -Gem::Specification.new do |s| - s.name = %q{pingdom-client} - s.version = "0.0.6.alpha" - - s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= - s.authors = ["Matt Todd"] - s.date = %q{2011-03-02} - s.description = %q{Pingdom Ruby Client} - s.email = %q{chiology@gmail.com} - s.files = [ - "pingdom-client.gemspec", - "Gemfile", - "Gemfile.lock", - "lib/pingdom/base.rb", - "lib/pingdom/check.rb", - "lib/pingdom/client.rb", - "lib/pingdom/contact.rb", - "lib/pingdom/probe.rb", - "lib/pingdom/result.rb", - "lib/pingdom/summary/average.rb", - "lib/pingdom/summary/outage.rb", - "lib/pingdom/summary/performance.rb", - "lib/pingdom/summary.rb", - "lib/pingdom-client.rb", - "lib/pingdom.rb", - "lib/tinder/faraday_response.rb", - "Rakefile", - "Readme.md", - "spec/pingdom-client_spec.rb", - "spec/spec_helper.rb" - ] - s.homepage = %q{http://github.com/mtodd/pingdom-client} - s.licenses = ["MIT"] - s.require_paths = ["lib"] - s.rubygems_version = %q{1.3.7} - s.summary = %q{Pingdom Ruby Client} - s.test_files = [ - "spec/spec_helper.rb", - "spec/pingdom-client_spec.rb" - ] - - if s.respond_to? :specification_version then - current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION - s.specification_version = 3 - - if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then - s.add_runtime_dependency("faraday", ["~> 0.5.7"]) - s.add_runtime_dependency("excon", ["~> 0.5.6"]) - s.add_runtime_dependency("yajl-ruby", ["~> 0.8.1"]) - s.add_runtime_dependency("activesupport", ["~> 3.0.4"]) - s.add_runtime_dependency("i18n", ["~> 0.5.0"]) - - s.add_development_dependency("bundler", ["~> 1.0.0"]) - s.add_development_dependency("rake", ["~> 0.8.7"]) - s.add_development_dependency("rspec", ["= 2.1.0"]) - else - s.add_dependency("faraday", ["~> 0.5.7"]) - s.add_dependency("excon", ["~> 0.5.6"]) - s.add_dependency("yajl-ruby", ["~> 0.8.1"]) - s.add_dependency("activesupport", ["~> 3.0.4"]) - s.add_dependency("i18n", ["~> 0.5.0"]) - - s.add_dependency("bundler", ["~> 1.0.0"]) - s.add_dependency("rake", ["~> 0.8.7"]) - s.add_dependency("rspec", ["= 2.1.0"]) - end - else - s.add_dependency("faraday", ["~> 0.5.7"]) - s.add_dependency("excon", ["~> 0.5.6"]) - s.add_dependency("yajl-ruby", ["~> 0.8.1"]) - s.add_dependency("activesupport", ["~> 3.0.4"]) - s.add_dependency("i18n", ["~> 0.5.0"]) - - s.add_dependency("bundler", ["~> 1.0.0"]) - s.add_dependency("rake", ["~> 0.8.7"]) - s.add_dependency("rspec", ["= 2.1.0"]) - end -end diff --git a/pingdom-ruby.gemspec b/pingdom-ruby.gemspec new file mode 100644 index 0000000..f68ed9e --- /dev/null +++ b/pingdom-ruby.gemspec @@ -0,0 +1,42 @@ +Gem::Specification.new do |s| + s.name = %q{pingdom-ruby} + s.version = "1.0.4" + + s.authors = ["Jason Straughan"] + s.date = %q{2013-10-05} + s.description = %q{Pingdom Ruby Client} + s.email = %q{jasons@grok-interactive.com} + s.files = [ + "pingdom-ruby.gemspec", + "Gemfile", + "Gemfile.lock", + "lib/pingdom/base.rb", + "lib/pingdom/check.rb", + "lib/pingdom/client.rb", + "lib/pingdom/contact.rb", + "lib/pingdom/probe.rb", + "lib/pingdom/result.rb", + "lib/pingdom/rca.rb", + "lib/pingdom/analysis.rb", + "lib/pingdom/summary/average.rb", + "lib/pingdom/summary/outage.rb", + "lib/pingdom/summary/performance.rb", + "lib/pingdom/summary.rb", + "lib/pingdom-ruby.rb", + "lib/pingdom.rb", + "lib/tinder/faraday_response.rb", + "Rakefile", + "README.md", + "spec/pingdom-ruby_spec.rb", + "spec/spec_helper.rb" + ] + s.licenses = ["MIT"] + s.require_paths = ["lib"] + s.rubygems_version = %q{1.3.7} + s.summary = %q{Pingdom Ruby Client} + s.test_files = [ + "spec/spec_helper.rb", + "spec/pingdom-ruby_spec.rb" + ] + s.requirements << 'faraday, v0.5.7' +end diff --git a/spec/pingdom-client_spec.rb b/spec/pingdom-ruby_spec.rb similarity index 100% rename from spec/pingdom-client_spec.rb rename to spec/pingdom-ruby_spec.rb diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e9b7b9d..20d30d1 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,7 @@ $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))) require 'rubygems' require 'bundler/setup' -require 'pingdom-client' +require 'pingdom-ruby' require 'logger' require 'rspec'