nfedobrasil 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -2
- data/Rakefile +10 -1
- data/lib/nfedobrasil.rb +14 -3
- data/lib/nfedobrasil/monkey_patches.rb +59 -0
- data/lib/nfedobrasil/version.rb +2 -2
- data/nfedobrasil.gemspec +13 -9
- data/spec/lib/nfedobrasil_spec.rb +24 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/support/certificate.p12 +0 -0
- metadata +52 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20a10e8c7e6a1004e4802a8d7e6b58ff54ff0d94
|
4
|
+
data.tar.gz: ce55f2ff9ccbf6cad174a60dba72f51333c258fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79e4edf72f750d8da29471d4e8f46fc9fb45d787b8220e294709f0742cdcb4fec137e5c617207fdf99e42feb52ed00d7f0c7e1f2f7c46c52b05ce140e274abcf
|
7
|
+
data.tar.gz: 5a4351c0b9851d83304250a793243dd02a4ade019f54a32931bb635b9d2cb4b51099178dcf955083bca63afb5b76f934b42bbca62b4b2655c8635b8dfcc24e50
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# NfedoBrasil
|
2
2
|
|
3
3
|
Gem to interact with NFEdoBrasil SOAP API.
|
4
4
|
|
@@ -20,7 +20,23 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
|
23
|
+
This gem is just a wrapper around [Savon](http://savonrb.com/) which [monkey
|
24
|
+
patches](https://en.wikipedia.org/wiki/Monkey_patch) (yes... I know =[) both Savon and
|
25
|
+
[HTTPI](http://httpirb.com/) so that they can work with P12 authentication
|
26
|
+
required by NFEdoBrasil.
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
require 'nfedobrasil'
|
30
|
+
# For dev mode access:
|
31
|
+
client = NfedoBrasil.client({ssl_plcs_file: './hml_natue.p12', ssl_plcs_password: 'y7bYntT3F'}, true)
|
32
|
+
|
33
|
+
# For production access:
|
34
|
+
client = NfedoBrasil.client({ssl_plcs_file: './hml_natue.p12', ssl_plcs_password: 'y7bYntT3F'})
|
35
|
+
|
36
|
+
# Now just consume the API using Savon
|
37
|
+
client.operations
|
38
|
+
# => [:enviar, :analisa_n_fe, :consultar, :consulta_token, :cancelar, :carta_correcao, :inutilizar, :consultar_cadastro_sefaz, :consultar_nota_sefaz, :status_servico, :retorna_danfe, :retorna_chaves, :retorna_xmls, :insere_emissor, :insere_armazenamento, :existe_emissor, :existe_armazenamento]
|
39
|
+
```
|
24
40
|
|
25
41
|
## Contributing
|
26
42
|
|
data/Rakefile
CHANGED
data/lib/nfedobrasil.rb
CHANGED
@@ -1,5 +1,16 @@
|
|
1
|
-
require
|
1
|
+
require 'savon'
|
2
|
+
require_relative 'nfedobrasil/monkey_patches'
|
3
|
+
require_relative 'nfedobrasil/version'
|
2
4
|
|
3
|
-
module
|
4
|
-
|
5
|
+
module NfedoBrasil
|
6
|
+
def self.client(config = {}, dev_mode = false)
|
7
|
+
config = {
|
8
|
+
wsdl: (dev_mode ?
|
9
|
+
'https://dev.sistema.nfeplace.com.br/services/emissor?wsdl' :
|
10
|
+
'https://sistema.nfeplace.com.br/services/emissor?wsdl'),
|
11
|
+
ssl_verify_mode: :none
|
12
|
+
}.merge config
|
13
|
+
|
14
|
+
Savon.client config
|
15
|
+
end
|
5
16
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# Add P12 support for savon
|
2
|
+
# Inspiration: https://gist.github.com/phaus/3313756
|
3
|
+
module Savon
|
4
|
+
class GlobalOptions
|
5
|
+
def ssl_plcs_file(ssl_plcs_file)
|
6
|
+
@options[:ssl_plcs_file] = ssl_plcs_file
|
7
|
+
end
|
8
|
+
|
9
|
+
def ssl_plcs_password(ssl_plcs_password)
|
10
|
+
@options[:ssl_plcs_password] = ssl_plcs_password
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class HTTPRequest
|
15
|
+
def configure_ssl
|
16
|
+
@http_request.auth.ssl.ssl_version = @globals[:ssl_version] if @globals.include? :ssl_version
|
17
|
+
@http_request.auth.ssl.verify_mode = @globals[:ssl_verify_mode] if @globals.include? :ssl_verify_mode
|
18
|
+
|
19
|
+
@http_request.auth.ssl.cert_key_file = @globals[:ssl_cert_key_file] if @globals.include? :ssl_cert_key_file
|
20
|
+
@http_request.auth.ssl.cert_key = @globals[:ssl_cert_key] if @globals.include? :ssl_cert_key
|
21
|
+
@http_request.auth.ssl.cert_file = @globals[:ssl_cert_file] if @globals.include? :ssl_cert_file
|
22
|
+
@http_request.auth.ssl.cert = @globals[:ssl_cert] if @globals.include? :ssl_cert
|
23
|
+
@http_request.auth.ssl.ca_cert_file = @globals[:ssl_ca_cert_file] if @globals.include? :ssl_ca_cert_file
|
24
|
+
@http_request.auth.ssl.ca_cert = @globals[:ssl_ca_cert] if @globals.include? :ssl_ca_cert
|
25
|
+
|
26
|
+
@http_request.auth.ssl.cert_key_password = @globals[:ssl_cert_key_password] if @globals.include? :ssl_cert_key_password
|
27
|
+
|
28
|
+
if (@globals.include?(:ssl_plcs_file) and @globals.include?(:ssl_plcs_password))
|
29
|
+
@http_request.auth.ssl.plcs_file @globals[:ssl_plcs_file], @globals[:ssl_plcs_password]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
module HTTPI
|
36
|
+
module Auth
|
37
|
+
class SSL
|
38
|
+
def plcs_file(file, password)
|
39
|
+
@pkcs12 = OpenSSL::PKCS12.new(File.read(file), password)
|
40
|
+
end
|
41
|
+
|
42
|
+
def cert
|
43
|
+
if @pkcs12
|
44
|
+
@cert ||= @pkcs12.certificate
|
45
|
+
else
|
46
|
+
@cert ||= (OpenSSL::X509::Certificate.new File.read(cert_file) if cert_file)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def cert_key
|
51
|
+
if @pkcs12
|
52
|
+
@cert_key ||= @pkcs12.key
|
53
|
+
else
|
54
|
+
@cert_key ||= (OpenSSL::PKey.read(File.read(cert_key_file), cert_key_password) if cert_key_file)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/nfedobrasil/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module
|
2
|
-
VERSION =
|
1
|
+
module NfedoBrasil
|
2
|
+
VERSION = '0.1.0'
|
3
3
|
end
|
data/nfedobrasil.gemspec
CHANGED
@@ -4,20 +4,24 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'nfedobrasil/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
8
|
-
spec.version =
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
7
|
+
spec.name = 'nfedobrasil'
|
8
|
+
spec.version = NfedoBrasil::VERSION
|
9
|
+
spec.authors = ['Eduardo Sampaio']
|
10
|
+
spec.email = ['eduardo@sampa.io']
|
11
11
|
spec.summary = %q{Gem to interact with NFEdoBrasil SOAP API.}
|
12
12
|
spec.description = %q{Gem to interact with NFEdoBrasil SOAP API. Enables creation, consultation and import of invoices.}
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
13
|
+
spec.homepage = 'https://github.com/natuelabs/nfedobrasil'
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.
|
22
|
-
|
21
|
+
spec.add_dependency 'savon', '~> 2.11.1'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.2.0'
|
26
|
+
spec.add_development_dependency 'simplecov', '~> 0.10'
|
23
27
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NfedoBrasil do
|
4
|
+
describe '#client' do
|
5
|
+
subject { NfedoBrasil.client({ssl_plcs_file: File.dirname(__FILE__) + '/../support/certificate.p12', ssl_plcs_password: 'nughee1O'}) }
|
6
|
+
|
7
|
+
it 'returns a Savon client' do
|
8
|
+
expect(subject).to be_a Savon::Client
|
9
|
+
expect(subject.globals[:wsdl]).to match(/https:\/\/sistema/)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'fails because cert is invalid' do
|
13
|
+
expect{subject.operations}.to raise_error(HTTPI::SSLError)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'dev mode' do
|
18
|
+
subject { NfedoBrasil.client({ssl_plcs_file: File.dirname(__FILE__) + '/../support/certificate.p12', ssl_plcs_password: 'nughee1O'}, true) }
|
19
|
+
|
20
|
+
it 'handles dev mode properly' do
|
21
|
+
expect(subject.globals[:wsdl]).to match(/https:\/\/dev.sistema/)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
|
3
|
+
SimpleCov.start do
|
4
|
+
add_filter '/spec'
|
5
|
+
end if ENV['COVERAGE']
|
6
|
+
|
7
|
+
require File.expand_path('../../lib/nfedobrasil', __FILE__)
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.expect_with :rspec do |c|
|
11
|
+
c.syntax = :expect
|
12
|
+
end
|
13
|
+
|
14
|
+
config.order = 'random'
|
15
|
+
end
|
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nfedobrasil
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eduardo Sampaio
|
@@ -10,6 +10,20 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2015-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: savon
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.11.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.11.1
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +52,34 @@ dependencies:
|
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.2.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.2.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.10'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.10'
|
41
83
|
description: Gem to interact with NFEdoBrasil SOAP API. Enables creation, consultation
|
42
84
|
and import of invoices.
|
43
85
|
email:
|
@@ -52,8 +94,12 @@ files:
|
|
52
94
|
- README.md
|
53
95
|
- Rakefile
|
54
96
|
- lib/nfedobrasil.rb
|
97
|
+
- lib/nfedobrasil/monkey_patches.rb
|
55
98
|
- lib/nfedobrasil/version.rb
|
56
99
|
- nfedobrasil.gemspec
|
100
|
+
- spec/lib/nfedobrasil_spec.rb
|
101
|
+
- spec/spec_helper.rb
|
102
|
+
- spec/support/certificate.p12
|
57
103
|
homepage: https://github.com/natuelabs/nfedobrasil
|
58
104
|
licenses:
|
59
105
|
- MIT
|
@@ -74,8 +120,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
120
|
version: '0'
|
75
121
|
requirements: []
|
76
122
|
rubyforge_project:
|
77
|
-
rubygems_version: 2.
|
123
|
+
rubygems_version: 2.4.5
|
78
124
|
signing_key:
|
79
125
|
specification_version: 4
|
80
126
|
summary: Gem to interact with NFEdoBrasil SOAP API.
|
81
|
-
test_files:
|
127
|
+
test_files:
|
128
|
+
- spec/lib/nfedobrasil_spec.rb
|
129
|
+
- spec/spec_helper.rb
|
130
|
+
- spec/support/certificate.p12
|