Skip to content

Commit

Permalink
Response is a BravoResponse now.
Browse files Browse the repository at this point in the history
  • Loading branch information
miloops committed Nov 9, 2011
1 parent c0f0d23 commit 350479d
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions lib/bravo/bill.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
class BravoResponse < Struct.new("BravoResponse", :header_result, :authorized_on, :detail_result, :cae_due_date, :cae, :iva_id, :iva_importe, :moneda, :cotizacion, :iva_base_imp, :doc_num, :cant_reg, :cbte_tipo, :pto_vta, :concepto, :doc_tipo, :cbte_fch, :imp_tot_conc, :imp_op_ex, :imp_trib, :imp_neto, :imp_iva, :imp_total, :cbte_hasta, :cbte_desde, :fch_serv_desde, :fch_serv_hasta, :fch_vto_pago)
def initialize(*args)
arg = args.first
if arg.is_a? Hash
arg.each {|key,value| self.send(:"#{key}=", value)}
else
super
end
end
end

module Bravo
class Bill
attr_reader :client, :base_imp, :total
Expand Down Expand Up @@ -144,9 +155,7 @@ def query_bill(iva_cond, cbte_number)
:doc_num => result[:doc_nro]
}

keys, values = response_hash.to_a.transpose

self.response = (defined?(Struct::Response) ? Struct::Response : Struct.new("Response", *keys)).new(*values)
self.response = BravoResponse.new(response_hash)
end

private
Expand All @@ -158,8 +167,6 @@ def header(cbte_type)#todo sacado de la factura
end

def setup_response(response)
# TODO: turn this into an all-purpose Response class

begin
result = response[:fecae_solicitar_response][:fecae_solicitar_result]

Expand Down Expand Up @@ -194,9 +201,7 @@ def setup_response(response)
:doc_num => request_detail.delete(:doc_nro)
}.merge!(request_header).merge!(request_detail)

keys, values = response_hash.to_a.transpose
self.response = (defined?(Struct::Response) ? Struct::Response : Struct.new("Response", *keys)).new(*values)
true
self.response = BravoResponse.new(response_hash)
end
end
end

0 comments on commit 350479d

Please sign in to comment.