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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 51231597d79a613436e06506f3fef51e54f8ad1b
4
- data.tar.gz: f07572647ee016687d787a6f770ece656b45e786
3
+ metadata.gz: 48306a5b571325269cefb86911a20ac7fc30f1c6
4
+ data.tar.gz: 4f500e96b3ab1429bf39fb1de6922f2a517cedd4
5
5
  SHA512:
6
- metadata.gz: e0c6af4a6da09f6ec53a6bc5127e3668361cb9a71cfa99bc310f73cc19f4f5a7ae09bbc6ba30e589ccedcd992e684074dc4fd055dc09b3025b39933ae81924c8
7
- data.tar.gz: f38ab6b0a6149e22032748049c7e514e053fba4681c4cb42afe9b5fc6234f8a74c8b48a0b41e5e310d3d2a2e89f6b79320279257c9918cad53572139b9d9fd03
6
+ metadata.gz: 9cd53cb28b9a2a3672d68dc05629326a34c706a09898d42bd4a5d74358993b02eb437139f0877cb19447f573d78b9f1827d2e2a2f31b733e1bb9d8e8f2cd97f8
7
+ data.tar.gz: a6e35a9ee2fff1a456c1aacb6f40e0aab1c1fc6934ab37d7fdd4273f7f72aac31ff4a0f22f34e34b1f1ca99093110cfd58e1bf5f8e303a3161203754d01a32f8
@@ -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 response
13
+ process_response(response)
14
14
  end
15
15
 
16
16
  private
17
17
 
18
- def process_response 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('//cod-erro | //cod_erro').text.to_i rescue nil
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
- when Models::CorreiosResponseCodes::INEXISTENT_ZIPCODE
42
- raise Models::Errors::InexistentZipcode
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
- error_message = result_node.search('//msg-erro | //msg_erro').text rescue ''
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
@@ -0,0 +1,8 @@
1
+ module CorreiosSigep
2
+ module Models
3
+ module Errors
4
+ class InvalidSolicitation < StandardError
5
+ end
6
+ end
7
+ end
8
+ end
@@ -1,3 +1,3 @@
1
1
  module CorreiosSigep
2
- VERSION = '1.0.1'.freeze
2
+ VERSION = '1.0.2'.freeze
3
3
  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.1
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-01-23 00:00:00.000000000 Z
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