correios_sigep 0.5.0 → 1.0.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 +5 -13
- data/.rubocop.yml +1155 -2
- data/.travis.yml +4 -4
- data/README.md +2 -3
- data/correios_sigep.gemspec +3 -2
- data/lib/correios_sigep.rb +0 -1
- data/lib/correios_sigep/builders/xml/collect_objects.rb +4 -4
- data/lib/correios_sigep/builders/xml/request.rb +30 -7
- data/lib/correios_sigep/builders/xml/request_collect_number.rb +5 -0
- data/lib/correios_sigep/configuration.rb +3 -3
- data/lib/correios_sigep/logistic_reverse/base_client.rb +7 -4
- data/lib/correios_sigep/logistic_reverse/request_sro.rb +1 -1
- data/lib/correios_sigep/models/administrative_fields.rb +1 -2
- data/lib/correios_sigep/models/sro.rb +2 -2
- data/lib/correios_sigep/version.rb +1 -1
- data/spec/correios_sigep/builders/xml/request_collect_number_spec.rb +1 -1
- data/spec/correios_sigep/builders/xml/request_spec.rb +2 -13
- data/spec/correios_sigep/builders/xml/request_sro_spec.rb +2 -2
- data/spec/correios_sigep/configuration_spec.rb +23 -33
- data/spec/correios_sigep/logistic_reverse/base_client_spec.rb +10 -4
- data/spec/correios_sigep/logistic_reverse/request_collect_number_spec.rb +18 -11
- data/spec/correios_sigep/logistic_reverse/request_sro_spec.rb +18 -11
- data/spec/correios_sigep_spec.rb +0 -14
- data/spec/fixtures/builders/request_collect_number.xml +1 -2
- data/spec/fixtures/builders/request_sro.xml +1 -2
- data/spec/fixtures/correios/request_sro/response_array_success.xml +2 -2
- data/spec/fixtures/correios/request_sro/response_collect_number_not_found.xml +2 -2
- data/spec/fixtures/correios/request_sro/response_required_fields.xml +2 -2
- data/spec/fixtures/correios/request_sro/response_sro_not_ready.xml +2 -2
- data/spec/fixtures/correios/request_sro/response_success.xml +2 -2
- data/spec/fixtures/correios/request_sro/response_unknown_error.xml +2 -2
- data/spec/fixtures/correios/wsdl.xml +650 -188
- data/spec/fixtures/requests/collect_number_request.xml +2 -2
- data/spec/fixtures/requests/sro_request.xml +1 -1
- data/spec/spec_helper.rb +2 -3
- metadata +48 -37
- data/lib/correios_sigep/builders/xml/authentication.rb +0 -37
- data/spec/fixtures/correios/wsdl_test.xml +0 -616
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -34,11 +34,10 @@ Para utilizar a gem, é necessário configurar os campos necessários com base n
|
|
34
34
|
|
35
35
|
```ruby
|
36
36
|
CorreiosSigep.configure do |config|
|
37
|
-
config.user = '
|
38
|
-
config.password = '
|
37
|
+
config.user = 'empresacws'
|
38
|
+
config.password = '123456'
|
39
39
|
config.administrative_code = '08082650'
|
40
40
|
config.card = '0057018901'
|
41
|
-
config.contract = '9912208555'
|
42
41
|
config.service_code = '41076'
|
43
42
|
end
|
44
43
|
```
|
data/correios_sigep.gemspec
CHANGED
@@ -20,12 +20,13 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_dependency 'net-http-persistent', '~> 2.9.4'
|
22
22
|
spec.add_dependency 'rack', '~> 1.6', '>= 1.6.4'
|
23
|
-
spec.add_dependency 'savon', '~> 2.
|
23
|
+
spec.add_dependency 'savon', '~> 2.11'
|
24
24
|
|
25
25
|
spec.add_development_dependency 'bundler', '~> 1.7'
|
26
|
+
spec.add_development_dependency 'pry', '~> 0.10'
|
26
27
|
spec.add_development_dependency 'coveralls'
|
27
28
|
spec.add_development_dependency 'rake', '~> 10.0'
|
28
29
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
29
30
|
spec.add_development_dependency 'simplecov', '~> 0.9'
|
30
|
-
spec.add_development_dependency 'webmock', '~>
|
31
|
+
spec.add_development_dependency 'webmock', '~> 2.3'
|
31
32
|
end
|
data/lib/correios_sigep.rb
CHANGED
@@ -15,7 +15,6 @@ require 'correios_sigep/builders/xml/sender'
|
|
15
15
|
require 'correios_sigep/builders/xml/product'
|
16
16
|
require 'correios_sigep/builders/xml/collect_objects'
|
17
17
|
require 'correios_sigep/builders/xml/collect'
|
18
|
-
require 'correios_sigep/builders/xml/authentication'
|
19
18
|
require 'correios_sigep/builders/xml/request'
|
20
19
|
require 'correios_sigep/builders/xml/request_collect_number'
|
21
20
|
require 'correios_sigep/builders/xml/request_sro'
|
@@ -17,11 +17,11 @@ module CorreiosSigep
|
|
17
17
|
|
18
18
|
private
|
19
19
|
def build_item(object)
|
20
|
-
@builder.item
|
21
|
-
@builder.id
|
22
|
-
@builder.desc
|
20
|
+
@builder.item object.item
|
21
|
+
@builder.id object.id
|
22
|
+
@builder.desc object.description
|
23
23
|
@builder.entrega object.ship
|
24
|
-
@builder.num
|
24
|
+
@builder.num object.num
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -3,18 +3,41 @@ module CorreiosSigep
|
|
3
3
|
module XML
|
4
4
|
class Request
|
5
5
|
|
6
|
-
def
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
def initialize(document, overrides={})
|
7
|
+
@document = Nokogiri::XML(document.to_xml)
|
8
|
+
config = CorreiosSigep.configuration
|
9
|
+
|
10
|
+
administrative_fields!( overrides[:administrative] ||
|
11
|
+
config.administrative_fields )
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
+
def administrative_fields!(administrative_fields)
|
15
|
+
add_node 'codAdministrativo', administrative_fields.administrative_code
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_xml
|
19
|
+
@document
|
14
20
|
.to_xml(save_with: Nokogiri::XML::Node::SaveOptions::NO_DECLARATION)
|
15
21
|
.gsub(/<(\/)?root>/, '')
|
16
22
|
end
|
17
23
|
|
24
|
+
def self.build_xml(request, overrides={})
|
25
|
+
new(request, overrides).to_xml
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def add_node(node_name, node_content)
|
31
|
+
@document.root.children.first.add_previous_sibling(
|
32
|
+
create_node(node_name, node_content)
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
def create_node(node_name, node_content)
|
37
|
+
node = Nokogiri::XML::Node.new(node_name, @document)
|
38
|
+
node.content = node_content
|
39
|
+
node
|
40
|
+
end
|
18
41
|
end
|
19
42
|
end
|
20
43
|
end
|
@@ -2,6 +2,11 @@ module CorreiosSigep
|
|
2
2
|
module Builders
|
3
3
|
module XML
|
4
4
|
class RequestCollectNumber < Request
|
5
|
+
def administrative_fields!(administrative_fields)
|
6
|
+
add_node 'codAdministrativo', administrative_fields.administrative_code
|
7
|
+
add_node 'codigo_servico', administrative_fields.service_code
|
8
|
+
add_node 'cartao', administrative_fields.card
|
9
|
+
end
|
5
10
|
end
|
6
11
|
end
|
7
12
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
module CorreiosSigep
|
2
2
|
class Configuration
|
3
|
-
attr_accessor :administrative_code, :card, :
|
4
|
-
:
|
3
|
+
attr_accessor :administrative_code, :card, :service_code, :wsdl_base_url,
|
4
|
+
:proxy, :timeout, :user, :password
|
5
5
|
|
6
6
|
def administrative_fields
|
7
7
|
@administrative_fields ||=
|
8
8
|
Models::AdministrativeFields.new(administrative_code: administrative_code,
|
9
|
-
card: card,
|
9
|
+
card: card,
|
10
10
|
service_code: service_code)
|
11
11
|
|
12
12
|
end
|
@@ -4,14 +4,17 @@ module CorreiosSigep
|
|
4
4
|
DEFAULT_TIMEOUT = 30
|
5
5
|
|
6
6
|
def initialize
|
7
|
-
timeout
|
7
|
+
timeout = CorreiosSigep.configuration.timeout || DEFAULT_TIMEOUT
|
8
|
+
user = CorreiosSigep.configuration.user
|
9
|
+
password = CorreiosSigep.configuration.password
|
8
10
|
|
9
11
|
options = {
|
10
12
|
adapter: :net_http_persistent,
|
11
13
|
proxy: CorreiosSigep.configuration.proxy,
|
12
14
|
wsdl: wsdl,
|
13
15
|
open_timeout: timeout,
|
14
|
-
read_timeout: timeout
|
16
|
+
read_timeout: timeout,
|
17
|
+
basic_auth: [user, password]
|
15
18
|
}
|
16
19
|
options.delete(:proxy) unless options[:proxy]
|
17
20
|
|
@@ -22,9 +25,9 @@ module CorreiosSigep
|
|
22
25
|
|
23
26
|
def wsdl
|
24
27
|
@wsdl ||= if ENV['GEM_ENV'] == 'test'
|
25
|
-
'
|
28
|
+
'https://apphom.correios.com.br/logisticaReversaWS/logisticaReversaService/logisticaReversaWS?wsdl'
|
26
29
|
else
|
27
|
-
'
|
30
|
+
'https://cws.correios.com.br/logisticaReversaWS/logisticaReversaService/logisticaReversaWS?wsdl'
|
28
31
|
end
|
29
32
|
end
|
30
33
|
|
@@ -14,7 +14,7 @@ module CorreiosSigep
|
|
14
14
|
|
15
15
|
private
|
16
16
|
def process_response response
|
17
|
-
correios_hash = response.body[:acompanhar_pedido_response][:
|
17
|
+
correios_hash = response.body[:acompanhar_pedido_response][:acompanhar_pedido]
|
18
18
|
check_sro_errors(correios_hash)
|
19
19
|
correios_response(correios_hash[:coleta][:objeto])[:numero_etiqueta] || begin raise Models::Errors::SRONotReady; end
|
20
20
|
end
|
@@ -1,12 +1,11 @@
|
|
1
1
|
module CorreiosSigep
|
2
2
|
module Models
|
3
3
|
class AdministrativeFields
|
4
|
-
attr_accessor :administrative_code, :card, :
|
4
|
+
attr_accessor :administrative_code, :card, :service_code
|
5
5
|
|
6
6
|
def initialize(options={})
|
7
7
|
self.administrative_code = options[:administrative_code]
|
8
8
|
self.card = options[:card]
|
9
|
-
self.contract = options[:contract]
|
10
9
|
self.service_code = options[:service_code]
|
11
10
|
end
|
12
11
|
end
|
@@ -10,11 +10,11 @@ module CorreiosSigep
|
|
10
10
|
|
11
11
|
def to_xml
|
12
12
|
builder = Nokogiri::XML::Builder.new do |xml|
|
13
|
-
xml.root
|
13
|
+
xml.root do
|
14
14
|
xml.tipoBusca('H')
|
15
15
|
xml.tipoSolicitacao(@type)
|
16
16
|
xml.numeroPedido(@collect_number)
|
17
|
-
|
17
|
+
end
|
18
18
|
end
|
19
19
|
builder.to_xml
|
20
20
|
end
|
@@ -5,7 +5,7 @@ module CorreiosSigep
|
|
5
5
|
module XML
|
6
6
|
describe RequestCollectNumber do
|
7
7
|
describe '.build_xml' do
|
8
|
-
subject { described_class.build_xml(logistic_reverse) }
|
8
|
+
subject { described_class.build_xml(logistic_reverse).chop }
|
9
9
|
|
10
10
|
let(:logistic_reverse) { CorreiosSigep::Models::LogisticReverse.new }
|
11
11
|
let(:expected_xml) { builders_fixture('request_collect_number.xml') }
|
@@ -9,12 +9,7 @@ module CorreiosSigep
|
|
9
9
|
context 'when do not override anything' do
|
10
10
|
it 'builds a Authentication XML with Configuration parameters' do
|
11
11
|
expected_response = [
|
12
|
-
'<
|
13
|
-
'<codigo_servico>41076</codigo_servico>',
|
14
|
-
'<contrato>9912208555</contrato>',
|
15
|
-
'<codAdministrativo>08082650</codAdministrativo>',
|
16
|
-
'<senha>8o8otn</senha>',
|
17
|
-
'<usuario>60618043</usuario><test/>'
|
12
|
+
'<codAdministrativo>08082650</codAdministrativo><test/>'
|
18
13
|
].join + "\n"
|
19
14
|
expect(described_class.build_xml request).to eq expected_response
|
20
15
|
end
|
@@ -24,15 +19,9 @@ module CorreiosSigep
|
|
24
19
|
it 'builds a Authentication XML with the override parameter' do
|
25
20
|
administrative_fields = Models::AdministrativeFields.new(administrative_code: 'adm123',
|
26
21
|
card: 'card123',
|
27
|
-
contract: 'cont123',
|
28
22
|
service_code: 'ser123')
|
29
23
|
expected_response = [
|
30
|
-
'<
|
31
|
-
'<codigo_servico>ser123</codigo_servico>',
|
32
|
-
'<contrato>cont123</contrato>',
|
33
|
-
'<codAdministrativo>adm123</codAdministrativo>',
|
34
|
-
'<senha>8o8otn</senha>',
|
35
|
-
'<usuario>60618043</usuario><test/>'
|
24
|
+
'<codAdministrativo>adm123</codAdministrativo><test/>'
|
36
25
|
].join + "\n"
|
37
26
|
expect(described_class.build_xml request, administrative: administrative_fields).to eq expected_response
|
38
27
|
end
|
@@ -3,13 +3,13 @@ module CorreiosSigep
|
|
3
3
|
module XML
|
4
4
|
describe RequestSRO do
|
5
5
|
describe '.build_xml' do
|
6
|
-
subject { described_class.build_xml(sro) }
|
6
|
+
subject { described_class.build_xml(sro).chop }
|
7
7
|
|
8
8
|
let(:sro_params) { { collect_number: '1234', type: 'A' } }
|
9
9
|
let(:sro) { CorreiosSigep::Models::SRO.new(sro_params) }
|
10
10
|
let(:expected_xml) { builders_fixture('request_sro.xml') }
|
11
11
|
|
12
|
-
it {
|
12
|
+
it { should eq expected_xml }
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -28,43 +28,29 @@ module CorreiosSigep
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
describe '#
|
32
|
-
it 'returns nil when unset' do
|
33
|
-
expect(subject.contract).to be_nil
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe '#contract=' do
|
38
|
-
it 'sets the contract in configuration' do
|
39
|
-
subject.contract = 'contract'
|
40
|
-
expect(subject.contract).to eq 'contract'
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe '#password' do
|
31
|
+
describe '#service_code' do
|
45
32
|
it 'returns nil when unset' do
|
46
|
-
expect(subject.
|
33
|
+
expect(subject.service_code).to be_nil
|
47
34
|
end
|
48
35
|
end
|
49
36
|
|
50
|
-
describe '#
|
37
|
+
describe '#service_code=' do
|
51
38
|
it 'sets the password in configuration' do
|
52
|
-
subject.
|
53
|
-
expect(subject.
|
39
|
+
subject.service_code = 'service_code'
|
40
|
+
expect(subject.service_code).to eq 'service_code'
|
54
41
|
end
|
55
42
|
end
|
56
43
|
|
57
|
-
|
58
|
-
describe '#service_code' do
|
44
|
+
describe '#timeout' do
|
59
45
|
it 'returns nil when unset' do
|
60
|
-
expect(subject.
|
46
|
+
expect(subject.timeout).to be_nil
|
61
47
|
end
|
62
48
|
end
|
63
49
|
|
64
|
-
describe '#
|
65
|
-
it 'sets the
|
66
|
-
subject.
|
67
|
-
expect(subject.
|
50
|
+
describe '#timeout=' do
|
51
|
+
it 'sets the timeout in configuration' do
|
52
|
+
subject.timeout = 15
|
53
|
+
expect(subject.timeout).to eq 15
|
68
54
|
end
|
69
55
|
end
|
70
56
|
|
@@ -75,22 +61,26 @@ module CorreiosSigep
|
|
75
61
|
end
|
76
62
|
|
77
63
|
describe '#user=' do
|
64
|
+
let(:user) { 'user' }
|
65
|
+
|
78
66
|
it 'sets the user in configuration' do
|
79
|
-
subject.user =
|
80
|
-
expect(subject.user).to eq
|
67
|
+
subject.user = user
|
68
|
+
expect(subject.user).to eq user
|
81
69
|
end
|
82
70
|
end
|
83
71
|
|
84
|
-
describe '#
|
72
|
+
describe '#password' do
|
85
73
|
it 'returns nil when unset' do
|
86
|
-
expect(subject.
|
74
|
+
expect(subject.password).to be_nil
|
87
75
|
end
|
88
76
|
end
|
89
77
|
|
90
|
-
describe '#
|
91
|
-
|
92
|
-
|
93
|
-
|
78
|
+
describe '#password=' do
|
79
|
+
let(:pass) { 'pass' }
|
80
|
+
|
81
|
+
it 'sets the password in configuration' do
|
82
|
+
subject.password = pass
|
83
|
+
expect(subject.password).to eq pass
|
94
84
|
end
|
95
85
|
end
|
96
86
|
end
|
@@ -3,6 +3,9 @@ require 'spec_helper'
|
|
3
3
|
module CorreiosSigep
|
4
4
|
module LogisticReverse
|
5
5
|
describe BaseClient do
|
6
|
+
let(:user) { CorreiosSigep.configuration.user }
|
7
|
+
let(:pass) { CorreiosSigep.configuration.password }
|
8
|
+
|
6
9
|
context 'setting up a proxy' do
|
7
10
|
subject { described_class.new }
|
8
11
|
|
@@ -15,6 +18,7 @@ module CorreiosSigep
|
|
15
18
|
wsdl: described_class.new.wsdl,
|
16
19
|
open_timeout: CorreiosSigep::LogisticReverse::BaseClient::DEFAULT_TIMEOUT,
|
17
20
|
read_timeout: CorreiosSigep::LogisticReverse::BaseClient::DEFAULT_TIMEOUT,
|
21
|
+
basic_auth: [user, pass],
|
18
22
|
headers: { 'SOAPAction' => '' }
|
19
23
|
}
|
20
24
|
end
|
@@ -33,6 +37,7 @@ module CorreiosSigep
|
|
33
37
|
wsdl: described_class.new.wsdl,
|
34
38
|
open_timeout: CorreiosSigep::LogisticReverse::BaseClient::DEFAULT_TIMEOUT,
|
35
39
|
read_timeout: CorreiosSigep::LogisticReverse::BaseClient::DEFAULT_TIMEOUT,
|
40
|
+
basic_auth: [user, pass],
|
36
41
|
headers: { 'SOAPAction' => '' }
|
37
42
|
}
|
38
43
|
end
|
@@ -48,16 +53,16 @@ module CorreiosSigep
|
|
48
53
|
subject { described_class.new.wsdl }
|
49
54
|
|
50
55
|
context 'in a test environment' do
|
51
|
-
it '
|
56
|
+
it 'returns the staging url' do
|
52
57
|
allow(ENV).to receive(:[]).with('GEM_ENV').and_return 'test'
|
53
|
-
expect(subject).to eq '
|
58
|
+
expect(subject).to eq 'https://apphom.correios.com.br/logisticaReversaWS/logisticaReversaService/logisticaReversaWS?wsdl'
|
54
59
|
end
|
55
60
|
end
|
56
61
|
|
57
62
|
context 'in other environment' do
|
58
|
-
it '
|
63
|
+
it 'returns the production url' do
|
59
64
|
allow(ENV).to receive(:[]).with('GEM_ENV').and_return 'prod'
|
60
|
-
expect(subject).to eq '
|
65
|
+
expect(subject).to eq 'https://cws.correios.com.br/logisticaReversaWS/logisticaReversaService/logisticaReversaWS?wsdl'
|
61
66
|
end
|
62
67
|
end
|
63
68
|
|
@@ -73,6 +78,7 @@ module CorreiosSigep
|
|
73
78
|
wsdl: described_class.new.wsdl,
|
74
79
|
open_timeout: CorreiosSigep.configuration.timeout,
|
75
80
|
read_timeout: CorreiosSigep.configuration.timeout,
|
81
|
+
basic_auth: [user, pass],
|
76
82
|
headers: { 'SOAPAction' => '' }
|
77
83
|
}
|
78
84
|
end
|
@@ -3,25 +3,32 @@ require 'spec_helper'
|
|
3
3
|
module CorreiosSigep
|
4
4
|
module LogisticReverse
|
5
5
|
describe RequestCollectNumber do
|
6
|
-
let(:logistic_reverse)
|
7
|
-
let(:request_collect)
|
8
|
-
let(:body)
|
6
|
+
let(:logistic_reverse) { Models::LogisticReverse.new }
|
7
|
+
let(:request_collect) { described_class.new logistic_reverse }
|
8
|
+
let(:body) { request_fixture('collect_number_request.xml').chop }
|
9
|
+
let(:user) { 'user' }
|
10
|
+
let(:pass) { 'pass' }
|
9
11
|
|
10
12
|
before do
|
11
13
|
seed_logistic_reverse(logistic_reverse)
|
12
14
|
|
13
15
|
# WSDL
|
14
|
-
stub_request(:get,
|
15
|
-
with(:
|
16
|
-
|
16
|
+
stub_request(:get, 'https://apphom.correios.com.br/logisticaReversaWS/logisticaReversaService/logisticaReversaWS?wsdl').
|
17
|
+
with(basic_auth: [user, pass]).
|
18
|
+
with(:headers => {
|
19
|
+
'Accept'=>'*/*',
|
20
|
+
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
21
|
+
'User-Agent'=>'Ruby'
|
22
|
+
}).to_return(:status => 200, :body => correios_fixture('wsdl.xml'), :headers => {})
|
17
23
|
|
18
24
|
# REQUEST
|
19
|
-
stub_request(:post,
|
20
|
-
|
25
|
+
stub_request(:post, 'https://apphom.correios.com.br/logisticaReversaWS/logisticaReversaService/logisticaReversaWS').
|
26
|
+
with(basic_auth: [user, pass]).
|
27
|
+
with(:body => body, :headers => {
|
28
|
+
'Accept'=>'*/*',
|
21
29
|
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
22
|
-
'
|
23
|
-
|
24
|
-
to_return(:status => 200, :body => correios_fixture("request_collect_number/#{response_body}"), :headers => {})
|
30
|
+
'User-Agent'=>'Ruby'
|
31
|
+
}).to_return(:status => 200, :body => correios_fixture("request_collect_number/#{response_body}"), :headers => {})
|
25
32
|
end
|
26
33
|
|
27
34
|
describe '.process' do
|