correios_sigep 1.0.2 → 2.0.0

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: 48306a5b571325269cefb86911a20ac7fc30f1c6
4
- data.tar.gz: 4f500e96b3ab1429bf39fb1de6922f2a517cedd4
3
+ metadata.gz: 85b92be1bc69bfaf584b2189929f7bcdb9b9eea2
4
+ data.tar.gz: 45ec9534a9adebaef05490913cb1528231edeb41
5
5
  SHA512:
6
- metadata.gz: 9cd53cb28b9a2a3672d68dc05629326a34c706a09898d42bd4a5d74358993b02eb437139f0877cb19447f573d78b9f1827d2e2a2f31b733e1bb9d8e8f2cd97f8
7
- data.tar.gz: a6e35a9ee2fff1a456c1aacb6f40e0aab1c1fc6934ab37d7fdd4273f7f72aac31ff4a0f22f34e34b1f1ca99093110cfd58e1bf5f8e303a3161203754d01a32f8
6
+ metadata.gz: b6133289b2d5fa2d63474603a93919544c397ec7671d63077453f80c4850d7bc53e87abf140d7d0ff3545d02882ebc80ec060f48c22c8198ad527aa8bfb28641
7
+ data.tar.gz: cd19948cd68d1b77e4513f4f2132368850a1dd5b04afca72f6373cc4e1f28d6c4bafa0d95b98124e69073abfe544b67ed5af8a077801432887772c6276fcddb9
@@ -1,54 +1,17 @@
1
- require 'correios_sigep/version'
2
- require 'correios_sigep/models/administrative_fields'
3
- require 'correios_sigep/configuration'
4
- require 'correios_sigep/dsl/logistic_reverse'
5
- require 'correios_sigep/dsl/person'
6
- require 'correios_sigep/dsl/object'
7
- require 'correios_sigep/dsl/product'
8
- require 'correios_sigep/dsl/collect'
9
- require 'correios_sigep/builders/person'
10
- require 'correios_sigep/builders/object'
11
- require 'correios_sigep/builders/product'
12
- require 'correios_sigep/builders/collect'
13
- require 'correios_sigep/builders/xml/recipient'
14
- require 'correios_sigep/builders/xml/sender'
15
- require 'correios_sigep/builders/xml/product'
16
- require 'correios_sigep/builders/xml/collect_objects'
17
- require 'correios_sigep/builders/xml/collect'
18
- require 'correios_sigep/builders/xml/request'
19
- require 'correios_sigep/builders/xml/request_collect_number'
20
- require 'correios_sigep/builders/xml/request_sro'
21
- require 'correios_sigep/models/recipient'
22
- require 'correios_sigep/models/product'
23
- require 'correios_sigep/models/recipient'
24
- require 'correios_sigep/models/sender'
25
- require 'correios_sigep/models/object'
26
- require 'correios_sigep/models/sender'
27
- require 'correios_sigep/models/collect'
28
- require 'correios_sigep/models/logistic_reverse'
29
- require 'correios_sigep/models/sro'
30
- require 'correios_sigep/models/correios_response_codes'
31
- require 'correios_sigep/models/errors/ticket_already_used'
32
- require 'correios_sigep/models/errors/unavailable_service'
33
- require 'correios_sigep/models/errors/inexistent_zipcode'
34
- require 'correios_sigep/models/errors/unavailable_house_collect'
35
- require 'correios_sigep/models/errors/collect_not_answered_for_the_zipcode'
36
- require 'correios_sigep/models/errors/not_configured_client'
37
- require 'correios_sigep/models/errors/unknown_error'
38
- require 'correios_sigep/models/errors/sro_not_ready'
39
- require 'correios_sigep/models/errors/required_fields'
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'
44
- require 'correios_sigep/logistic_reverse/base_client'
45
- require 'correios_sigep/logistic_reverse/request_collect_number'
46
- require 'correios_sigep/logistic_reverse/request_sro'
47
1
  require 'net/http/persistent'
48
2
  require 'nokogiri'
49
3
  require 'savon'
50
4
 
5
+ require 'correios_sigep/version'
6
+
7
+ require 'correios_sigep/builders'
8
+ require 'correios_sigep/dsl'
9
+ require 'correios_sigep/logistic_reverse'
10
+ require 'correios_sigep/models'
11
+
51
12
  module CorreiosSigep
13
+ autoload :Configuration, 'correios_sigep/configuration'
14
+
52
15
  def self.configuration
53
16
  @configuration ||= Configuration.new
54
17
  end
@@ -0,0 +1,19 @@
1
+ module CorreiosSigep
2
+ module Builders
3
+ autoload :Collect, 'correios_sigep/builders/collect'
4
+ autoload :Object, 'correios_sigep/builders/object'
5
+ autoload :Person, 'correios_sigep/builders/person'
6
+ autoload :Product, 'correios_sigep/builders/product'
7
+
8
+ module XML
9
+ autoload :Collect, 'correios_sigep/builders/xml/collect'
10
+ autoload :CollectObjects, 'correios_sigep/builders/xml/collect_objects'
11
+ autoload :Product, 'correios_sigep/builders/xml/product'
12
+ autoload :Recipient, 'correios_sigep/builders/xml/recipient'
13
+ autoload :Request, 'correios_sigep/builders/xml/request'
14
+ autoload :RequestCollectNumber, 'correios_sigep/builders/xml/request_collect_number'
15
+ autoload :RequestSRO, 'correios_sigep/builders/xml/request_sro'
16
+ autoload :Sender, 'correios_sigep/builders/xml/sender'
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ module CorreiosSigep
2
+ module DSL
3
+ autoload :Collect, 'correios_sigep/dsl/collect'
4
+ autoload :LogisticReverse, 'correios_sigep/dsl/logistic_reverse'
5
+ autoload :Object, 'correios_sigep/dsl/object'
6
+ autoload :Person, 'correios_sigep/dsl/person'
7
+ autoload :Product, 'correios_sigep/dsl/product'
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ module CorreiosSigep
2
+ module LogisticReverse
3
+ autoload :BaseClient, 'correios_sigep/logistic_reverse/base_client'
4
+ autoload :RequestCollectNumber, 'correios_sigep/logistic_reverse/request_collect_number'
5
+ autoload :RequestSRO, 'correios_sigep/logistic_reverse/request_sro'
6
+
7
+ module CollectNumberActions
8
+ autoload :ProcessInvalidRequest, 'correios_sigep/logistic_reverse/collect_number_actions/process_invalid_request'
9
+ autoload :ProcessValidRequest, 'correios_sigep/logistic_reverse/collect_number_actions/process_valid_request'
10
+ end
11
+ end
12
+ end
@@ -7,10 +7,7 @@ module CorreiosSigep
7
7
  end
8
8
 
9
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
-
10
+ klass = (errors[error_code] || errors[new_error_code] || Models::Errors::UnknownError)
14
11
  raise klass.new(error_message)
15
12
  end
16
13
 
@@ -23,9 +20,25 @@ module CorreiosSigep
23
20
  Models::CorreiosResponseCodes::INEXISTENT_ZIPCODE => Models::Errors::InexistentZipcode,
24
21
  Models::CorreiosResponseCodes::UNAVAILABLE_HOUSE_COLLECT => Models::Errors::UnavailableHouseCollect,
25
22
  Models::CorreiosResponseCodes::COLLECT_NOT_ANSWERED_FOR_THE_ZIPCODE => Models::Errors::CollectNotAnsweredForTheZipcode,
26
- Models::CorreiosResponseCodes::NOT_CONFIGURED_CLIENT => Models::Errors::NotConfiguredClient
23
+ Models::CorreiosResponseCodes::NOT_CONFIGURED_CLIENT => Models::Errors::NotConfiguredClient,
24
+ Models::CorreiosResponseCodes::INVALID_CONTRACT => Models::Errors::InvalidContract,
25
+ Models::CorreiosResponseCodes::INVALID_DECLARED_VALUE => Models::Errors::InvalidDeclaredValue
27
26
  }
28
27
  end
28
+
29
+ def error_code
30
+ return nil if @response.search('//cod_erro').empty?
31
+ @response.search('//cod_erro').text.to_i
32
+ end
33
+
34
+ def new_error_code
35
+ return nil if @response.search('//codigo_erro').empty?
36
+ @response.search('//codigo_erro').text.to_i
37
+ end
38
+
39
+ def error_message
40
+ "#{@response.search('//msg_erro').text} #{@response.search('//descricao_erro').text}".strip
41
+ end
29
42
  end
30
43
  end
31
44
  end
@@ -1,3 +1,5 @@
1
+ # encoding UTF-8
2
+
1
3
  module CorreiosSigep
2
4
  module LogisticReverse
3
5
  class RequestCollectNumber < BaseClient
@@ -16,15 +18,19 @@ module CorreiosSigep
16
18
  private
17
19
 
18
20
  def process_response(response)
19
- response_xml = response.to_xml.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
21
+ response_xml = response.to_xml.force_encoding('UTF-8')
20
22
  response_doc = Nokogiri::XML.parse(response_xml)
21
- code = response_doc.search('//cod_erro').text.to_i
23
+ code = response_doc.search('//cod_erro').text.to_i
24
+
25
+ unless response_doc.search('//codigo_erro').empty?
26
+ new_code = response_doc.search('//codigo_erro').text.to_i
27
+ end
22
28
 
23
- action(code).new(response_doc).run
29
+ action([code, new_code || nil].compact).new(response_doc).run
24
30
  end
25
31
 
26
- def action(code)
27
- if Models::CorreiosResponseCodes::SUCCESS == code
32
+ def action(response_codes)
33
+ if response_codes.all?{|response_code| response_code == Models::CorreiosResponseCodes::SUCCESS}
28
34
  CollectNumberActions::ProcessValidRequest
29
35
  else
30
36
  CollectNumberActions::ProcessInvalidRequest
@@ -0,0 +1,30 @@
1
+
2
+ module CorreiosSigep
3
+ module Models
4
+ autoload :AdministrativeFields, 'correios_sigep/models/administrative_fields'
5
+ autoload :Collect, 'correios_sigep/models/collect'
6
+ autoload :CorreiosResponseCodes, 'correios_sigep/models/correios_response_codes'
7
+ autoload :LogisticReverse, 'correios_sigep/models/logistic_reverse'
8
+ autoload :Object, 'correios_sigep/models/object'
9
+ autoload :Product, 'correios_sigep/models/product'
10
+ autoload :Recipient, 'correios_sigep/models/recipient'
11
+ autoload :Sender, 'correios_sigep/models/sender'
12
+ autoload :SRO, 'correios_sigep/models/sro'
13
+
14
+ module Errors
15
+ autoload :CollectNotAnsweredForTheZipcode, 'correios_sigep/models/errors/collect_not_answered_for_the_zipcode'
16
+ autoload :CollectNumberNotFound, 'correios_sigep/models/errors/collect_number_not_found'
17
+ autoload :InexistentZipcode, 'correios_sigep/models/errors/inexistent_zipcode'
18
+ autoload :InvalidSolicitation, 'correios_sigep/models/errors/invalid_solicitation'
19
+ autoload :NotConfiguredClient, 'correios_sigep/models/errors/not_configured_client'
20
+ autoload :RequiredFields, 'correios_sigep/models/errors/required_fields'
21
+ autoload :SRONotReady, 'correios_sigep/models/errors/sro_not_ready'
22
+ autoload :TicketAlreadyUsed, 'correios_sigep/models/errors/ticket_already_used'
23
+ autoload :UnavailableHouseCollect, 'correios_sigep/models/errors/unavailable_house_collect'
24
+ autoload :UnavailableService, 'correios_sigep/models/errors/unavailable_service'
25
+ autoload :InvalidContract, 'correios_sigep/models/errors/invalid_contract'
26
+ autoload :InvalidDeclaredValue, 'correios_sigep/models/errors/invalid_declared_value'
27
+ autoload :UnknownError, 'correios_sigep/models/errors/unknown_error'
28
+ end
29
+ end
30
+ end
@@ -8,6 +8,8 @@ module CorreiosSigep
8
8
  UNAVAILABLE_HOUSE_COLLECT = 111
9
9
  COLLECT_NOT_ANSWERED_FOR_THE_ZIPCODE = 117
10
10
  NOT_CONFIGURED_CLIENT = 105
11
+ INVALID_CONTRACT = 109
12
+ INVALID_DECLARED_VALUE = 205
11
13
  end
12
14
  end
13
15
  end
@@ -0,0 +1,8 @@
1
+ module CorreiosSigep
2
+ module Models
3
+ module Errors
4
+ class InvalidContract < StandardError
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module CorreiosSigep
2
+ module Models
3
+ module Errors
4
+ class InvalidDeclaredValue < StandardError
5
+ end
6
+ end
7
+ end
8
+ end
@@ -1,3 +1,3 @@
1
1
  module CorreiosSigep
2
- VERSION = '1.0.2'.freeze
2
+ VERSION = '2.0.0'.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.2
4
+ version: 2.0.0
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-02-02 00:00:00.000000000 Z
12
+ date: 2017-08-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: net-http-persistent
@@ -170,6 +170,7 @@ files:
170
170
  - README.md
171
171
  - correios_sigep.gemspec
172
172
  - lib/correios_sigep.rb
173
+ - lib/correios_sigep/builders.rb
173
174
  - lib/correios_sigep/builders/collect.rb
174
175
  - lib/correios_sigep/builders/object.rb
175
176
  - lib/correios_sigep/builders/person.rb
@@ -183,22 +184,27 @@ files:
183
184
  - lib/correios_sigep/builders/xml/request_sro.rb
184
185
  - lib/correios_sigep/builders/xml/sender.rb
185
186
  - lib/correios_sigep/configuration.rb
187
+ - lib/correios_sigep/dsl.rb
186
188
  - lib/correios_sigep/dsl/collect.rb
187
189
  - lib/correios_sigep/dsl/logistic_reverse.rb
188
190
  - lib/correios_sigep/dsl/object.rb
189
191
  - lib/correios_sigep/dsl/person.rb
190
192
  - lib/correios_sigep/dsl/product.rb
193
+ - lib/correios_sigep/logistic_reverse.rb
191
194
  - lib/correios_sigep/logistic_reverse/base_client.rb
192
195
  - lib/correios_sigep/logistic_reverse/collect_number_actions/process_invalid_request.rb
193
196
  - lib/correios_sigep/logistic_reverse/collect_number_actions/process_valid_request.rb
194
197
  - lib/correios_sigep/logistic_reverse/request_collect_number.rb
195
198
  - lib/correios_sigep/logistic_reverse/request_sro.rb
199
+ - lib/correios_sigep/models.rb
196
200
  - lib/correios_sigep/models/administrative_fields.rb
197
201
  - lib/correios_sigep/models/collect.rb
198
202
  - lib/correios_sigep/models/correios_response_codes.rb
199
203
  - lib/correios_sigep/models/errors/collect_not_answered_for_the_zipcode.rb
200
204
  - lib/correios_sigep/models/errors/collect_number_not_found.rb
201
205
  - lib/correios_sigep/models/errors/inexistent_zipcode.rb
206
+ - lib/correios_sigep/models/errors/invalid_contract.rb
207
+ - lib/correios_sigep/models/errors/invalid_declared_value.rb
202
208
  - lib/correios_sigep/models/errors/invalid_solicitation.rb
203
209
  - lib/correios_sigep/models/errors/not_configured_client.rb
204
210
  - lib/correios_sigep/models/errors/required_fields.rb