class Dogapi::V1::EventService
Event-specific client affording more granular control than the simple Dogapi::Client
Constants
- API_VERSION
- MAX_BODY_LENGTH
- MAX_TITLE_LENGTH
Public Instance Methods
delete(id)
click to toggle source
# File lib/dogapi/v1/event.rb 34 def delete(id) 35 request(Net::HTTP::Delete, '/api/' + API_VERSION + '/events/' + id.to_s, nil, nil, false) 36 end
get(id)
click to toggle source
# File lib/dogapi/v1/event.rb 30 def get(id) 31 request(Net::HTTP::Get, '/api/' + API_VERSION + '/events/' + id.to_s, nil, nil, false) 32 end
post(event, scope=nil)
click to toggle source
Records an Event
with no duration
# File lib/dogapi/v1/event.rb 16 def post(event, scope=nil) 17 scope = scope || Dogapi::Scope.new() 18 body = event.to_hash.merge({ 19 :title => event.msg_title[0..MAX_TITLE_LENGTH - 1], 20 :text => event.msg_text[0..MAX_BODY_LENGTH - 1], 21 :date_happened => event.date_happened.to_i, 22 :host => scope.host, 23 :device => scope.device, 24 :aggregation_key => event.aggregation_key.to_s 25 }) 26 27 request(Net::HTTP::Post, '/api/v1/events', nil, body, true, false) 28 end
stream(start, stop, options= {})
click to toggle source
# File lib/dogapi/v1/event.rb 38 def stream(start, stop, options= {}) 39 defaults = { 40 :priority => nil, 41 :sources => nil, 42 :tags => nil 43 } 44 options = defaults.merge(options) 45 46 extra_params = { 47 :start => start.to_i, 48 :end => stop.to_i 49 } 50 51 if options[:priority] 52 extra_params[:priority] = options[:priority] 53 end 54 if options[:sources] 55 extra_params[:sources] = options[:sources] 56 end 57 if options[:tags] 58 tags = options[:tags] 59 extra_params[:tags] = tags.kind_of?(Array) ? tags.join(',') : tags 60 end 61 62 request(Net::HTTP::Get, '/api/' + API_VERSION + '/events', extra_params, nil, false) 63 end