Class: MultiInfo::API::Response
- Inherits:
-
Object
- Object
- MultiInfo::API::Response
- Defined in:
- lib/multiinfo/api/response.rb
Overview
Used to parse HTTP responses returned from MultiInfo API calls.
Constant Summary collapse
- API_RESPONSES =
{ # Hash keys for each response lines. # Line no 1 is skipped as it always is 'status' 'sendsms' => [ :sms_id # 2 ], 'cancelsms' => [ :cancel_status # 2 ], 'infosms' => [ :sms_id, # 2 :message_type, # 3 :message_body, # 4 :protocol_id, # 5 :coding_scheme, # 6 :service_id, # 7 :conector_id, # 8 :originator_sms_id, # 9 :priority, # 10 :send_date, # 11 :valid_to, # 12 :deliv_notif_request, # 13 :originator, # 14 :destination, # 15 :message_status, # 16 :status_date # 17 ], 'packageinfo' => [ :package_id, # 2 :sent_message_count, # 3 :waiting_message_count,# 4 :package_status # 5 ], 'getsms' => [ :sms_id, # 2 :sender, # 3 :destination, # 4 :message_type, # 5 :message_body, # 6 :protocol_id, # 7 :coding_scheme, # 8 :service_id, # 9 :conector_id, # 9 :receive_date # 10 ] }
Class Method Summary collapse
-
.parse(response_arr) ⇒ Object
Returns the HTTP response body data as a hash.
Class Method Details
.parse(response_arr) ⇒ Object
Returns the HTTP response body data as a hash.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/multiinfo/api/response.rb', line 9 def parse(response_arr) return { :status => 'OK' } if API.test_mode command, http_response = response_arr response_rows = http_response.split(/\r\n|\n/) response_status, response_body = response_rows[0], response_rows[1..-1] if response_status.to_i < 0 raise MultiInfo::API::Error.new(response_status, response_body.first) else response_hash(command, response_body).merge({:status => response_status}) end end |