Class: Dogapi::V1::EventService
- Inherits:
-
APIService
- Object
- APIService
- Dogapi::V1::EventService
- Defined in:
- lib/dogapi/v1/event.rb
Overview
Event-specific client affording more granular control than the simple Dogapi::Client
Constant Summary collapse
- API_VERSION =
'v1'
- MAX_BODY_LENGTH =
4000
- MAX_TITLE_LENGTH =
100
Instance Attribute Summary
Attributes inherited from APIService
Instance Method Summary collapse
- #delete(id) ⇒ Object
- #get(id) ⇒ Object
-
#post(event, scope = nil) ⇒ Object
Records an Event with no duration.
- #stream(start, stop, options = {}) ⇒ Object
Methods inherited from APIService
#connect, #handle_redirect, #handle_response, #initialize, #prepare_params, #prepare_request, #request, #should_set_api_and_app_keys_in_params?, #suppress_error_if_silent
Constructor Details
This class inherits a constructor from Dogapi::APIService
Instance Method Details
#delete(id) ⇒ Object
34 35 36 |
# File 'lib/dogapi/v1/event.rb', line 34 def delete(id) request(Net::HTTP::Delete, '/api/' + API_VERSION + '/events/' + id.to_s, nil, nil, false) end |
#get(id) ⇒ Object
30 31 32 |
# File 'lib/dogapi/v1/event.rb', line 30 def get(id) request(Net::HTTP::Get, '/api/' + API_VERSION + '/events/' + id.to_s, nil, nil, false) end |
#post(event, scope = nil) ⇒ Object
Records an Event with no duration
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/dogapi/v1/event.rb', line 16 def post(event, scope=nil) scope = scope || Dogapi::Scope.new() body = event.to_hash.merge({ :title => event.msg_title[0..MAX_TITLE_LENGTH - 1], :text => event.msg_text[0..MAX_BODY_LENGTH - 1], :date_happened => event.date_happened.to_i, :host => scope.host, :device => scope.device, :aggregation_key => event.aggregation_key.to_s }) request(Net::HTTP::Post, '/api/v1/events', nil, body, true, false) end |
#stream(start, stop, options = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/dogapi/v1/event.rb', line 38 def stream(start, stop, = {}) defaults = { :priority => nil, :sources => nil, :tags => nil } = defaults.merge() extra_params = { :start => start.to_i, :end => stop.to_i } if [:priority] extra_params[:priority] = [:priority] end if [:sources] extra_params[:sources] = [:sources] end if [:tags] = [:tags] extra_params[:tags] = .kind_of?(Array) ? .join(',') : end request(Net::HTTP::Get, '/api/' + API_VERSION + '/events', extra_params, nil, false) end |