Class: Pingdom::Client
- Inherits:
-
Object
- Object
- Pingdom::Client
- Defined in:
- lib/pingdom/client.rb
Instance Attribute Summary collapse
-
#limit ⇒ Object
Returns the value of attribute limit.
Instance Method Summary collapse
- #check(id) ⇒ Object
- #checks(options = {}) ⇒ Object
- #contacts(options = {}) ⇒ Object
- #get(uri, params = {}, &block) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
-
#parse_limit(limit) ⇒ Object
“Remaining: 394 Time until reset: 3589”.
-
#prepare_params(options) ⇒ Object
probes => [1,2,3] #=> probes => “1,2,3”.
- #probes(options = {}) ⇒ Object
-
#results(id, options = {}) ⇒ Object
Check ID.
- #summary(id) ⇒ Object
- #test!(options = {}) ⇒ Object
- #update_limits!(short, long) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/pingdom/client.rb', line 8 def initialize( = {}) = .with_indifferent_access.reverse_merge(:http_driver => :excon) raise ArgumentError, "an application key must be provided (as :key)" unless .key?(:key) @connection = Faraday::Connection.new(:url => "https://api/pingdom.com/api/2.0/") do |builder| builder.url_prefix = "https://api.pingdom.com/api/2.0" builder.adapter :logger, [:logger] builder.adapter [:http_driver] # builder.use Gzip # TODO: write GZip response handler, add Accept-Encoding: gzip header builder.response :yajl builder.use Tinder::FaradayResponse::WithIndifferentAccess builder.basic_auth [:username], [:password] end end |
Instance Attribute Details
#limit ⇒ Object
Returns the value of attribute limit.
6 7 8 |
# File 'lib/pingdom/client.rb', line 6 def limit @limit end |
Instance Method Details
#check(id) ⇒ Object
66 67 68 |
# File 'lib/pingdom/client.rb', line 66 def check(id) Check.parse(self, get("checks/#{id}")).first end |
#checks(options = {}) ⇒ Object
63 64 65 |
# File 'lib/pingdom/client.rb', line 63 def checks( = {}) Check.parse(self, get("checks", )) end |
#contacts(options = {}) ⇒ Object
80 81 82 |
# File 'lib/pingdom/client.rb', line 80 def contacts( = {}) Contact.parse(self, get("contacts", )) end |
#get(uri, params = {}, &block) ⇒ Object
38 39 40 41 42 |
# File 'lib/pingdom/client.rb', line 38 def get(uri, params = {}, &block) response = @connection.get(@connection.build_url(uri, prepare_params(params)), "App-Key" => [:key], &block) update_limits!(response.headers['req-limit-short'], response.headers['req-limit-long']) response end |
#parse_limit(limit) ⇒ Object
“Remaining: 394 Time until reset: 3589”
52 53 54 55 56 57 |
# File 'lib/pingdom/client.rb', line 52 def parse_limit(limit) if limit.to_s =~ /Remaining: (\d+) Time until reset: (\d+)/ { :remaining => $1.to_i, :resets_at => $2.to_i.seconds.from_now } end end |
#prepare_params(options) ⇒ Object
probes => [1,2,3] #=> probes => “1,2,3”
29 30 31 32 33 34 35 36 |
# File 'lib/pingdom/client.rb', line 29 def prepare_params() .each do |(key, value)| [key] = Array.wrap(value).map(&:to_s).join(',') [key] = value.to_i if value.acts_like?(:time) end end |
#probes(options = {}) ⇒ Object
76 77 78 |
# File 'lib/pingdom/client.rb', line 76 def probes( = {}) Probe.parse(self, get("probes", )) end |
#results(id, options = {}) ⇒ Object
Check ID
71 72 73 74 |
# File 'lib/pingdom/client.rb', line 71 def results(id, = {}) .reverse_merge!(:includeanalysis => true) Result.parse(self, get("results/#{id}", )) end |
#summary(id) ⇒ Object
84 85 86 |
# File 'lib/pingdom/client.rb', line 84 def summary(id) Summary.proxy(self, id) end |
#test!(options = {}) ⇒ Object
59 60 61 |
# File 'lib/pingdom/client.rb', line 59 def test!( = {}) Result.parse(self, get("single", )).first end |
#update_limits!(short, long) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/pingdom/client.rb', line 44 def update_limits!(short, long) @limit ||= {} @limit[:short] = parse_limit(short) @limit[:long] = parse_limit(long) @limit end |