class RunscopeStatuspage::StatuspageAPI

Public Class Methods

new(token) click to toggle source

Set credentials

# File lib/runscope_statuspage/statuspage_api.rb, line 11
def initialize(token)
  @options = { headers: {"Authorization" => "OAuth #{token}"} }
end

Public Instance Methods

clear_metric_data(page_id, metric_id) click to toggle source

Delete all data for a custom page metric

# File lib/runscope_statuspage/statuspage_api.rb, line 40
def clear_metric_data(page_id, metric_id)
  reply = self.class.delete("/pages/#{page_id}/metrics/#{metric_id}/data.json", @options)

  raise StatuspageAPIException.new,
        "Could not delete all data for #{page_id}/#{metric_id}: #{reply}" if reply.key?('error')
end
create_realtime_incident(page, name, msg, status, twitter) click to toggle source

Create incident

# File lib/runscope_statuspage/statuspage_api.rb, line 16
def create_realtime_incident(page, name, msg, status, twitter)
  incident = self.class.post("/pages/#{page}/incidents.json", @options.merge!(body: {"incident" => {
                                                                            "name" => name,
                                                                            "message" => msg,
                                                                            "status" => status.nil? ? 'investigating' : status,
                                                                            "wants_twitter_update" => twitter
  }}))

  raise StatuspageAPIException.new,
        "Could not create incident: #{incident}" if incident.key?('error')
end
push_metric_data(page_id, metric_id, data, timestamp) click to toggle source

Publish data for a custom page metric

# File lib/runscope_statuspage/statuspage_api.rb, line 29
def push_metric_data(page_id, metric_id, data, timestamp)
  reply = self.class.post("/pages/#{page_id}/metrics/#{metric_id}/data.json", @options.merge!(body: {"data" => {
                                                                                               "value" => data,
                                                                                               "timestamp" => timestamp
  }}))

  raise StatuspageAPIException.new,
        "Could not push to #{page_id}/#{metric_id}: #{reply}" if reply.key?('error')
end