nfeplace-client 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +9 -5
- data/spec/lib/nfedobrasil_spec.rb +24 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/support/certificate.p12 +0 -0
- metadata +51 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a11db98db9c51b6506abade778098f57551c8a2
|
4
|
+
data.tar.gz: 6ae447dd2290fed4d967ccad5dd27bdf8dcde5bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f81578a583cf195d1d58e660497d22234d4e651e1333ff49ef2d2d465c8de8a22a24990f39d3cbb4b171a5c9c56c208a907f805e5a36e466627af3f140db5b1e
|
7
|
+
data.tar.gz: a1ce96bbc6983ce96cef8a108601ec50a37933be472efa726d5e04080faf932e3e92fdedc9c8e67174c352f5b99f658a2a48721277fef055768bd9401a9416fb
|
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
@@ -5,19 +5,23 @@ require 'nfedobrasil/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'nfeplace-client'
|
8
|
-
spec.version = '0.0
|
8
|
+
spec.version = '0.1.0'
|
9
9
|
spec.authors = ['Edson Lima','Paulo Gomes', 'Diogo Tozzi']
|
10
10
|
spec.email = ['dddwebdeveloper@gmail.com', 'pv.gomes89@gmail.com', 'diogo.tozzi@natue.com.br']
|
11
11
|
spec.summary = %q{Gem to interact with NFEPlace SOAP API.}
|
12
12
|
spec.description = %q{Gem to interact with NFEPlace SOAP API. Enables creation, consultation and import of invoices.}
|
13
13
|
spec.homepage = 'https://github.com/natuelabs/nfeplace-client'
|
14
|
-
spec.license =
|
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: nfeplace-client
|
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
|
- Edson Lima
|
@@ -12,6 +12,20 @@ bindir: bin
|
|
12
12
|
cert_chain: []
|
13
13
|
date: 2018-09-20 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: savon
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - "~>"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.11.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - "~>"
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: 2.11.1
|
15
29
|
- !ruby/object:Gem::Dependency
|
16
30
|
name: bundler
|
17
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -40,6 +54,34 @@ dependencies:
|
|
40
54
|
- - "~>"
|
41
55
|
- !ruby/object:Gem::Version
|
42
56
|
version: '10.0'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: rspec
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 3.2.0
|
64
|
+
type: :development
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - "~>"
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 3.2.0
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: simplecov
|
73
|
+
requirement: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - "~>"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0.10'
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - "~>"
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0.10'
|
43
85
|
description: Gem to interact with NFEPlace SOAP API. Enables creation, consultation
|
44
86
|
and import of invoices.
|
45
87
|
email:
|
@@ -56,8 +98,12 @@ files:
|
|
56
98
|
- README.md
|
57
99
|
- Rakefile
|
58
100
|
- lib/nfedobrasil.rb
|
101
|
+
- lib/nfedobrasil/monkey_patches.rb
|
59
102
|
- lib/nfedobrasil/version.rb
|
60
103
|
- nfedobrasil.gemspec
|
104
|
+
- spec/lib/nfedobrasil_spec.rb
|
105
|
+
- spec/spec_helper.rb
|
106
|
+
- spec/support/certificate.p12
|
61
107
|
homepage: https://github.com/natuelabs/nfeplace-client
|
62
108
|
licenses:
|
63
109
|
- MIT
|
@@ -82,4 +128,7 @@ rubygems_version: 2.2.2
|
|
82
128
|
signing_key:
|
83
129
|
specification_version: 4
|
84
130
|
summary: Gem to interact with NFEPlace SOAP API.
|
85
|
-
test_files:
|
131
|
+
test_files:
|
132
|
+
- spec/lib/nfedobrasil_spec.rb
|
133
|
+
- spec/spec_helper.rb
|
134
|
+
- spec/support/certificate.p12
|