Skip to content

Instantly share code, notes, and snippets.

@chrisroberts
Forked from cwjohnston/gist:3960708
Created October 26, 2012 19:04
Show Gist options
  • Save chrisroberts/3960758 to your computer and use it in GitHub Desktop.
Save chrisroberts/3960758 to your computer and use it in GitHub Desktop.
class PingdomClient
class << self
def load_httparty
require 'httparty'
self.send(:include, HTTParty)
self.class_eval do
self.base_uri = 'https://api.pingdom.com/api/2.0'
end
end
end
def initialize(u,p,k)
@auth = {:username => u, :password => p}
@headers = {'App-Key' => k}
end
def get(uri, options={})
options.merge!({:basic_auth => @auth})
options.merge!({:headers => @headers})
response = self.class.get(uri, options)
end
def put(uri, options={})
options.merge!({:basic_auth => @auth})
options.merge!({:headers => @headers})
response = self.class.put(uri, options)
end
def post(uri, options={})
options.merge!({:basic_auth => @auth})
options.merge!({:headers => @headers})
response = self.class.post(uri, options)
end
def delete(uri, options={})
options.merge!({:basic_auth => @auth})
options.merge!({:headers => @headers})
response = self.class.delete(uri, options)
end
def checks(options={})
options.merge!({:basic_auth => @auth})
options.merge!({:headers => @headers})
response = self.class.get('/checks', options).parsed_response
checks = response['checks']
end
end
######
# In your default recipe, something like this:
chef_gem 'httparty'
rb = ruby_block 'Enable httparty' do
block do
PingdomClient.load_httparty
end
not_if do
PingdomClient.ancestors.include?(HTTParty)
end
end
rb.run_action(:create)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment