Class: Touchpass::Rp::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/touchpass/rp/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_party_response = nil) ⇒ Response

Returns a new instance of Response.



7
8
9
10
11
12
# File 'lib/touchpass/rp/response.rb', line 7

def initialize(http_party_response = nil)
  if http_party_response
    @http_status_code = http_party_response.code
    @response = http_party_response.parsed_response
  end
end

Instance Attribute Details

#http_status_codeObject

Returns the value of attribute http_status_code.



5
6
7
# File 'lib/touchpass/rp/response.rb', line 5

def http_status_code
  @http_status_code
end

#responseObject

Returns the value of attribute response.



5
6
7
# File 'lib/touchpass/rp/response.rb', line 5

def response
  @response
end

Instance Method Details

#[](key) ⇒ Object



24
25
26
# File 'lib/touchpass/rp/response.rb', line 24

def [](key)
  @response.kind_of?(Hash) ? @response[key] : nil
end

#to_hObject



14
15
16
17
18
19
20
21
22
# File 'lib/touchpass/rp/response.rb', line 14

def to_h
  if @response.kind_of?(Hash)
    @response.merge(:http_status_code => @http_status_code)
  elsif @http_status_code != 200
    { :error => @response, :http_status_code => @http_status_code }
  else
    { :text => @response, :http_status_code => @http_status_code }
  end
end

#to_json(options = {}) ⇒ Object



28
29
30
# File 'lib/touchpass/rp/response.rb', line 28

def to_json(options = {})
  to_h.to_json(options)
end