Class: CachetClient

Inherits:
Object
  • Object
show all
Defined in:
lib/cachet.rb,
lib/cachet/rb/version.rb

Overview

Sets Version

Defined Under Namespace

Classes: Error

Constant Summary collapse

STATUS_OPERATIONAL =

Constant to utilize for Component Status Operational

1
STATUS_PERFORMANCE_ISSUES =

Constant to utilize for Component Status Peformance Issues

2
STATUS_PARTIAL_OUTAGE =

Constant to utilize for Component Status Partial Outage

3
STATUS_MAJOR_OUTAGE =

Constant to utilize for Component Status Major Outage

4
INCIDENT_SCHEDULED =

Constant to utilize for Incident Status Scheduled Incident/Maintainence

0
INCIDENT_INVESTIGATING =

Constant to utilize for Incident Status Investigating

1
INCIDENT_IDENTIFIED =

Constant to utilize for Incident Status Identified

2
INCIDENT_WATCHING =

Constant to utilize for Incident Status Watching

3
INCIDENT_FIXED =

Constant to utilize for Incident Status Fixed

4
VERSION =

Sets Version of gem

'1.0.2'

Instance Method Summary collapse

Constructor Details

#initialize(api_key, base_url) ⇒ Object

Providing Demo api/url information if none provided

Parameters:

  • :api_key Your cachet API Token/Key

  • :base_url Your cachet base api url



50
51
52
53
54
55
56
57
# 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

Instance Method Details

#pingObject

Ping.

Returns:

  • object



88
89
90
91
# File 'lib/cachet.rb', line 88

def ping
  request method:  :get,
          url:     @base_url + 'ping'
end

#request(params) ⇒ Object

Posts token, url, headers, and any payloads to rest-client all params are passed by methods

Parameters:

  • :api_key Your cachet API Token/Key

  • :url Your complete cachet api url, built by methods

  • :method Get, Post, Put, and Delete

  • :options Set of options provided by the Cachet methods

  • :headers provides by initialize methods

Returns:

  • object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# 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