Class: Epay::Api::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/epay/api/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_response, action) ⇒ Response

Returns a new instance of Response.



6
7
8
9
# File 'lib/epay/api/response.rb', line 6

def initialize(raw_response, action)
  @raw_response = raw_response
  @action = action
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



24
25
26
# File 'lib/epay/api/response.rb', line 24

def method_missing(method, *args)
  raw_response.send(method, *args)
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



4
5
6
# File 'lib/epay/api/response.rb', line 4

def action
  @action
end

#raw_responseObject

Returns the value of attribute raw_response.



4
5
6
# File 'lib/epay/api/response.rb', line 4

def raw_response
  @raw_response
end

Instance Method Details

#dataObject



15
16
17
18
19
20
21
22
# File 'lib/epay/api/response.rb', line 15

def data
  if headers[:content_type] =~ %r(text/xml) && code == 200
    # Remove envelope and XML namespace objects
    Hash.from_xml(raw_response.to_s).first.last["Body"]["#{action}Response"].reject { |k,v| k.match(/xmlns/) }
  else
    raw_response.to_s
  end
end

#success?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/epay/api/response.rb', line 11

def success?
  code == 200 && data["#{action}Result"] == "true"
end