Class: Transbank::Oneclick::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/transbank/oneclick/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action, params = {}, opt = {}) ⇒ Request

Returns a new instance of Request.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/transbank/oneclick/request.rb', line 6

def initialize(action, params = {}, opt = {})
  opt = {
    rescue_exceptions: Transbank::Oneclick.configuration.rescue_exceptions,
    http_options: {}
  }.merge(opt)

  self.action = action
  self.rescue_exceptions = opt[:rescue_exceptions]
  self.xml = Document.new(action, params)
  self.client = Client.new opt.delete(:http_options)
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



4
5
6
# File 'lib/transbank/oneclick/request.rb', line 4

def action
  @action
end

#clientObject

Returns the value of attribute client.



4
5
6
# File 'lib/transbank/oneclick/request.rb', line 4

def client
  @client
end

#rescue_exceptionsObject

Returns the value of attribute rescue_exceptions.



4
5
6
# File 'lib/transbank/oneclick/request.rb', line 4

def rescue_exceptions
  @rescue_exceptions
end

#xmlObject

Returns the value of attribute xml.



4
5
6
# File 'lib/transbank/oneclick/request.rb', line 4

def xml
  @xml
end

Instance Method Details

#responseObject



18
19
20
21
22
23
24
# File 'lib/transbank/oneclick/request.rb', line 18

def response
  @Response ||= begin
    Response.new client.post(xml.canonicalize), action
  rescue match_class(rescue_exceptions) => error
    ExceptionResponse.new error, action
  end
end