class DogapiDemo::V1::EventService

Event-specific client affording more granular control than the simple DogapiDemo::Client

Constants

API_VERSION
MAX_BODY_LENGTH
MAX_TITLE_LENGTH

Public Instance Methods

get(id) click to toggle source
   # File lib/dogapi-demo/v1/event.rb
41 def get(id)
42   begin
43     params = {
44       :api_key => @api_key,
45       :application_key => @application_key
46     }
47 
48     request(Net::HTTP::Get, '/api/' + API_VERSION + '/events/' + id.to_s, params, nil, false)
49   rescue Exception => e
50     if @silent
51       warn e
52       return -1, {}
53     else
54       raise e
55     end
56   end
57 end
post(event, scope=nil) click to toggle source

Records an Event with no duration

   # File lib/dogapi-demo/v1/event.rb
14 def post(event, scope=nil)
15   begin
16     scope = scope || DogapiDemo::Scope.new()
17     params = {
18       :api_key => @api_key
19     }
20 
21     body = event.to_hash.merge({
22       :title => event.msg_title[0..MAX_TITLE_LENGTH - 1],
23       :text => event.msg_text[0..MAX_BODY_LENGTH - 1],
24       :date_happened => event.date_happened.to_i,
25       :host => scope.host,
26       :device => scope.device,
27       :aggregation_key => event.aggregation_key.to_s
28     })
29 
30     request(Net::HTTP::Post, '/api/v1/events', params, body, true)
31   rescue Exception => e
32     if @silent
33       warn e
34       return -1, {}
35     else
36       raise e
37     end
38   end
39 end
stream(start, stop, options = {}) click to toggle source
   # File lib/dogapi-demo/v1/event.rb
59 def stream(start, stop, options = {})
60   begin
61     defaults = {
62       :priority => nil,
63       :sources => nil,
64       :tags => nil
65     }
66     options = defaults.merge(options)
67 
68     params = {
69       :api_key => @api_key,
70       :application_key => @application_key,
71 
72       :start => start.to_i,
73       :end => stop.to_i
74     }
75 
76     if options[:priority]
77       params[:priority] = options[:priority]
78     end
79     if options[:sources]
80       params[:sources] = options[:sources]
81     end
82     if options[:tags]
83       tags = options[:tags]
84       params[:tags] = tags.kind_of?(Array) ? tags.join(",") : tags
85     end
86 
87     request(Net::HTTP::Get, '/api/' + API_VERSION + '/events', params, nil, false)
88   rescue Exception => e
89     if @silent
90       warn e
91       return -1, {}
92     else
93       raise e
94     end
95   end
96 end