Class: LiveAddress::ResponseParser

Inherits:
Object
  • Object
show all
Defined in:
lib/live_address/response_parser.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ ResponseParser

Returns a new instance of ResponseParser.



17
18
19
# File 'lib/live_address/response_parser.rb', line 17

def initialize(response)
  set_attrs(response)
end

Class Method Details

.parse(response) ⇒ Object

Raises:



7
8
9
10
11
12
13
14
15
# File 'lib/live_address/response_parser.rb', line 7

def self.parse(response)
  raise BadInputError        if response.code == 400
  raise AuthorizationError   if response.code == 401
  raise PaymentRequiredError if response.code == 402
  raise InternalServerError  if response.code == 500

  parsed_response = JSON.parse(response.body)
  parsed_response.map {|r| ResponseParser.new(r) }
end