class CachetClient

Basic client to call to make calls into rest-client

Sets Version

Constants

INCIDENT_FIXED

Constant to utilize for Incident Status Fixed

INCIDENT_IDENTIFIED

Constant to utilize for Incident Status Identified

INCIDENT_INVESTIGATING

Constant to utilize for Incident Status Investigating

INCIDENT_SCHEDULED

Constant to utilize for Incident Status Scheduled Incident/Maintainence

INCIDENT_WATCHING

Constant to utilize for Incident Status Watching

STATUS_MAJOR_OUTAGE

Constant to utilize for Component Status Major Outage

STATUS_OPERATIONAL

Constant to utilize for Component Status Operational

STATUS_PARTIAL_OUTAGE

Constant to utilize for Component Status Partial Outage

STATUS_PERFORMANCE_ISSUES

Constant to utilize for Component Status Peformance Issues

VERSION

Sets Version of gem

Public Class Methods

new(api_key, base_url) click to toggle source

Providing Demo api/url information if none provided @param api_key [string] :api_key Your cachet API Token/Key @param base_url [string] :base_url Your cachet base api url @return object

# File lib/cachet.rb, line 50
def initialize(api_key, base_url)
  @api_key = api_key
  @base_url = base_url
  @headers = {
    'X-Cachet-Token' => @api_key,
    'Content-Type' => 'application/json'
  }
end

Public Instance Methods

ping() click to toggle source

Ping.

@return object

# File lib/cachet.rb, line 88
def ping
  request method:  :get,
          url:     @base_url + 'ping'
end
request(params) click to toggle source

Posts token, url, headers, and any payloads to rest-client all params are passed by methods @param params [string] :api_key Your cachet API Token/Key @param params [string] :url Your complete cachet api url, built by methods @param params [string] :method Get, Post, Put, and Delete @param params [hash] :options Set of options provided by the Cachet methods @param params [hash] :headers provides by initialize methods @return object

# File lib/cachet.rb, line 68
def request(params)
  headers = params[:headers] ? @headers.merge(params[:headers]) : @headers
  response = RestClient::Request.execute(params.merge(headers: headers))
  code = response.code

  if response.code == 200
    body = JSON.parse(response.body)
    return body
  elsif response.code == 204
    return { 'data' => code }
  else
    fail Net::HTTPError, response.inspect
  end
end