Class: Exetel::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/exetel/response.rb,
lib/exetel/response/type_keys.rb

Overview

Used to parse HTTP responses returned from Exetel API calls.

Defined Under Namespace

Classes: TypeKeys

Class Method Summary collapse

Class Method Details

.parse(response_type, http_response) ⇒ Object

Returns the HTTP response body data as a hash.

  • TODO - CLean this up

Raises:



10
11
12
13
14
15
16
# File 'lib/exetel/response.rb', line 10

def parse(response_type, http_response)
  response_keys = Exetel::Response::TypeKeys[response_type]
  body = http_response.body.gsub("\n", '')
  response = Hash[*response_keys.zip(body.split("|")).flatten]
  raise Exetel::API::Error.new(response) if response[:status] == "0"
  response
end