class StatusPage::API::Base
Public Instance Methods
execute(path, method:, **options)
click to toggle source
sends request to status page API
for given path and method, passing any other options through to RestClient parses the response and returns as a ruby hash or array
# File lib/status_page/api/base.rb, line 6 def execute(path, method:, **options) default_options = {headers: headers, method: method, url: get_full_url(path)} JSON.parse(RestClient::Request.execute(default_options.merge(options))) rescue ::RestClient::Exception => e raise Exception.new(e) end
get_resource()
click to toggle source
sends GET request for subclass's resource_path
and returns json result as hash
# File lib/status_page/api/base.rb, line 14 def get_resource execute(resource_path, method: :get) end
patch_resource(payload)
click to toggle source
sends PATCH request for subclass's resource_path
and returns json result as hash; accepts a payload parameter to convert to JSON body
# File lib/status_page/api/base.rb, line 20 def patch_resource(payload) execute(resource_path, method: :patch, payload: payload.to_json) end
Private Instance Methods
api_key()
click to toggle source
# File lib/status_page/api/base.rb, line 38 def api_key ENV['STATUS_PAGE_API_KEY'] || raise("Must specify STATUS_PAGE_API_KEY to use StatusPage") end
get_full_url(subpath)
click to toggle source
# File lib/status_page/api/base.rb, line 30 def get_full_url(subpath) "https://api.statuspage.io/v1/#{subpath}" end
headers()
click to toggle source
# File lib/status_page/api/base.rb, line 34 def headers {"Authorization" => "OAuth #{api_key}", "Content-Type" => "application/json"} end
resource_path()
click to toggle source
# File lib/status_page/api/base.rb, line 26 def resource_path raise("Must define resource_path in your subclass") end