Module: Xcal::Parktronic::Routes::Nested::AlarmActions
- Included in:
- GenericResponse
- Defined in:
- lib/xcal/parktronic/routes/nested/alarm_actions.rb
Instance Method Summary collapse
-
#get_alarm_action(alarm_action_id) ⇒ Object
Fetches alarm action with specific ID.
-
#get_alarm_actions ⇒ Object
Fetches alarm_actions for the specific alarm Executed as a method chain from the GenericResponse object.
-
#post_alarm_action(params) ⇒ Object
Posts new alarm.
-
#set_position(alarm_action_id, position) ⇒ Object
Insert the Alarm Action at the given position.
-
#update_alarm_action(alarm_action_id, params) ⇒ Object
Update Alarm Action.
Instance Method Details
#get_alarm_action(alarm_action_id) ⇒ Object
Fetches alarm action with specific ID
Accepted attributes:
+id+ alarm_action ID
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/xcal/parktronic/routes/nested/alarm_actions.rb', line 28 def get_alarm_action(alarm_action_id) response = client.get_response("/#{client.api_version}/alarms/#{id}/alarm_actions/#{alarm_action_id}?access_token=#{client.access_token}") generic_response = Xcal::Parktronic::GenericResponse.new(response.body, client) if response.code == '200' && generic_response.has_key?(:alarm_action) generic_response.alarm_action else generic_response end end |
#get_alarm_actions ⇒ Object
Fetches alarm_actions for the specific alarm Executed as a method chain from the GenericResponse object
Call example:
alarm(3).get_alarm_actions
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/xcal/parktronic/routes/nested/alarm_actions.rb', line 13 def get_alarm_actions response = client.get_response("/#{client.api_version}/alarms/#{id}/alarm_actions?#{URI.encode_www_form(access_token: client.access_token)}") generic_response = Xcal::Parktronic::GenericResponse.new(response.body, client) if response.code == '200' && generic_response.has_key?(:alarm_actions) generic_response.alarm_actions.map(&:alarm_action) else generic_response end end |
#post_alarm_action(params) ⇒ Object
Posts new alarm
params
hash of AlarmAction data.
42 43 44 45 46 47 48 |
# File 'lib/xcal/parktronic/routes/nested/alarm_actions.rb', line 42 def post_alarm_action(params) request = Net::HTTP::Post.new("/#{client.api_version}/alarms/#{id}/alarm_actions", 'Content-Type' => 'application/json') request.body = { access_token: client.access_token, alarm_action: params }.to_json response = client.http.start { |net| net.request(request) } Xcal::Parktronic::GenericResponse.new(response.body) end |
#set_position(alarm_action_id, position) ⇒ Object
Insert the Alarm Action at the given position
68 69 70 71 72 73 74 |
# File 'lib/xcal/parktronic/routes/nested/alarm_actions.rb', line 68 def set_position(alarm_action_id, position) request = Net::HTTP::Post.new("/#{client.api_version}/alarms/#{id}/alarm_actions/#{alarm_action_id}/insert_at", 'Content-Type' => 'application/json') request.body = { access_token: client.access_token, position: position }.to_json response = client.http.start { |net| net.request(request) } Xcal::Parktronic::GenericResponse.new(response.body) end |
#update_alarm_action(alarm_action_id, params) ⇒ Object
Update Alarm Action
Accepted attributes: alarm_action_id
alarm action id params
alarm params
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/xcal/parktronic/routes/nested/alarm_actions.rb', line 55 def update_alarm_action(alarm_action_id, params) begin request = Net::HTTP::Patch.new("/#{client.api_version}/alarms/#{id}/alarm_actions/#{alarm_action_id}", 'Content-Type' => 'application/json') rescue # ruby 1.9.2 request = Net::HTTP::Put.new("/#{client.api_version}/alarms/#{id}/alarm_actions/#{alarm_action_id}", 'Content-Type' => 'application/json') end request.body = { access_token: client.access_token, alarm_action: params }.to_json response = client.http.start { |net| net.request(request) } Xcal::Parktronic::GenericResponse.new(response.body) end |