Class: Nfe::Danfe
- Inherits:
-
Object
- Object
- Nfe::Danfe
- Defined in:
- lib/nfe/danfe.rb
Instance Method Summary collapse
-
#initialize(xml_or_file) ⇒ Danfe
constructor
A new instance of Danfe.
- #pdf ⇒ Object
Constructor Details
#initialize(xml_or_file) ⇒ Danfe
Returns a new instance of Danfe.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/nfe/danfe.rb', line 7 def initialize(xml_or_file) if File.exist?(xml_or_file) @xml_or_file = xml_or_file else @xml_or_file = "#{Dir.tmpdir}/nota.xml" File.open(@xml_or_file, 'w') do |file| file.write(xml_or_file) end end end |
Instance Method Details
#pdf ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/nfe/danfe.rb', line 18 def pdf return @pdf if @pdf url = URI('http://freenfe.com.br/danfe/?view=1') http = Net::HTTP.new(url.host, url.port) req = Net::HTTP::Post::Multipart.new url.request_uri, nota: UploadIO.new(@xml_or_file, 'text/xml', 'nota.xml') request = http.request(req) @pdf = request.body end |