Class: Nfe::Danfe
- Inherits:
-
Object
- Object
- Nfe::Danfe
- Defined in:
- lib/nfe/danfe.rb
Instance Attribute Summary collapse
-
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
-
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
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.
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_timeout ⇒ Object
Returns the value of attribute open_timeout.
6 7 8 |
# File 'lib/nfe/danfe.rb', line 6 def open_timeout @open_timeout end |
#read_timeout ⇒ Object
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
#pdf ⇒ Object
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 |