Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.