Created
July 14, 2016 15:40
-
-
Save lfepp/f337f064e86ce39e88b7b98a91e4a5b5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'pp' | |
require 'httparty' | |
# Class to GET or POST to the PagerDuty REST API | |
class PagerDuty | |
include HTTParty | |
format :json | |
def initialize(api_token) | |
@options = { | |
:headers => { | |
'Authorization' => "Token token=#{api_token}", | |
'Content-type' => 'application/json', | |
'Accept' => 'application/vnd.pagerduty+json;version=2' | |
}, | |
:output => 'json' | |
} | |
end | |
def get(req, opts = {}) | |
opts = opts.merge(@options) | |
self.class.get("https://api.pagerduty.com/#{req}", opts) | |
end | |
def post(req, opts = {}) | |
opts = opts.merge(@options) | |
self.class.post("https://api.pagerduty.com/#{req}", opts) | |
end | |
end | |
# This is a read-only API key: | |
webdemo = PagerDuty.new('3Zy8bTHN1fDJq5vBW-X7') | |
# 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