Class: Wavefront::Events

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/wavefront/events.rb

Overview

These methods expect to be called with a hash whose keys are as defined in the Wavefront API Console. That is, ‘n’ as ‘name for the event’, ‘s’ as ‘start time for the event’ and so-on.

Constant Summary collapse

DEFAULT_PATH =
'/api/events/'

Constants included from Constants

Constants::DEFAULT_FORMAT, Constants::DEFAULT_HOST, Constants::DEFAULT_PERIOD_SECONDS, Constants::DEFAULT_PREFIX_LENGTH, Constants::DEFAULT_STRICT, Constants::FORMATS, Constants::GRANULARITIES

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ Events

Returns a new instance of Events.



26
27
28
# File 'lib/wavefront/events.rb', line 26

def initialize(token)
  @token = token
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



24
25
26
# File 'lib/wavefront/events.rb', line 24

def token
  @token
end

Instance Method Details

#close(payload = {}, options = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/wavefront/events.rb', line 43

def close(payload = {}, options = {})
  options[:host] ||= DEFAULT_HOST
  options[:path] ||= DEFAULT_PATH

  # This request seems to need the data as a query string. I was
  # getting a 500 when I posted a hash. A map will do the
  # needful.

  uri = URI::HTTPS.build(
    host:  options[:host],
    path:  options[:path] + 'close',
    query: URI.escape(
      payload.map { |k, v| [k, v].join('=') }.join('&') + '&t=' + @token
    )
  )
  puts uri.to_s

  RestClient.post(uri.to_s, payload)
end

#create(payload = {}, options = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/wavefront/events.rb', line 30

def create(payload = {}, options = {})
  options[:host] ||= DEFAULT_HOST
  options[:path] ||= DEFAULT_PATH

  uri = URI::HTTPS.build(
    host:  options[:host],
    path:  options[:path],
    query: "t=#{@token}"
  )

  RestClient.post(uri.to_s, payload)
end