Class: CobroDigital::Operador
- Inherits:
-
Object
- Object
- CobroDigital::Operador
- Defined in:
- lib/cobro_digital/operador.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#http_method ⇒ Object
Returns the value of attribute http_method.
-
#render ⇒ Object
Returns the value of attribute render.
-
#response ⇒ Object
Returns the value of attribute response.
-
#webservice ⇒ Object
Returns the value of attribute webservice.
Instance Method Summary collapse
- #call(id_comercio, sid, opt = {}) ⇒ Object
-
#initialize(attrs = {}) ⇒ Operador
constructor
A new instance of Operador.
- #parse_response ⇒ Object
- #request ⇒ Object
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
#client ⇒ Object
Returns the value of attribute client.
4 5 6 |
# File 'lib/cobro_digital/operador.rb', line 4 def client @client end |
#http_method ⇒ Object
Returns the value of attribute http_method.
4 5 6 |
# File 'lib/cobro_digital/operador.rb', line 4 def http_method @http_method end |
#render ⇒ Object
Returns the value of attribute render.
4 5 6 |
# File 'lib/cobro_digital/operador.rb', line 4 def render @render end |
#response ⇒ Object
Returns the value of attribute response.
4 5 6 |
# File 'lib/cobro_digital/operador.rb', line 4 def response @response end |
#webservice ⇒ Object
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_response ⇒ Object
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 |
#request ⇒ Object
13 14 15 |
# File 'lib/cobro_digital/operador.rb', line 13 def request { :metodo_webservice => @webservice }.merge(render) end |