Class: Transbank::Webpay::Response

Inherits:
Object
  • Object
show all
Includes:
Helper, Reader, Validations
Defined in:
lib/transbank/webpay/response.rb

Constant Summary

Constants included from Helper

Helper::XS_DATE_TIME, Helper::XS_INTEGER

Constants included from Reader

Transbank::Webpay::Reader::RESPONSE_CODE

Instance Attribute Summary collapse

Attributes included from Reader

#action, #content

Attributes included from Validations

#errors

Instance Method Summary collapse

Methods included from Helper

#camelcase, #typecasting, #underscore, #xml_to_hash

Methods included from Reader

#attributes?, #body, #doc, #response_code_display, #xml_error_display

Methods included from Validations

#errors_display, #valid?, #validate_response!

Constructor Details

#initialize(content, action, params) ⇒ Response

Returns a new instance of Response.



10
11
12
13
14
15
16
17
18
# File 'lib/transbank/webpay/response.rb', line 10

def initialize(content, action, params)
  @content = content
  @action = action
  @params = params
  @attributes = xml_to_hash(xml_return)
  @errors = []

  validate_response!
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



39
40
41
# File 'lib/transbank/webpay/response.rb', line 39

def method_missing(method_name, *args, &block)
  attributes.respond_to?(method_name) && attributes.send(method_name) || super
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



8
9
10
# File 'lib/transbank/webpay/response.rb', line 8

def attributes
  @attributes
end

#exceptionObject (readonly)

Returns the value of attribute exception.



8
9
10
# File 'lib/transbank/webpay/response.rb', line 8

def exception
  @exception
end

#paramsObject (readonly)

Returns the value of attribute params.



8
9
10
# File 'lib/transbank/webpay/response.rb', line 8

def params
  @params
end

Instance Method Details

#exception?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/transbank/webpay/response.rb', line 31

def exception?
  false
end

#http_codeObject



20
21
22
# File 'lib/transbank/webpay/response.rb', line 20

def http_code
  content.code
end

#inspectObject



24
25
26
27
28
29
# File 'lib/transbank/webpay/response.rb', line 24

def inspect
  result = ["valid: #{valid?}"]
  result << attributes.inspect if attributes?
  result << "error: \"#{errors_display}\"" if errors.any?
  "#<#{self.class} #{result.join(', ')}>"
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/transbank/webpay/response.rb', line 43

def respond_to_missing?(method_name, include_private = false)
  attributes.respond_to?(method_name, include_private) || super
end