-
-
Save thegreenrobot/f672f4f3a147f8d63091 to your computer and use it in GitHub Desktop.
PagerDuty Incident with Faraday
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
#!/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 | |
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
{ | |
"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