Class: Wavefront::Events
- Inherits:
-
Object
- Object
- Wavefront::Events
- 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_HOST =
'metrics.wavefront.com'- DEFAULT_PATH =
'/api/events/'
Instance Attribute Summary collapse
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #close(payload = {}, options = {}) ⇒ Object
- #create(payload = {}, options = {}) ⇒ Object
-
#initialize(token) ⇒ Events
constructor
A new instance of Events.
Constructor Details
#initialize(token) ⇒ Events
Returns a new instance of Events.
25 26 27 |
# File 'lib/wavefront/events.rb', line 25 def initialize(token) @token = token end |
Instance Attribute Details
#token ⇒ Object (readonly)
Returns the value of attribute token.
23 24 25 |
# File 'lib/wavefront/events.rb', line 23 def token @token end |
Instance Method Details
#close(payload = {}, options = {}) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/wavefront/events.rb', line 42 def close(payload = {}, = {}) [:host] ||= DEFAULT_HOST [: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: [:host], path: [: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
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/wavefront/events.rb', line 29 def create(payload = {}, = {}) [:host] ||= DEFAULT_HOST [:path] ||= DEFAULT_PATH uri = URI::HTTPS.build( host: [:host], path: [:path], query: "t=#{@token}" ) RestClient.post(uri.to_s, payload) end |