Class: AndSon::Response

Inherits:
Struct
  • Object
show all
Defined in:
lib/and-son/response.rb

Constant Summary collapse

CODE_MATCHERS =
{
  '400' => 400,
  '404' => 404,
  '4xx' => /4[0-9][0-9]/,
  '5xx' => /5[0-9][0-9]/
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#protocol_responseObject

Returns the value of attribute protocol_response

Returns:

  • (Object)

    the current value of protocol_response



5
6
7
# File 'lib/and-son/response.rb', line 5

def protocol_response
  @protocol_response
end

Class Method Details

.parse(hash) ⇒ Object



14
15
16
# File 'lib/and-son/response.rb', line 14

def self.parse(hash)
  self.new(Sanford::Protocol::Response.parse(hash))
end

Instance Method Details

#dataObject



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/and-son/response.rb', line 18

def data
  if self.code_is_5xx?
    raise ServerError.new(self.protocol_response)
  elsif self.code_is_404?
    raise NotFoundError.new(self.protocol_response)
  elsif self.code_is_400?
    raise BadRequestError.new(self.protocol_response)
  elsif self.code_is_4xx?
    raise ClientError.new(self.protocol_response)
  else
    self.protocol_response.data
  end
end