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
# File 'lib/cobro_digital/operador.rb', line 6

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

Instance Attribute Details

#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



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

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



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

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

  datos = []

  if parsed_response['datos'].present?
    parsed_response['datos'].each do |data|
      _data = data.split("\"")
      _data.delete("")
      datos << _data
    end
  end

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

#requestObject



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

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