Module: Xcal::Parktronic::Routes::Nested::Events
- Included in:
- GenericResponse
- Defined in:
- lib/xcal/parktronic/routes/nested/events.rb
Instance Method Summary collapse
-
#get_all_events ⇒ Object
Fetches all events for the specific alarm Executed as a method chain from the GenericResponse object.
-
#get_paged_events(args = {}) ⇒ Object
(also: #get_events)
Fetches events for the specific alarm Executed as a method chain from the GenericResponse object.
-
#post_event(params) ⇒ Object
Create event for the specific alarm Executed as a method chain from the GenericResponse object.
Instance Method Details
#get_all_events ⇒ Object
Fetches all events for the specific alarm Executed as a method chain from the GenericResponse object
Call example:
alarm(id).get_all_events
31 32 33 34 35 36 |
# File 'lib/xcal/parktronic/routes/nested/events.rb', line 31 def get_all_events response = client.get_response("/#{client.api_version}/alarms/#{id}/events?#{URI.encode_www_form(access_token: client.access_token)}") generic_response = Xcal::Parktronic::GenericResponse.new(response.body, client) response.code == '200' && generic_response.has_key?(:events) ? generic_response.events.map(&:event) : generic_response end |
#get_paged_events(args = {}) ⇒ Object Also known as: get_events
Fetches events for the specific alarm Executed as a method chain from the GenericResponse object
Call example:
alarm(id).get_events(page: 2, per_page: 4)
Accepted attributes:
+page+ page number, defaults to 1
+per_page+ per page value, defaults to 100
17 18 19 20 21 22 23 |
# File 'lib/xcal/parktronic/routes/nested/events.rb', line 17 def get_paged_events(args = {}) args.merge!(:access_token => client.access_token) response = client.get_response("/#{client.api_version}/alarms/#{id}/events?#{URI.encode_www_form(args)}") generic_response = Xcal::Parktronic::GenericResponse.new(response.body, client) response.code == '200' && generic_response.has_key?(:events) ? generic_response.events.map(&:event) : generic_response end |
#post_event(params) ⇒ Object
Create event for the specific alarm Executed as a method chain from the GenericResponse object
Call example:
alarms.last.post_event(subject: 'example', host_impacted: 'test')
alarm(id).post_event(subject: 'example', host_impacted: 'test')
44 45 46 47 48 49 50 |
# File 'lib/xcal/parktronic/routes/nested/events.rb', line 44 def post_event(params) request = Net::HTTP::Post.new("/#{client.api_version}/alarms/#{id}/events", 'Content-Type' => 'application/json') request.body = { access_token: client.access_token, event: params }.to_json response = client.http.start { |net| net.request(request) } Xcal::Parktronic::GenericResponse.new(response.body) end |