class Statuspageio::Client

Public Class Methods

bad_response(response) click to toggle source
# File lib/statuspageio/client.rb, line 33
def self.bad_response(response)
  if response.class == HTTParty::Response
    raise ResponseError, response
  end
  raise StandardError, 'Unknown error'
end
handle_response(response) click to toggle source
# File lib/statuspageio/client.rb, line 25
def self.handle_response(response)
  if response.success?
    JSON.parse(response.body)
  else
    bad_response(response)
  end
end
new(options = {}) click to toggle source
# File lib/statuspageio/client.rb, line 18
def initialize(options = {})
  options = Statuspageio.options.merge(options)
  Configuration::VALID_OPTIONS_KEYS.each do |key|
    send("#{key}=", options[key])
  end
end

Public Instance Methods

delete(path) click to toggle source
# File lib/statuspageio/client.rb, line 40
def delete(path)
  self.class.handle_response(self.class.delete("#{path}.json", headers: headers))
end
get(path, query = {}) click to toggle source
# File lib/statuspageio/client.rb, line 44
def get(path, query = {})
  self.class.handle_response(self.class.get("#{path}.json", query: query, headers: headers))
end
post(path, data = {}) click to toggle source
# File lib/statuspageio/client.rb, line 48
def post(path, data = {})
  self.class.handle_response(self.class.post("#{path}.json", body: data.to_json, headers: headers))
end
put(path, data = {}) click to toggle source
# File lib/statuspageio/client.rb, line 52
def put(path, data = {})
  self.class.handle_response(self.class.put("#{path}.json", body: data.to_json, headers: headers))
end

Private Instance Methods

headers() click to toggle source
# File lib/statuspageio/client.rb, line 58
def headers
  {
    'Authorization' => "OAuth #{self.api_key}",
    'Content-Type'  => 'application/json'
  }
end