Class: Nfe::Danfe

Inherits:
Object
  • Object
show all
Defined in:
lib/nfe/danfe.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml_or_file) ⇒ Danfe

Returns a new instance of Danfe.



8
9
10
11
12
13
14
15
16
17
# File 'lib/nfe/danfe.rb', line 8

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 Attribute Details

#open_timeoutObject

Returns the value of attribute open_timeout.



6
7
8
# File 'lib/nfe/danfe.rb', line 6

def open_timeout
  @open_timeout
end

#read_timeoutObject

Returns the value of attribute read_timeout.



6
7
8
# File 'lib/nfe/danfe.rb', line 6

def read_timeout
  @read_timeout
end

Instance Method Details

#pdfObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/nfe/danfe.rb', line 19

def pdf
  return @pdf if @pdf

  url = URI('http://freenfe.com.br/danfe/?view=1')

  http = Net::HTTP.new(url.host, url.port)
  http.open_timeout = self.open_timeout
  http.read_timeout = self.read_timeout
  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