module Xcal module Parktronic module Routes module Nested module 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 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 alias :get_events :get_paged_events # Fetches all events for the specific alarm # Executed as a method chain from the GenericResponse object # # Call example: # alarm(id).get_all_events 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 # 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') 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 end end end end end