Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added analysis call for a specific check id #11

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -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
43 changes: 22 additions & 21 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions lib/pingdom-client.rb → lib/pingdom-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
15 changes: 15 additions & 0 deletions lib/pingdom/analysis.rb
Original file line number Diff line number Diff line change
@@ -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
27 changes: 26 additions & 1 deletion lib/pingdom/client.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
9 changes: 9 additions & 0 deletions lib/pingdom/rca.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Pingdom

class RCA < Base
def self.parse(client, response)
rca = super
new(client, response, rca)
end
end
end
78 changes: 0 additions & 78 deletions pingdom-client.gemspec

This file was deleted.

42 changes: 42 additions & 0 deletions pingdom-ruby.gemspec
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand Down