Class: Tappay::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/tappay/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(net_http_response) ⇒ Response



64
65
66
67
68
69
# File 'lib/tappay/client.rb', line 64

def initialize(net_http_response)
  @response = net_http_response
  @code = net_http_response.code.to_i
  @body = net_http_response.body
  @headers = net_http_response.to_hash
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



62
63
64
# File 'lib/tappay/client.rb', line 62

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



62
63
64
# File 'lib/tappay/client.rb', line 62

def code
  @code
end

#headersObject (readonly)

Returns the value of attribute headers.



62
63
64
# File 'lib/tappay/client.rb', line 62

def headers
  @headers
end

Instance Method Details

#[](key) ⇒ Object



81
82
83
# File 'lib/tappay/client.rb', line 81

def [](key)
  parsed_response[key]
end

#parsed_responseObject



71
72
73
74
75
# File 'lib/tappay/client.rb', line 71

def parsed_response
  @parsed_response ||= JSON.parse(@body)
rescue JSON::ParserError
  @body
end

#success?Boolean



77
78
79
# File 'lib/tappay/client.rb', line 77

def success?
  @code >= 200 && @code < 300
end