Class: CachetClient

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

Overview

Basic client to call to make calls into rest-client

Defined Under Namespace

Classes: Error

Constant Summary collapse

STATUS_OPERATIONAL =
1
STATUS_PERFORMANCE_ISSUES =
2
STATUS_PARTIAL_OUTAGE =
3
STATUS_MAJOR_OUTAGE =
4
INCIDENT_SCHEDULED =
0
INCIDENT_INVESTIGATING =
1
INCIDENT_IDENTIFIED =
3
INCIDENT_WATCHING =
3
INCIDENT_FIXED =
4
VERSION =
'0.1.0'

Instance Method Summary collapse

Constructor Details

#initialize(api_key, base_url) ⇒ CachetClient

Providing Demo api/url information if none provided


27
28
29
30
31
32
33
34
# File 'lib/cachet.rb', line 27

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


52
53
54
55
# File 'lib/cachet.rb', line 52

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

#request(params) ⇒ Object


36
37
38
39
40
41
42
43
44
45
# File 'lib/cachet.rb', line 36

def request(params)
  response = RestClient::Request.execute(params.merge(headers: @headers))
  body = JSON.parse(response.body)

  if response.code == 200
    return body
  else
    fail Net::HTTPError, response.inspect
  end
end