correios_sigep 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.travis.yml +1 -1
- data/README.md +1 -1
- data/lib/correios_sigep.rb +4 -0
- data/lib/correios_sigep/builders/xml/authentication.rb +1 -1
- data/lib/correios_sigep/builders/xml/request_collect_number.rb +5 -3
- data/lib/correios_sigep/builders/xml/request_sro.rb +19 -0
- data/lib/correios_sigep/logistic_reverse/base_client.rb +5 -2
- data/lib/correios_sigep/logistic_reverse/request_collect_number.rb +12 -9
- data/lib/correios_sigep/logistic_reverse/request_sro.rb +28 -0
- data/lib/correios_sigep/models/errors/sro_not_ready.rb +8 -0
- data/lib/correios_sigep/models/sro.rb +23 -0
- data/lib/correios_sigep/version.rb +1 -1
- data/spec/correios_sigep/builders/xml/request_sro_spec.rb +19 -0
- data/spec/correios_sigep/logistic_reverse/request_sro_spec.rb +64 -0
- data/spec/correios_sigep/models/sro_spec.rb +40 -0
- data/spec/spec_helper.rb +0 -1
- metadata +12 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YjA5NmI1OTJjZWQ3NTFjYTdmNDQ5ZDA1ZDMyYTdkNDM0MjdlNGJjZg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NDgwOGYxMmY0NDA0Yzg5YWM4ZWRhYzBkOWJhYWRmYTg3N2VkNjcxZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MWYwMDI0NGI2MmIyMmJkNTdlZmNmZjY4NDIxMmQxNTZlYTI3MzBjOTNkNzBj
|
10
|
+
MDBiNDU2Y2MwYTdkZjUzMmEyYTQ5MzM2MzcxNWY5YzNiZDkzNWE3OTZkNDZm
|
11
|
+
NzQ0ZjYwYjY2MzQ1MzQxMjU5MjMzM2YxOWM3Y2RkMjg3MzZiODc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YWZjOWZmMTg3OTkwNGJiZWMzYzA4MGRhNTU0NzI5ZmQyYjkyYjM3Y2I1MjUy
|
14
|
+
ZmRhYTBmYjY1ZGRjNGI5ZTE1ZWFiZmYwOTAwZjkxZGJiOTNjNDRjYmFlZjMx
|
15
|
+
YWRkMzdjMDMxOWUwY2NiYzRmYWYwZDhjY2Y2NTkxMGQ3MThhNzU=
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -4,7 +4,7 @@ CorreiosSigep
|
|
4
4
|
[![Build Status](https://travis-ci.org/duduribeiro/correios_sigep.svg?branch=master)](https://travis-ci.org/duduribeiro/correios_sigep)
|
5
5
|
|
6
6
|
- Integrador responsável pela comunicação com o SigepWeb - http://goo.gl/z8VJjJ.
|
7
|
-
-
|
7
|
+
- Excelente documentação do SigepWeb providenciada pelos Correios: http://goo.gl/6TWp2f :trollface:
|
8
8
|
- Atualmente a Gem faz somente uma solicitação de uma postagem de reversa (documentação, pág 36).
|
9
9
|
|
10
10
|
## Instalação
|
data/lib/correios_sigep.rb
CHANGED
@@ -7,6 +7,7 @@ require 'correios_sigep/builders/xml/collect_objects'
|
|
7
7
|
require 'correios_sigep/builders/xml/collect'
|
8
8
|
require 'correios_sigep/builders/xml/authentication'
|
9
9
|
require 'correios_sigep/builders/xml/request_collect_number'
|
10
|
+
require 'correios_sigep/builders/xml/request_sro'
|
10
11
|
require 'correios_sigep/models/recipient'
|
11
12
|
require 'correios_sigep/models/product'
|
12
13
|
require 'correios_sigep/models/recipient'
|
@@ -15,6 +16,7 @@ require 'correios_sigep/models/object'
|
|
15
16
|
require 'correios_sigep/models/sender'
|
16
17
|
require 'correios_sigep/models/collect'
|
17
18
|
require 'correios_sigep/models/logistic_reverse'
|
19
|
+
require 'correios_sigep/models/sro'
|
18
20
|
require 'correios_sigep/models/correios_response_codes'
|
19
21
|
require 'correios_sigep/models/errors/ticket_already_used'
|
20
22
|
require 'correios_sigep/models/errors/unavailable_service'
|
@@ -22,8 +24,10 @@ require 'correios_sigep/models/errors/inexistent_zipcode'
|
|
22
24
|
require 'correios_sigep/models/errors/unavailable_house_collect'
|
23
25
|
require 'correios_sigep/models/errors/collect_not_answered_for_the_zipcode'
|
24
26
|
require 'correios_sigep/models/errors/unknown_error'
|
27
|
+
require 'correios_sigep/models/errors/sro_not_ready'
|
25
28
|
require 'correios_sigep/logistic_reverse/base_client'
|
26
29
|
require 'correios_sigep/logistic_reverse/request_collect_number'
|
30
|
+
require 'correios_sigep/logistic_reverse/request_sro'
|
27
31
|
require 'nokogiri'
|
28
32
|
require 'savon'
|
29
33
|
|
@@ -4,9 +4,11 @@ module CorreiosSigep
|
|
4
4
|
class RequestCollectNumber
|
5
5
|
|
6
6
|
def self.build_xml(logistic_reverse)
|
7
|
-
document
|
8
|
-
XML::Authentication.new(document).build_xml
|
9
|
-
|
7
|
+
document = Nokogiri::XML(logistic_reverse.to_xml)
|
8
|
+
XML::Authentication.new(document).build_xml!
|
9
|
+
|
10
|
+
document
|
11
|
+
.to_xml(save_with: Nokogiri::XML::Node::SaveOptions::NO_DECLARATION)
|
10
12
|
.gsub(/<(\/)?root>/, '')
|
11
13
|
end
|
12
14
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module CorreiosSigep
|
2
|
+
module Builders
|
3
|
+
module XML
|
4
|
+
class RequestSRO
|
5
|
+
|
6
|
+
def self.build_xml(sro)
|
7
|
+
document = Nokogiri::XML(sro.to_xml)
|
8
|
+
XML::Authentication.new(document).build_xml!
|
9
|
+
|
10
|
+
document
|
11
|
+
.to_xml(save_with: Nokogiri::XML::Node::SaveOptions::NO_DECLARATION)
|
12
|
+
.gsub(/<(\/)?root>/, '')
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -14,8 +14,11 @@ module CorreiosSigep
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def invoke(method, message)
|
17
|
-
@client.instance_variable_set(
|
18
|
-
|
17
|
+
@client.instance_variable_set(
|
18
|
+
:@wsdl,
|
19
|
+
Wasabi::Document.new(CorreiosSigep.configuration.wsdl_base_url)
|
20
|
+
) if wsdl_base_url_changed?
|
21
|
+
|
19
22
|
@client.call(method, message: message)
|
20
23
|
end
|
21
24
|
|
@@ -14,7 +14,7 @@ module CorreiosSigep
|
|
14
14
|
|
15
15
|
private
|
16
16
|
|
17
|
-
def process_response
|
17
|
+
def process_response response
|
18
18
|
response_xml = response.to_xml.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
|
19
19
|
response_doc = Nokogiri::XML.parse(response_xml)
|
20
20
|
code = response_doc.search('//cod-erro | //cod_erro').text.to_i rescue nil
|
@@ -26,26 +26,29 @@ module CorreiosSigep
|
|
26
26
|
result_node = response_doc.search(result_string)
|
27
27
|
|
28
28
|
case code
|
29
|
-
|
30
29
|
when Models::CorreiosResponseCodes::SUCCESS
|
31
30
|
result = result_node.search('//numero-coleta | //numero_coleta')
|
32
|
-
|
33
|
-
|
34
|
-
end
|
31
|
+
result.first.text rescue nil
|
32
|
+
|
35
33
|
when Models::CorreiosResponseCodes::TICKET_ALREADY_USED
|
36
|
-
|
37
|
-
|
34
|
+
error_message = result_node.search('//msg_erro | //msg_erro').text
|
35
|
+
raise Models::Errors::TicketAlreadyUsed.new error_message
|
36
|
+
|
38
37
|
when Models::CorreiosResponseCodes::UNAVAILABLE_SERVICE
|
39
38
|
raise Models::Errors::UnavailableService
|
39
|
+
|
40
40
|
when Models::CorreiosResponseCodes::INEXISTENT_ZIPCODE
|
41
41
|
raise Models::Errors::InexistentZipcode
|
42
|
+
|
42
43
|
when Models::CorreiosResponseCodes::UNAVAILABLE_HOUSE_COLLECT
|
43
44
|
raise Models::Errors::UnavailableHouseCollect
|
45
|
+
|
44
46
|
when Models::CorreiosResponseCodes::COLLECT_NOT_ANSWERED_FOR_THE_ZIPCODE
|
45
47
|
raise Models::Errors::CollectNotAnsweredForTheZipcode
|
48
|
+
|
46
49
|
else
|
47
|
-
|
48
|
-
|
50
|
+
error_message = result_node.search('//msg_erro | //msg_erro').text
|
51
|
+
raise Models::Errors::UnknownError.new error_message
|
49
52
|
end
|
50
53
|
end
|
51
54
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module CorreiosSigep
|
2
|
+
module LogisticReverse
|
3
|
+
class RequestSRO < BaseClient
|
4
|
+
def initialize(sro)
|
5
|
+
@sro = sro
|
6
|
+
super()
|
7
|
+
end
|
8
|
+
|
9
|
+
def process
|
10
|
+
xml = Builders::XML::RequestSRO.build_xml(@sro)
|
11
|
+
process_response invoke(:acompanhar_pedido, xml)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
def process_response response
|
16
|
+
correios_hash = response.body[:acompanhar_pedido_response][:return]
|
17
|
+
|
18
|
+
case correios_hash[:cod_erro].to_i
|
19
|
+
when 0
|
20
|
+
correios_hash[:coleta][:objeto][:numero_etiqueta]
|
21
|
+
else
|
22
|
+
# TODO look for a descritpion of this weird error
|
23
|
+
raise Models::Errors::SRONotReady
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module CorreiosSigep
|
2
|
+
module Models
|
3
|
+
class SRO
|
4
|
+
attr_accessor :collect_number, :type
|
5
|
+
|
6
|
+
def initialize(options={})
|
7
|
+
@collect_number = options[:collect_number]
|
8
|
+
@type = options[:type]
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_xml
|
12
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
13
|
+
xml.root {
|
14
|
+
xml.tipoBusca('H')
|
15
|
+
xml.tipoSolicitacao(@type)
|
16
|
+
xml.numeroPedido(@collect_number)
|
17
|
+
}
|
18
|
+
end
|
19
|
+
builder.to_xml
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module CorreiosSigep
|
2
|
+
module Builders
|
3
|
+
module XML
|
4
|
+
describe RequestSRO do
|
5
|
+
let(:sro_params) { { collect_number: '1234', type: 'A' } }
|
6
|
+
let(:sro) { CorreiosSigep::Models::SRO.new(sro_params) }
|
7
|
+
let(:xml) do
|
8
|
+
"<cartao>0057018901</cartao><codigo_servico>41076</codigo_servico><contrato>9912208555</contrato><codAdministrativo>08082650</codAdministrativo><senha>8o8otn</senha><usuario>60618043</usuario>\n <tipoBusca>H</tipoBusca>\n <tipoSolicitacao>A</tipoSolicitacao>\n <numeroPedido>1234</numeroPedido>\n\n"
|
9
|
+
end
|
10
|
+
|
11
|
+
subject { described_class.build_xml(sro) }
|
12
|
+
|
13
|
+
it 'builds a xml without root but with authentication' do
|
14
|
+
expect(subject).to eq xml
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module CorreiosSigep
|
2
|
+
module LogisticReverse
|
3
|
+
describe RequestSRO do
|
4
|
+
let(:sro_params) { { collect_number: '1234', type: 'A' } }
|
5
|
+
let(:sro) { CorreiosSigep::Models::SRO.new(sro_params) }
|
6
|
+
|
7
|
+
describe '.initialize' do
|
8
|
+
subject { described_class.new(sro) }
|
9
|
+
|
10
|
+
it 'instantiates necessary classes' do
|
11
|
+
expect(subject.class).to eq CorreiosSigep::LogisticReverse::RequestSRO
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '.process' do
|
16
|
+
subject { described_class.new(sro).process }
|
17
|
+
|
18
|
+
before :each do
|
19
|
+
expect_any_instance_of(RequestSRO).to receive(:invoke).with(any_args) { response }
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:response) { double('response', body: response_hash) }
|
23
|
+
let(:sro_ticket) { 'ABC123123123BR' }
|
24
|
+
|
25
|
+
context 'when successfully brings a SRO' do
|
26
|
+
let(:response_hash) do
|
27
|
+
{
|
28
|
+
acompanhar_pedido_response: {
|
29
|
+
return: {
|
30
|
+
cod_erro: 0,
|
31
|
+
coleta: {
|
32
|
+
objeto: {
|
33
|
+
numero_etiqueta: sro_ticket
|
34
|
+
}
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'returns sro ticket' do
|
42
|
+
expect(subject).to eq sro_ticket
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'when SRO is not ready yet' do
|
47
|
+
let(:response_hash) do
|
48
|
+
{
|
49
|
+
acompanhar_pedido_response: {
|
50
|
+
return: {
|
51
|
+
cod_erro: 1
|
52
|
+
}
|
53
|
+
}
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'raises an error' do
|
58
|
+
expect{subject}.to raise_error Models::Errors::SRONotReady
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module CorreiosSigep
|
2
|
+
module Models
|
3
|
+
describe SRO do
|
4
|
+
it { should respond_to :collect_number }
|
5
|
+
it { should respond_to :type }
|
6
|
+
|
7
|
+
describe '.initialize' do
|
8
|
+
subject { described_class.new params }
|
9
|
+
|
10
|
+
context 'with nil params' do
|
11
|
+
let(:params) { Hash.new }
|
12
|
+
|
13
|
+
it 'binds attrs to nil' do
|
14
|
+
expect(subject.collect_number).to be_nil
|
15
|
+
expect(subject.type).to be_nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'with present params' do
|
20
|
+
let(:params) { { collect_number: '1234', type: 'A' } }
|
21
|
+
it 'binds params to params' do
|
22
|
+
expect(subject.collect_number).to eq params[:collect_number]
|
23
|
+
expect(subject.type).to eq params[:type]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '.to_xml' do
|
29
|
+
let(:sro) { described_class.new(collect_number: '12345', type: 'A') }
|
30
|
+
let(:xml) do
|
31
|
+
"<?xml version=\"1.0\"?>\n<root>\n <tipoBusca>H</tipoBusca>\n <tipoSolicitacao>A</tipoSolicitacao>\n <numeroPedido>12345</numeroPedido>\n</root>\n"
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'generates the correct xml with root' do
|
35
|
+
expect(sro.to_xml).to eq xml
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: correios_sigep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Ribeiro
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-03-
|
12
|
+
date: 2015-03-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: savon
|
@@ -138,14 +138,17 @@ files:
|
|
138
138
|
- lib/correios_sigep/builders/xml/product.rb
|
139
139
|
- lib/correios_sigep/builders/xml/recipient.rb
|
140
140
|
- lib/correios_sigep/builders/xml/request_collect_number.rb
|
141
|
+
- lib/correios_sigep/builders/xml/request_sro.rb
|
141
142
|
- lib/correios_sigep/builders/xml/sender.rb
|
142
143
|
- lib/correios_sigep/configuration.rb
|
143
144
|
- lib/correios_sigep/logistic_reverse/base_client.rb
|
144
145
|
- lib/correios_sigep/logistic_reverse/request_collect_number.rb
|
146
|
+
- lib/correios_sigep/logistic_reverse/request_sro.rb
|
145
147
|
- lib/correios_sigep/models/collect.rb
|
146
148
|
- lib/correios_sigep/models/correios_response_codes.rb
|
147
149
|
- lib/correios_sigep/models/errors/collect_not_answered_for_the_zipcode.rb
|
148
150
|
- lib/correios_sigep/models/errors/inexistent_zipcode.rb
|
151
|
+
- lib/correios_sigep/models/errors/sro_not_ready.rb
|
149
152
|
- lib/correios_sigep/models/errors/ticket_already_used.rb
|
150
153
|
- lib/correios_sigep/models/errors/unavailable_house_collect.rb
|
151
154
|
- lib/correios_sigep/models/errors/unavailable_service.rb
|
@@ -155,17 +158,21 @@ files:
|
|
155
158
|
- lib/correios_sigep/models/product.rb
|
156
159
|
- lib/correios_sigep/models/recipient.rb
|
157
160
|
- lib/correios_sigep/models/sender.rb
|
161
|
+
- lib/correios_sigep/models/sro.rb
|
158
162
|
- lib/correios_sigep/version.rb
|
159
163
|
- spec/correios_sigep/builders/xml/request_collect_number_spec.rb
|
164
|
+
- spec/correios_sigep/builders/xml/request_sro_spec.rb
|
160
165
|
- spec/correios_sigep/configuration_spec.rb
|
161
166
|
- spec/correios_sigep/logistic_reverse/base_client_spec.rb
|
162
167
|
- spec/correios_sigep/logistic_reverse/request_collect_number_spec.rb
|
168
|
+
- spec/correios_sigep/logistic_reverse/request_sro_spec.rb
|
163
169
|
- spec/correios_sigep/models/collect_spec.rb
|
164
170
|
- spec/correios_sigep/models/logistic_reverse_spec.rb
|
165
171
|
- spec/correios_sigep/models/object_spec.rb
|
166
172
|
- spec/correios_sigep/models/product_spec.rb
|
167
173
|
- spec/correios_sigep/models/recipient_spec.rb
|
168
174
|
- spec/correios_sigep/models/sender_spec.rb
|
175
|
+
- spec/correios_sigep/models/sro_spec.rb
|
169
176
|
- spec/correios_sigep_spec.rb
|
170
177
|
- spec/fixtures/correios/response_already_in_use.xml
|
171
178
|
- spec/fixtures/correios/response_inexistent_zipcode.xml
|
@@ -204,15 +211,18 @@ specification_version: 4
|
|
204
211
|
summary: A gem that integrates with Correios SIGEP WEB.
|
205
212
|
test_files:
|
206
213
|
- spec/correios_sigep/builders/xml/request_collect_number_spec.rb
|
214
|
+
- spec/correios_sigep/builders/xml/request_sro_spec.rb
|
207
215
|
- spec/correios_sigep/configuration_spec.rb
|
208
216
|
- spec/correios_sigep/logistic_reverse/base_client_spec.rb
|
209
217
|
- spec/correios_sigep/logistic_reverse/request_collect_number_spec.rb
|
218
|
+
- spec/correios_sigep/logistic_reverse/request_sro_spec.rb
|
210
219
|
- spec/correios_sigep/models/collect_spec.rb
|
211
220
|
- spec/correios_sigep/models/logistic_reverse_spec.rb
|
212
221
|
- spec/correios_sigep/models/object_spec.rb
|
213
222
|
- spec/correios_sigep/models/product_spec.rb
|
214
223
|
- spec/correios_sigep/models/recipient_spec.rb
|
215
224
|
- spec/correios_sigep/models/sender_spec.rb
|
225
|
+
- spec/correios_sigep/models/sro_spec.rb
|
216
226
|
- spec/correios_sigep_spec.rb
|
217
227
|
- spec/fixtures/correios/response_already_in_use.xml
|
218
228
|
- spec/fixtures/correios/response_inexistent_zipcode.xml
|