correios_sigep 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/correios_sigep.rb +3 -0
- data/lib/correios_sigep/logistic_reverse/collect_number_actions/process_invalid_request.rb +32 -0
- data/lib/correios_sigep/logistic_reverse/collect_number_actions/process_valid_request.rb +24 -0
- data/lib/correios_sigep/logistic_reverse/request_collect_number.rb +9 -36
- data/lib/correios_sigep/models/errors/invalid_solicitation.rb +8 -0
- data/lib/correios_sigep/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48306a5b571325269cefb86911a20ac7fc30f1c6
|
4
|
+
data.tar.gz: 4f500e96b3ab1429bf39fb1de6922f2a517cedd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cd53cb28b9a2a3672d68dc05629326a34c706a09898d42bd4a5d74358993b02eb437139f0877cb19447f573d78b9f1827d2e2a2f31b733e1bb9d8e8f2cd97f8
|
7
|
+
data.tar.gz: a6e35a9ee2fff1a456c1aacb6f40e0aab1c1fc6934ab37d7fdd4273f7f72aac31ff4a0f22f34e34b1f1ca99093110cfd58e1bf5f8e303a3161203754d01a32f8
|
data/lib/correios_sigep.rb
CHANGED
@@ -38,6 +38,9 @@ require 'correios_sigep/models/errors/unknown_error'
|
|
38
38
|
require 'correios_sigep/models/errors/sro_not_ready'
|
39
39
|
require 'correios_sigep/models/errors/required_fields'
|
40
40
|
require 'correios_sigep/models/errors/collect_number_not_found'
|
41
|
+
require 'correios_sigep/models/errors/invalid_solicitation'
|
42
|
+
require 'correios_sigep/logistic_reverse/collect_number_actions/process_invalid_request'
|
43
|
+
require 'correios_sigep/logistic_reverse/collect_number_actions/process_valid_request'
|
41
44
|
require 'correios_sigep/logistic_reverse/base_client'
|
42
45
|
require 'correios_sigep/logistic_reverse/request_collect_number'
|
43
46
|
require 'correios_sigep/logistic_reverse/request_sro'
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module CorreiosSigep
|
2
|
+
module LogisticReverse
|
3
|
+
module CollectNumberActions
|
4
|
+
class ProcessInvalidRequest
|
5
|
+
def initialize(response)
|
6
|
+
@response = response
|
7
|
+
end
|
8
|
+
|
9
|
+
def run
|
10
|
+
code = @response.search('//cod_erro').text.to_i
|
11
|
+
error_message = @response.search('//msg_erro').text
|
12
|
+
klass = (errors[code] || Models::Errors::UnknownError)
|
13
|
+
|
14
|
+
raise klass.new(error_message)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def errors
|
20
|
+
{
|
21
|
+
Models::CorreiosResponseCodes::TICKET_ALREADY_USED => Models::Errors::TicketAlreadyUsed,
|
22
|
+
Models::CorreiosResponseCodes::UNAVAILABLE_SERVICE => Models::Errors::UnavailableService,
|
23
|
+
Models::CorreiosResponseCodes::INEXISTENT_ZIPCODE => Models::Errors::InexistentZipcode,
|
24
|
+
Models::CorreiosResponseCodes::UNAVAILABLE_HOUSE_COLLECT => Models::Errors::UnavailableHouseCollect,
|
25
|
+
Models::CorreiosResponseCodes::COLLECT_NOT_ANSWERED_FOR_THE_ZIPCODE => Models::Errors::CollectNotAnsweredForTheZipcode,
|
26
|
+
Models::CorreiosResponseCodes::NOT_CONFIGURED_CLIENT => Models::Errors::NotConfiguredClient
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module CorreiosSigep
|
2
|
+
module LogisticReverse
|
3
|
+
module CollectNumberActions
|
4
|
+
class ProcessValidRequest
|
5
|
+
def initialize(response)
|
6
|
+
@response = response
|
7
|
+
end
|
8
|
+
|
9
|
+
def run
|
10
|
+
result_node = @response.search('//resultado_solicitacao')
|
11
|
+
code = result_node.search('//codigo_erro').text.to_i
|
12
|
+
|
13
|
+
if Models::CorreiosResponseCodes::SUCCESS != code
|
14
|
+
error_message = @response.search('//descricao_erro').text
|
15
|
+
raise Models::Errors::InvalidSolicitation.new(error_message)
|
16
|
+
end
|
17
|
+
|
18
|
+
result = result_node.search('//numero_coleta')
|
19
|
+
result.first.text
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -10,51 +10,24 @@ module CorreiosSigep
|
|
10
10
|
def process
|
11
11
|
xml = Builders::XML::RequestCollectNumber.build_xml(@logistic_reverse, @overrides)
|
12
12
|
response = invoke(:solicitar_postagem_reversa, xml)
|
13
|
-
process_response
|
13
|
+
process_response(response)
|
14
14
|
end
|
15
15
|
|
16
16
|
private
|
17
17
|
|
18
|
-
def process_response
|
18
|
+
def process_response(response)
|
19
19
|
response_xml = response.to_xml.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
|
20
20
|
response_doc = Nokogiri::XML.parse(response_xml)
|
21
|
-
code = response_doc.search('//
|
22
|
-
handle_errors code, response_doc
|
23
|
-
end
|
24
|
-
|
25
|
-
def handle_errors code, response_doc
|
26
|
-
result_string = '//resultado-solicitacao | //resultado_solicitacao'
|
27
|
-
result_node = response_doc.search(result_string)
|
28
|
-
error_message = response_doc.search('//msg-erro | //msg_erro').text rescue ''
|
29
|
-
|
30
|
-
case code
|
31
|
-
when Models::CorreiosResponseCodes::SUCCESS
|
32
|
-
result = result_node.search('//numero-coleta | //numero_coleta')
|
33
|
-
result.first.text rescue nil
|
34
|
-
|
35
|
-
when Models::CorreiosResponseCodes::TICKET_ALREADY_USED
|
36
|
-
raise Models::Errors::TicketAlreadyUsed.new error_message
|
37
|
-
|
38
|
-
when Models::CorreiosResponseCodes::UNAVAILABLE_SERVICE
|
39
|
-
raise Models::Errors::UnavailableService
|
21
|
+
code = response_doc.search('//cod_erro').text.to_i
|
40
22
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
when Models::CorreiosResponseCodes::UNAVAILABLE_HOUSE_COLLECT
|
45
|
-
raise Models::Errors::UnavailableHouseCollect
|
46
|
-
|
47
|
-
when Models::CorreiosResponseCodes::COLLECT_NOT_ANSWERED_FOR_THE_ZIPCODE
|
48
|
-
raise Models::Errors::CollectNotAnsweredForTheZipcode
|
49
|
-
|
50
|
-
when Models::CorreiosResponseCodes::NOT_CONFIGURED_CLIENT
|
51
|
-
raise Models::Errors::NotConfiguredClient.new error_message
|
23
|
+
action(code).new(response_doc).run
|
24
|
+
end
|
52
25
|
|
26
|
+
def action(code)
|
27
|
+
if Models::CorreiosResponseCodes::SUCCESS == code
|
28
|
+
CollectNumberActions::ProcessValidRequest
|
53
29
|
else
|
54
|
-
|
55
|
-
invalid_xml_message = response_doc.search("//return").text rescue ''
|
56
|
-
|
57
|
-
raise Models::Errors::UnknownError.new [error_message, invalid_xml_message].join(', ')
|
30
|
+
CollectNumberActions::ProcessInvalidRequest
|
58
31
|
end
|
59
32
|
end
|
60
33
|
end
|
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: 1.0.
|
4
|
+
version: 1.0.2
|
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: 2017-
|
12
|
+
date: 2017-02-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: net-http-persistent
|
@@ -189,6 +189,8 @@ files:
|
|
189
189
|
- lib/correios_sigep/dsl/person.rb
|
190
190
|
- lib/correios_sigep/dsl/product.rb
|
191
191
|
- lib/correios_sigep/logistic_reverse/base_client.rb
|
192
|
+
- lib/correios_sigep/logistic_reverse/collect_number_actions/process_invalid_request.rb
|
193
|
+
- lib/correios_sigep/logistic_reverse/collect_number_actions/process_valid_request.rb
|
192
194
|
- lib/correios_sigep/logistic_reverse/request_collect_number.rb
|
193
195
|
- lib/correios_sigep/logistic_reverse/request_sro.rb
|
194
196
|
- lib/correios_sigep/models/administrative_fields.rb
|
@@ -197,6 +199,7 @@ files:
|
|
197
199
|
- lib/correios_sigep/models/errors/collect_not_answered_for_the_zipcode.rb
|
198
200
|
- lib/correios_sigep/models/errors/collect_number_not_found.rb
|
199
201
|
- lib/correios_sigep/models/errors/inexistent_zipcode.rb
|
202
|
+
- lib/correios_sigep/models/errors/invalid_solicitation.rb
|
200
203
|
- lib/correios_sigep/models/errors/not_configured_client.rb
|
201
204
|
- lib/correios_sigep/models/errors/required_fields.rb
|
202
205
|
- lib/correios_sigep/models/errors/sro_not_ready.rb
|