Skip to content

Instantly share code, notes, and snippets.

@thegreenrobot
Last active August 29, 2015 14:06
Show Gist options
  • Save thegreenrobot/f672f4f3a147f8d63091 to your computer and use it in GitHub Desktop.
Save thegreenrobot/f672f4f3a147f8d63091 to your computer and use it in GitHub Desktop.
PagerDuty Incident with Faraday
#!/usr/bin/env ruby
# encoding: UTF-8
require 'faraday'
require 'json'
SECRETS_FILE = './lib/secrets.json'
SECRETS_PARSED = JSON.parse( IO.read( SECRETS_FILE ))
URL = SECRETS_PARSED['url']
API_KEY = SECRETS_PARSED['api_key']
INCIDENT = ARGV[0]
conn = Faraday.new(:url => "#{URL}") do |faraday|
faraday.adapter Faraday.default_adapter
faraday.headers['Content-type'] = 'application/json'
faraday.headers['Authorization'] = "Token token=#{API_KEY}"
end
begin
response = conn.get "/api/v1/incidents/#{INCIDENT}"
puts JSON.parse(response.body)
rescue
puts 'Awww snap. The response from the PagerDuty API was not successful.'
end
{
"url": "https://mysubdomain.pagerduty.com",
"api_key": "MYREALLYLONGAPIKEY",
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment