Skip to content

Instantly share code, notes, and snippets.

@eurica
Last active December 5, 2016 17:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eurica/8951769 to your computer and use it in GitHub Desktop.
Save eurica/8951769 to your computer and use it in GitHub Desktop.
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