Last active
December 5, 2016 17:55
-
-
Save eurica/8951769 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
require 'pp' | |
require 'httparty' | |
class PagerDuty | |
include HTTParty | |
format :json | |
def initialize(subdomain, api_token) | |
@options = { | |
:headers => { | |
"Authorization" => "Token token=#{api_token}", | |
"Content-type" => "application/json"}, | |
:output => 'json' | |
} | |
@subdomain = subdomain | |
end | |
def get(req, opts = {}) | |
opts = opts.merge(@options) | |
self.class.get("https://#{@subdomain}.pagerduty.com/api/v1/#{req}", opts) | |
end | |
def post(req, opts = {}) | |
opts = opts.merge(@options) | |
self.class.post("https://#{@subdomain}.pagerduty.com/api/v1/#{req}", opts) | |
end | |
end | |
#This is a read-only API key: | |
webdemo = PagerDuty.new("webdemo","BcRghqyTqokgfx3ADXiq") | |
# Get incidents: | |
puts webdemo.get("incidents", :query => "limit=1") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment