nfe-xml 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0f9925173a7031c1416bf46e1451c5bfb70b7bec
4
- data.tar.gz: d319cbe6de8677ab1c4fc896eea9a7211aedd6e7
3
+ metadata.gz: 7629e675a2c020909c8d689c751f2e02de43eab9
4
+ data.tar.gz: a7d4336bab4b16e3d8a0a84cde2b1b52e12535b8
5
5
  SHA512:
6
- metadata.gz: 1357dbd029e8e54986407b7c72118b7b7ce6130d151c9c097b3d6d5bb10039e462204108b147dcd1d021fb0154ab95db4a15c15ffbc0caf3427460fb0be63f1d
7
- data.tar.gz: 392354153af233212ebaf964b06744f8248b1f39d7a0bacc7d1e04047da807a21848b971c1c621537f87844e9a1622efde8e5c95f0b714bc0e7ff9d9ba26ed9b
6
+ metadata.gz: 9b7feaa3669a7894de35edfc367065f9268efc8fe86d4cc65b1d34f84a2e2e6ec232dfd7c7bd0d61cf6362c777beb2a74cd185481d333881b9221bc73efd4d91
7
+ data.tar.gz: cc507905ca104457ae0ef28cc70d63a56dbb0a0962ae7c8cbced5e5514f5ee8751c55e4463732c682d69884e583322fe996f4e606bb1e8d59838fcde43fc48e6
data/Gemfile CHANGED
@@ -2,3 +2,4 @@ source 'https://rubygems.org'
2
2
  gemspec
3
3
 
4
4
  gem 'nokogiri'
5
+ gem 'multipart-post'
@@ -1,13 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nfe-xml (0.1.1)
4
+ nfe-xml (0.1.2)
5
+ multipart-post (~> 2.0.0, >= 2.0.0)
5
6
  nokogiri (~> 1.5)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
10
11
  mini_portile2 (2.1.0)
12
+ multipart-post (2.0.0)
11
13
  nokogiri (1.6.8)
12
14
  mini_portile2 (~> 2.1.0)
13
15
  pkg-config (~> 1.1.7)
@@ -17,6 +19,7 @@ PLATFORMS
17
19
  ruby
18
20
 
19
21
  DEPENDENCIES
22
+ multipart-post
20
23
  nfe-xml!
21
24
  nokogiri
22
25
 
data/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  # Nfe
2
2
 
3
- NFe gem validates XML NFe used the site https://www.sefaz.rs.gov.br
3
+ NFe gem validates XML NFe used the site https://www.sefaz.rs.gov.br and generates Danfe used the site http://freenfe.com.br/danfe
4
4
 
5
5
  ## Installation
6
6
 
7
7
  Add this line to your application's Gemfile:
8
8
 
9
9
  ```ruby
10
- gem 'nfe'
10
+ gem 'nfe-xml'
11
11
  ```
12
12
 
13
13
  And then execute:
@@ -16,7 +16,7 @@ And then execute:
16
16
 
17
17
  Or install it yourself as:
18
18
 
19
- $ gem install nfe
19
+ $ gem install nfe-xml
20
20
 
21
21
  ## Usage
22
22
 
@@ -36,11 +36,25 @@ On terminal you can use nfe like this:
36
36
 
37
37
  xml.valid? # Returns boolean
38
38
  xml.result.messages # Returns Hash
39
+
40
+ danfe = Nfe::Danfe.new('~/nfe.xml')
41
+ danfe = Nfe::Danfe.new <<-XML
42
+ <?xml version="1.0" encoding="utf-8"?>
43
+ <NFe>
44
+ .
45
+ .
46
+ .
47
+ </NFe>
48
+ XML
49
+ File.open('~/nfe.pdf','w') do |f|
50
+ f.write(danfe.pdf)
51
+ end
39
52
  ```
40
53
 
41
54
  You can use from terminal either
42
55
  ```bash
43
56
  $ validate ~/nfe.xml ~/nfe2.xml
57
+ $ generate ~/nfe.xml ~/nfe2.xml
44
58
  ```
45
59
  ## Development
46
60
 
@@ -50,7 +64,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
50
64
 
51
65
  ## Contributing
52
66
 
53
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/nfe. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
67
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tofoli/nfe. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
54
68
 
55
69
 
56
70
  ## License
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
4
+ require 'nfe/danfe'
5
+
6
+ if ARGV.count > 0
7
+ ARGV.each do |file|
8
+ danfe = Nfe::Danfe.new(file)
9
+ File.open("#{file}.pdf", 'w') do |f|
10
+ f.write(danfe.pdf)
11
+ end
12
+ puts "#{file}:"
13
+ puts " Generates file #{file}.pdf"
14
+ end
15
+ else
16
+ puts 'How to use'
17
+ puts ' generate ~/nfe.xml'
18
+ puts ' generate ~/nfe.xml ~/nfe2.xml'
19
+ end
@@ -1,14 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
4
- require 'nfe'
4
+ require 'nfe/xml'
5
5
 
6
6
  if ARGV.count > 0
7
7
  ARGV.each do |file|
8
8
  xml = Nfe::Xml.new(file)
9
9
  puts "#{file}:"
10
10
  puts " #{xml.valid?}"
11
- puts " Messages:"
11
+ puts ' Messages:'
12
12
  xml.result.messages.each do |key, msg|
13
13
  puts " #{key} #{msg}"
14
14
  end
data/lib/nfe.rb CHANGED
@@ -1,2 +1,5 @@
1
+ require 'nfe/xml'
2
+ require 'nfe/danfe'
3
+
1
4
  module Nfe
2
5
  end
@@ -0,0 +1,31 @@
1
+ require 'net/http/post/multipart'
2
+ require 'tmpdir'
3
+
4
+ module Nfe
5
+ class Danfe
6
+
7
+ def initialize(xml_or_file)
8
+ if File.exist?(xml_or_file)
9
+ @xml_or_file = xml_or_file
10
+ else
11
+ @xml_or_file = "#{Dir.tmpdir}/nota.xml"
12
+ File.open(@xml_or_file, 'w') do |file|
13
+ file.write(xml_or_file)
14
+ end
15
+ end
16
+ end
17
+
18
+ def pdf
19
+ return @pdf if @pdf
20
+
21
+ url = URI('http://freenfe.com.br/danfe/?view=1')
22
+
23
+ http = Net::HTTP.new(url.host, url.port)
24
+ req = Net::HTTP::Post::Multipart.new url.request_uri, nota: UploadIO.new(@xml_or_file, 'text/xml', 'nota.xml')
25
+
26
+ request = http.request(req)
27
+ @pdf = request.body
28
+ end
29
+
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module Nfe
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -20,4 +20,5 @@ Gem::Specification.new do |spec|
20
20
  spec.require_paths = ['lib']
21
21
 
22
22
  spec.add_dependency 'nokogiri', '~> 1.5'
23
+ spec.add_dependency 'multipart-post', '~> 2.0.0', '>= 2.0.0'
23
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nfe-xml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luis Tofoli
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-09 00:00:00.000000000 Z
11
+ date: 2016-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -24,6 +24,26 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: multipart-post
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.0
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 2.0.0
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: 2.0.0
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 2.0.0
27
47
  description: API to validate the signature of an XML of NF-e
28
48
  email:
29
49
  - tofoli.luis@gmail.com
@@ -38,9 +58,11 @@ files:
38
58
  - README.md
39
59
  - Rakefile
40
60
  - bin/console
61
+ - bin/generate
41
62
  - bin/setup
42
63
  - bin/validate
43
64
  - lib/nfe.rb
65
+ - lib/nfe/danfe.rb
44
66
  - lib/nfe/version.rb
45
67
  - lib/nfe/web_service/search_result.rb
46
68
  - lib/nfe/xml.rb