-
-
Save chrisroberts/3960758 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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