Class: CobroDigital::Operador

Inherits:
Object
  • Object
show all
Defined in:
lib/cobro_digital/operador.rb

Direct Known Subclasses

Boleta, Meta, Micrositio, Pagador, Transaccion

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Operador

Returns a new instance of Operador.



6
7
8
9
10
11
# File 'lib/cobro_digital/operador.rb', line 6

def initialize(attrs={})
  @http_method = attrs[:http_method]
  @webservice  = attrs[:webservice]
  @render      = attrs[:render]
  @client      = nil
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



4
5
6
# File 'lib/cobro_digital/operador.rb', line 4

def client
  @client
end

#http_methodObject

Returns the value of attribute http_method.



4
5
6
# File 'lib/cobro_digital/operador.rb', line 4

def http_method
  @http_method
end

#renderObject

Returns the value of attribute render.



4
5
6
# File 'lib/cobro_digital/operador.rb', line 4

def render
  @render
end

#responseObject

Returns the value of attribute response.



4
5
6
# File 'lib/cobro_digital/operador.rb', line 4

def response
  @response
end

#webserviceObject

Returns the value of attribute webservice.



4
5
6
# File 'lib/cobro_digital/operador.rb', line 4

def webservice
  @webservice
end

Instance Method Details

#call(id_comercio, sid, opt = {}) ⇒ Object



17
18
19
20
# File 'lib/cobro_digital/operador.rb', line 17

def call(id_comercio, sid, opt = {})
  @client = CobroDigital::Client.new(opt.merge(:id_comercio => id_comercio, :sid => sid, :http_method => http_method))
  @response = @client.call(request)
end

#parse_responseObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/cobro_digital/operador.rb', line 22

def parse_response
  output = response.body[:webservice_cobrodigital_response][:output]
  parsed_response = JSON.parse(output)

  raw_datos = parsed_response['datos'] || []

  datos = raw_datos.map do |row|
    row.is_a?(Array) ? row : (JSON.parse(row) rescue row)
  end.flatten

  { resultado: (parsed_response['ejecucion_correcta'] == '1'), log: parsed_response['log'], datos:  datos }
end

#requestObject



13
14
15
# File 'lib/cobro_digital/operador.rb', line 13

def request
  { :metodo_webservice => @webservice }.merge(render)
end