correios_sigep 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/correios_sigep.gemspec +1 -1
  4. data/lib/correios_sigep/logistic_reverse/base_client.rb +3 -4
  5. data/lib/correios_sigep/version.rb +1 -1
  6. metadata +4 -90
  7. data/.gitignore +0 -14
  8. data/.rspec +0 -3
  9. data/.rubocop.yml +0 -1160
  10. data/.ruby-gemset +0 -1
  11. data/.ruby-version +0 -1
  12. data/.travis.yml +0 -16
  13. data/Gemfile +0 -8
  14. data/Rakefile +0 -15
  15. data/bin/rake +0 -16
  16. data/spec/correios_sigep/builders/xml/request_collect_number_spec.rb +0 -22
  17. data/spec/correios_sigep/builders/xml/request_spec.rb +0 -34
  18. data/spec/correios_sigep/builders/xml/request_sro_spec.rb +0 -17
  19. data/spec/correios_sigep/configuration_spec.rb +0 -87
  20. data/spec/correios_sigep/logistic_reverse/base_client_spec.rb +0 -93
  21. data/spec/correios_sigep/logistic_reverse/request_collect_number_spec.rb +0 -106
  22. data/spec/correios_sigep/logistic_reverse/request_sro_spec.rb +0 -86
  23. data/spec/correios_sigep/models/collect_spec.rb +0 -149
  24. data/spec/correios_sigep/models/logistic_reverse_spec.rb +0 -221
  25. data/spec/correios_sigep/models/object_spec.rb +0 -53
  26. data/spec/correios_sigep/models/product_spec.rb +0 -37
  27. data/spec/correios_sigep/models/recipient_spec.rb +0 -108
  28. data/spec/correios_sigep/models/sender_spec.rb +0 -141
  29. data/spec/correios_sigep/models/sro_spec.rb +0 -40
  30. data/spec/correios_sigep_spec.rb +0 -27
  31. data/spec/fixtures/builders/logistic_reverse.xml +0 -66
  32. data/spec/fixtures/builders/request_collect_number.xml +0 -64
  33. data/spec/fixtures/builders/request_sro.xml +0 -4
  34. data/spec/fixtures/correios/request_collect_number/response_already_in_use.xml +0 -14
  35. data/spec/fixtures/correios/request_collect_number/response_inexistent_zipcode.xml +0 -14
  36. data/spec/fixtures/correios/request_collect_number/response_not_answered_for_zipcode.xml +0 -14
  37. data/spec/fixtures/correios/request_collect_number/response_not_configured_client.xml +0 -14
  38. data/spec/fixtures/correios/request_collect_number/response_success.xml +0 -27
  39. data/spec/fixtures/correios/request_collect_number/response_unavailable_house_collect.xml +0 -14
  40. data/spec/fixtures/correios/request_collect_number/response_unavailable_service.xml +0 -14
  41. data/spec/fixtures/correios/request_collect_number/response_unexpected.xml +0 -14
  42. data/spec/fixtures/correios/request_sro/response_array_success.xml +0 -38
  43. data/spec/fixtures/correios/request_sro/response_collect_number_not_found.xml +0 -13
  44. data/spec/fixtures/correios/request_sro/response_required_fields.xml +0 -13
  45. data/spec/fixtures/correios/request_sro/response_sro_not_ready.xml +0 -30
  46. data/spec/fixtures/correios/request_sro/response_success.xml +0 -30
  47. data/spec/fixtures/correios/request_sro/response_unknown_error.xml +0 -13
  48. data/spec/fixtures/correios/wsdl.xml +0 -650
  49. data/spec/fixtures/requests/collect_number_request.xml +0 -66
  50. data/spec/fixtures/requests/sro_request.xml +0 -6
  51. data/spec/spec_helper.rb +0 -39
  52. data/spec/support/fixture_helper.rb +0 -13
  53. data/spec/support/logistic_reverse_helper.rb +0 -15
data/.ruby-gemset DELETED
@@ -1 +0,0 @@
1
- correios-sigep
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.1.5
data/.travis.yml DELETED
@@ -1,16 +0,0 @@
1
- language: ruby
2
- before_install:
3
- - gem install bundler -v '~> 1.5'
4
- rvm:
5
- - 2.1.10
6
- - 2.2.6
7
- - 2.3.3
8
- - 2.4.0
9
- bundler_args: --without debug
10
- deploy:
11
- provider: rubygems
12
- api_key:
13
- secure: JxDBiuSJgTyne4WriC56QqOhhl07ojHN/qZerKyxabBj1yQ/GmxlzcdvXdU6eUFJ1E3BvrfrMmraJ28xADm2hG3xgxkNP/D7jqTv0o0h2CODh+W2dr0iv3bNkoDOfjChNrJZCLPXJbuQp8G3O/KJS84g4l4dEIRIRTCS/0yMEBc=
14
- gem: correios_sigep
15
- on:
16
- repo: duduribeiro/correios_sigep
data/Gemfile DELETED
@@ -1,8 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in correios_sigep.gemspec
4
- gemspec
5
-
6
- group :debug do
7
- gem 'pry-meta', '~> 0.0.10'
8
- end
data/Rakefile DELETED
@@ -1,15 +0,0 @@
1
- require 'bundler/gem_tasks'
2
-
3
- desc "Default task"
4
- task default: :spec
5
-
6
- desc "Open an irb session preloaded with this library"
7
- task :console do
8
- exec 'irb -r correios_sigep -I ./lib'
9
- end
10
-
11
- desc "Run specs"
12
- task :spec do
13
- system "rspec ."
14
- end
15
-
data/bin/rake DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # This file was generated by Bundler.
4
- #
5
- # The application 'rake' is installed as part of a gem, and
6
- # this file is here to facilitate running it.
7
- #
8
-
9
- require 'pathname'
10
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
- Pathname.new(__FILE__).realpath)
12
-
13
- require 'rubygems'
14
- require 'bundler/setup'
15
-
16
- load Gem.bin_path('rake', 'rake')
@@ -1,22 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module CorreiosSigep
4
- module Builders
5
- module XML
6
- describe RequestCollectNumber do
7
- describe '.build_xml' do
8
- subject { described_class.build_xml(logistic_reverse).chop }
9
-
10
- let(:logistic_reverse) { CorreiosSigep::Models::LogisticReverse.new }
11
- let(:expected_xml) { builders_fixture('request_collect_number.xml') }
12
-
13
- before :each do
14
- seed_logistic_reverse(logistic_reverse)
15
- end
16
-
17
- it { should eq expected_xml }
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,34 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module CorreiosSigep
4
- module Builders
5
- module XML
6
- describe Request do
7
- describe '.build_xml' do
8
- let(:request) { double(:request, to_xml: '<root><test></root>') }
9
- context 'when do not override anything' do
10
- it 'builds a Authentication XML with Configuration parameters' do
11
- expected_response = [
12
- '<codAdministrativo>08082650</codAdministrativo><test/>'
13
- ].join + "\n"
14
- expect(described_class.build_xml request).to eq expected_response
15
- end
16
- end
17
-
18
- context 'when override the administrative fields' do
19
- it 'builds a Authentication XML with the override parameter' do
20
- administrative_fields = Models::AdministrativeFields.new(administrative_code: 'adm123',
21
- card: 'card123',
22
- service_code: 'ser123')
23
- expected_response = [
24
- '<codAdministrativo>adm123</codAdministrativo><test/>'
25
- ].join + "\n"
26
- expect(described_class.build_xml request, administrative: administrative_fields).to eq expected_response
27
- end
28
- end
29
-
30
- end
31
- end
32
- end
33
- end
34
- end
@@ -1,17 +0,0 @@
1
- module CorreiosSigep
2
- module Builders
3
- module XML
4
- describe RequestSRO do
5
- describe '.build_xml' do
6
- subject { described_class.build_xml(sro).chop }
7
-
8
- let(:sro_params) { { collect_number: '1234', type: 'A' } }
9
- let(:sro) { CorreiosSigep::Models::SRO.new(sro_params) }
10
- let(:expected_xml) { builders_fixture('request_sro.xml') }
11
-
12
- it { should eq expected_xml }
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,87 +0,0 @@
1
- module CorreiosSigep
2
- describe Configuration do
3
- subject { described_class.new }
4
-
5
- describe '#administrative_code' do
6
- it 'returns nil when unset' do
7
- expect(subject.administrative_code).to be_nil
8
- end
9
- end
10
-
11
- describe '#administrative_code=' do
12
- it 'sets the administrative code in configuration' do
13
- subject.administrative_code = '12345'
14
- expect(subject.administrative_code).to eq '12345'
15
- end
16
- end
17
-
18
- describe '#card' do
19
- it 'returns nil when unset' do
20
- expect(subject.card).to be_nil
21
- end
22
- end
23
-
24
- describe '#card=' do
25
- it 'sets the card in configuration' do
26
- subject.card = 'card'
27
- expect(subject.card).to eq 'card'
28
- end
29
- end
30
-
31
- describe '#service_code' do
32
- it 'returns nil when unset' do
33
- expect(subject.service_code).to be_nil
34
- end
35
- end
36
-
37
- describe '#service_code=' do
38
- it 'sets the password in configuration' do
39
- subject.service_code = 'service_code'
40
- expect(subject.service_code).to eq 'service_code'
41
- end
42
- end
43
-
44
- describe '#timeout' do
45
- it 'returns nil when unset' do
46
- expect(subject.timeout).to be_nil
47
- end
48
- end
49
-
50
- describe '#timeout=' do
51
- it 'sets the timeout in configuration' do
52
- subject.timeout = 15
53
- expect(subject.timeout).to eq 15
54
- end
55
- end
56
-
57
- describe '#user' do
58
- it 'returns nil when unset' do
59
- expect(subject.user).to be_nil
60
- end
61
- end
62
-
63
- describe '#user=' do
64
- let(:user) { 'user' }
65
-
66
- it 'sets the user in configuration' do
67
- subject.user = user
68
- expect(subject.user).to eq user
69
- end
70
- end
71
-
72
- describe '#password' do
73
- it 'returns nil when unset' do
74
- expect(subject.password).to be_nil
75
- end
76
- end
77
-
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
84
- end
85
- end
86
- end
87
- end
@@ -1,93 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module CorreiosSigep
4
- module LogisticReverse
5
- describe BaseClient do
6
- let(:user) { CorreiosSigep.configuration.user }
7
- let(:pass) { CorreiosSigep.configuration.password }
8
-
9
- context 'setting up a proxy' do
10
- subject { described_class.new }
11
-
12
- context 'with a proxy' do
13
- before { CorreiosSigep.configuration.proxy = 'http://localhost' }
14
- let(:params) do
15
- {
16
- adapter: :net_http_persistent,
17
- proxy: CorreiosSigep.configuration.proxy,
18
- wsdl: described_class.new.wsdl,
19
- open_timeout: CorreiosSigep::LogisticReverse::BaseClient::DEFAULT_TIMEOUT,
20
- read_timeout: CorreiosSigep::LogisticReverse::BaseClient::DEFAULT_TIMEOUT,
21
- basic_auth: [user, pass],
22
- headers: { 'SOAPAction' => '' }
23
- }
24
- end
25
-
26
- it 'initializes @client with proxy' do
27
- expect(Savon).to receive(:client).with(params) { true }
28
- subject
29
- end
30
- end
31
-
32
- context 'without a proxy' do
33
- before { CorreiosSigep.configuration.proxy = nil }
34
- let(:params) do
35
- {
36
- adapter: :net_http_persistent,
37
- wsdl: described_class.new.wsdl,
38
- open_timeout: CorreiosSigep::LogisticReverse::BaseClient::DEFAULT_TIMEOUT,
39
- read_timeout: CorreiosSigep::LogisticReverse::BaseClient::DEFAULT_TIMEOUT,
40
- basic_auth: [user, pass],
41
- headers: { 'SOAPAction' => '' }
42
- }
43
- end
44
-
45
- it 'initializes @client without proxy' do
46
- expect(Savon).to receive(:client).with(params) { true }
47
- subject
48
- end
49
- end
50
- end
51
-
52
- describe '#wsdl' do
53
- subject { described_class.new.wsdl }
54
-
55
- context 'in a test environment' do
56
- it 'returns the staging url' do
57
- allow(ENV).to receive(:[]).with('GEM_ENV').and_return 'test'
58
- expect(subject).to eq 'https://apphom.correios.com.br/logisticaReversaWS/logisticaReversaService/logisticaReversaWS?wsdl'
59
- end
60
- end
61
-
62
- context 'in other environment' do
63
- it 'returns the production url' do
64
- allow(ENV).to receive(:[]).with('GEM_ENV').and_return 'prod'
65
- expect(subject).to eq 'https://cws.correios.com.br/logisticaReversaWS/logisticaReversaService/logisticaReversaWS?wsdl'
66
- end
67
- end
68
-
69
- end
70
-
71
- context 'setting a timeout' do
72
- subject { described_class.new }
73
-
74
- before { CorreiosSigep.configuration.timeout = 15 }
75
- let(:params) do
76
- {
77
- adapter: :net_http_persistent,
78
- wsdl: described_class.new.wsdl,
79
- open_timeout: CorreiosSigep.configuration.timeout,
80
- read_timeout: CorreiosSigep.configuration.timeout,
81
- basic_auth: [user, pass],
82
- headers: { 'SOAPAction' => '' }
83
- }
84
- end
85
-
86
- it 'initializes @client with informed timeout' do
87
- expect(Savon).to receive(:client).with(params) { true }
88
- subject
89
- end
90
- end
91
- end
92
- end
93
- end
@@ -1,106 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module CorreiosSigep
4
- module LogisticReverse
5
- describe RequestCollectNumber do
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' }
11
-
12
- before do
13
- seed_logistic_reverse(logistic_reverse)
14
-
15
- # WSDL
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 => {})
23
-
24
- # REQUEST
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'=>'*/*',
29
- 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
30
- 'User-Agent'=>'Ruby'
31
- }).to_return(:status => 200, :body => correios_fixture("request_collect_number/#{response_body}"), :headers => {})
32
- end
33
-
34
- describe '.process' do
35
- subject { request_collect.process }
36
-
37
- context 'with success response' do
38
- let(:response_body) { 'response_success.xml' }
39
-
40
- it 'returns the collect number' do
41
- expect(subject).to eq '373533437'
42
- end
43
- end
44
-
45
- context 'with ticket already in use' do
46
- let(:response_body) { 'response_already_in_use.xml' }
47
-
48
- it 'raises TicketAlreadyUsed error' do
49
- expect{subject}.to raise_error(Models::Errors::TicketAlreadyUsed)
50
- end
51
- end
52
-
53
- context 'when service is unavailable' do
54
- let(:response_body) { 'response_unavailable_service.xml' }
55
-
56
- it 'raises UnvailableService error' do
57
- expect{subject}.to raise_error(Models::Errors::UnavailableService)
58
- end
59
- end
60
-
61
- context 'when zipcode not exist' do
62
- let(:response_body) { 'response_inexistent_zipcode.xml' }
63
-
64
- it 'raises InexistentZipcode error' do
65
- expect{subject}.to raise_error(Models::Errors::InexistentZipcode)
66
- end
67
- end
68
-
69
- context 'when collect is not available for the house' do
70
- let(:response_body) { 'response_unavailable_house_collect.xml' }
71
-
72
- it 'raises UnavailableHouseCollect error' do
73
- expect{subject}.to raise_error(Models::Errors::UnavailableHouseCollect)
74
- end
75
- end
76
-
77
-
78
- context 'when collect is for a not answered zipcode' do
79
- let(:response_body) { 'response_not_answered_for_zipcode.xml' }
80
-
81
- it 'raises CollectNotAnsweredForTheZipcode error' do
82
- expect{subject}.to raise_error(Models::Errors::CollectNotAnsweredForTheZipcode)
83
- end
84
- end
85
-
86
- context 'when user is not configured to use sigepweb' do
87
- let(:response_body) { 'response_not_configured_client.xml' }
88
-
89
- it 'raises NotConfiguredClient error' do
90
- expect{subject}.to raise_error(Models::Errors::NotConfiguredClient)
91
- end
92
- end
93
-
94
-
95
- context 'when correios answer with another code' do
96
- let(:response_body) { 'response_unexpected.xml' }
97
-
98
- it 'raises UnknownError error' do
99
- expect{subject}.to raise_error(Models::Errors::UnknownError)
100
- end
101
- end
102
-
103
- end
104
- end
105
- end
106
- end
@@ -1,86 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module CorreiosSigep
4
- module LogisticReverse
5
- describe RequestSRO do
6
- let(:sro_params) { { collect_number: '1234', type: 'A' } }
7
- let(:sro) { CorreiosSigep::Models::SRO.new(sro_params) }
8
- let(:body) { request_fixture('sro_request.xml').chop }
9
- let(:user) { 'user' }
10
- let(:pass) { 'pass' }
11
-
12
- before do
13
- # WSDL
14
- stub_request(:get, 'https://apphom.correios.com.br/logisticaReversaWS/logisticaReversaService/logisticaReversaWS?wsdl').
15
- with(basic_auth: [user, pass]).
16
- with(:headers => {
17
- 'Accept'=>'*/*',
18
- 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
19
- 'User-Agent'=>'Ruby'
20
- }).to_return(status: 200, body: correios_fixture('wsdl.xml'), headers: {})
21
-
22
- # REQUEST
23
- stub_request(:post, 'https://apphom.correios.com.br/logisticaReversaWS/logisticaReversaService/logisticaReversaWS').
24
- with(basic_auth: [user, pass]).
25
- with(:body => body, :headers => {
26
- 'Accept'=>'*/*',
27
- 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
28
- 'User-Agent'=>'Ruby'
29
- }).to_return(status: 200, body: correios_fixture("request_sro/#{response_body}"), headers: {})
30
- end
31
-
32
- describe '.process' do
33
- subject { described_class.new(sro).process }
34
-
35
- context 'when successfully brings a SRO' do
36
- let(:response_body) { 'response_success.xml' }
37
-
38
- it 'returns sro ticket' do
39
- expect(subject).to eq 'ETI12345'
40
- end
41
- end
42
-
43
- context 'when SRO is not ready yet' do
44
- let(:response_body) { 'response_sro_not_ready.xml' }
45
-
46
- it 'raises SRONotReady error' do
47
- expect{subject}.to raise_error Models::Errors::SRONotReady
48
- end
49
- end
50
-
51
- context 'when required fields is not filled' do
52
- let(:response_body) { 'response_required_fields.xml' }
53
-
54
- it 'raises RequiredFields error' do
55
- expect{subject}.to raise_error Models::Errors::RequiredFields
56
- end
57
- end
58
-
59
- context 'when CollectNumber does not exist or it is not valid' do
60
- let(:response_body) { 'response_collect_number_not_found.xml' }
61
-
62
- it 'raises CollectNumberNotFound' do
63
- expect{subject}.to raise_error Models::Errors::CollectNumberNotFound
64
- end
65
- end
66
-
67
- context 'with an unknow error' do
68
- let(:response_body) { 'response_unknown_error.xml' }
69
-
70
- it 'raises UnkowError' do
71
- expect{subject}.to raise_error Models::Errors::UnknownError
72
- end
73
- end
74
-
75
- context 'when response is an array' do
76
- let(:response_body) { 'response_array_success.xml' }
77
-
78
- it 'returns sro ticket' do
79
- expect(subject).to eq 'ETI12345'
80
- end
81
- end
82
-
83
- end
84
- end
85
- end
86
- end