correios-cep 0.5.0 → 0.5.1

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: 37ca8dbe26d97bd4264d9c02a66ba229d7014d92
4
- data.tar.gz: c92f319267e2fb49a431c110753ce6c6206022bf
3
+ metadata.gz: 16943d9f8d0f187364d858f8d0df8bb83e19c5ec
4
+ data.tar.gz: 0250306e8ce1b0039d25a6d1c52af6221e0e2229
5
5
  SHA512:
6
- metadata.gz: c620b2d30da1e0f7485f68300c1e115cf22bccb19fa917c4af9be36a21bee09a5849bdf93ca02926a7093c8539d2841fc81287eb90c59032375d54d6691a3b4f
7
- data.tar.gz: 7376ae683db061ed2b5070e056c686f98e191911d6cedb2670e9fa561319a54d5637db32044eb9b47f4a398a45112ddfa4b00c789cfac57cb250e3eda35443fe
6
+ metadata.gz: 5b57fd6f6a44b73442094e683d1222e36cc0f9330acb96d08bc94ea0053be22f3b37368bfd34354e8ef78ed4eca7475f029773d69143d27c19ea22a8c49b423d
7
+ data.tar.gz: 5dd164f88e74adfcae72e905d1c62d1e7c4acdc421fa4309708c650a7b4c62ad9d8ce041535e96f4aa7e89efdfb3e18771f5e0304dcb8d8bf6189060137b464a
@@ -1,40 +1,16 @@
1
- ## Version 0.5.0
2
- - Fix: Handle errors returned from Correios web service. [Issue #10](https://github.com/prodis/correios-cep/issues/10)
3
- - Improvent: Zipcode input validation.
4
-
5
- ## Version 0.4.0
6
- - Improvement: Replace Nokogiri by Ox. [Issue #3](https://github.com/prodis/correios-cep/issues/3).
7
-
8
- ## Version 0.3.3
9
- - Fix: Downgrade LogMe gem version to 0.0.8, because 0.0.9 does not support Ruby 1.9.2.
10
-
11
- ## Version 0.3.2
12
- - Update: Optional HTTP requests using HTTP proxy.
13
- - Improvement: Update LogMe gem version to 0.0.9.
14
-
15
- ## Version 0.3.1
16
- - Warning: Minimal required Ruby version is 1.9.2 again.
17
-
18
- ## Version 0.3.0
19
- - Update: Update Correios Web Service URL.
20
-
21
- ## Version 0.2.0
22
- - Warning: Minimal required Ruby version from now is 1.9.3.
23
-
24
- ## Version 0.1.4
25
- - Improvement: Minimal required Ruby version now is 1.9.2.
26
-
27
- ## Version 0.1.3
28
- - Improvement: Update LogMe gem to version 0.0.6 with support to log request and response messages.
29
-
30
- ## Version 0.1.2
31
- - Improvement: Update LogMe gem to version 0.0.5 with support to log messages label.
32
-
33
- ## Version 0.1.1
34
- - New: A `get` class method in `AddressFinder` class.
35
-
36
- ## Version 0.1.0
37
- - First working version.
38
-
39
- ## Version 0.0.1
40
- - First version, not working yet.
1
+ | Version | Changes |
2
+ | ------- | ------- |
3
+ | 0.5.1 | Zipcode input validation improvement. |
4
+ | 0.5.0 | Handle errors returned from Correios web service. [Issue #10](https://github.com/prodis/correios-cep/issues/10); Zipcode input validation. |
5
+ | 0.4.0 | Replace Nokogiri by Ox. [Issue #3](https://github.com/prodis/correios-cep/issues/3) |
6
+ | 0.3.3 | Downgrade LogMe gem version to 0.0.8, because 0.0.9 does not support Ruby 1.9.2. |
7
+ | 0.3.2 | Optional use of HTTP proxy; Update LogMe gem version to 0.0.9. |
8
+ | 0.3.1 | Minimal required Ruby version is 1.9.2 again. |
9
+ | 0.3.0 | Update Correios web service URL. |
10
+ | 0.2.0 | Minimal required Ruby version from now is 1.9.3. |
11
+ | 0.1.4 | Minimal required Ruby version now is 1.9.2. |
12
+ | 0.1.3 | Update LogMe gem to version 0.0.6 with support to log request and response messages. |
13
+ | 0.1.2 | Update LogMe gem to version 0.0.5 with support to log messages label. |
14
+ | 0.1.1 | `AddressFinder.get` class method. |
15
+ | 0.1.0 | First working version. |
16
+ | 0.0.1 | First version, not working yet. |
data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
- source "http://rubygems.org"
1
+ source 'http://rubygems.org'
2
2
  gemspec
data/README.md CHANGED
@@ -1,55 +1,56 @@
1
1
  # Correios CEP
2
2
 
3
- Current available solutions to find Brazilian addresses by zipcode use an HTML form from Correios web site to perform it, instead of to use a real API.
3
+ Current available solutions to find Brazilian addresses by zipcode use an HTML form from [Correios web site](http://correios.com.br) to perform it, instead of to use a real API.
4
4
 
5
5
  The old solution works with an HTTP request to the form, followed by parsing the HTML result page. The huge problem here is when the Correios web site development team decides to modify some HTML element in the result page, even a layout update, it will break the parser logic for result.
6
6
 
7
7
  Correios CEP gem solves this problem, getting data directly from Correios database.
8
8
 
9
- ![Correios Logo](http://prodis.net.br/images/ruby/2011/correios_logo.png)
9
+ ![Correios Logo](http://prodis.net.br/images/ruby/2015/correios_logo.png)
10
10
 
11
- [![Gem Version](https://badge.fury.io/rb/correios-cep.png)](http://badge.fury.io/rb/correios-cep)
12
- [![Build Status](https://travis-ci.org/prodis/correios-cep.png?branch=master)](https://travis-ci.org/prodis/correios-cep)
13
- [![Coverage Status](https://coveralls.io/repos/prodis/correios-cep/badge.png)](https://coveralls.io/r/prodis/correios-cep)
14
- [![Code Climate](https://codeclimate.com/github/prodis/correios-cep.png)](https://codeclimate.com/github/prodis/correios-cep)
15
- [![Dependency Status](https://gemnasium.com/prodis/correios-cep.png)](https://gemnasium.com/prodis/correios-cep)
11
+ [![Gem Version](https://badge.fury.io/rb/correios-cep.svg)](http://badge.fury.io/rb/correios-cep)
12
+ [![Build Status](https://travis-ci.org/prodis/correios-cep.svg?branch=master)](https://travis-ci.org/prodis/correios-cep)
13
+ [![Coverage Status](https://coveralls.io/repos/prodis/correios-cep/badge.svg?branch=master&service=github)](https://coveralls.io/github/prodis/correios-cep?branch=master)
14
+ [![Code Climate](https://codeclimate.com/github/prodis/correios-cep/badges/gpa.svg)](https://codeclimate.com/github/prodis/correios-cep)
15
+ [![Dependency Status](https://gemnasium.com/prodis/correios-cep.svg)](https://gemnasium.com/prodis/correios-cep)
16
+ [![GitHub license](https://img.shields.io/apm/l/vim-mode.svg)](LICENSE)
16
17
 
17
18
  ## Installing
18
19
 
19
20
  ### Gemfile
20
21
 
21
22
  ```ruby
22
- gem 'correios-cep'
23
+ gem 'correios-cep'
23
24
  ```
24
25
 
25
26
  ### Direct installation
26
27
 
27
28
  ```console
28
- $ gem install correios-cep
29
+ $ gem install correios-cep
29
30
  ```
30
31
 
31
32
 
32
33
  ## Using
33
34
 
34
35
  ```ruby
35
- require 'correios-cep'
36
-
37
- # With "get" instance method
38
- finder = Correios::CEP::AddressFinder.new
39
- address = finder.get("54250610")
40
-
41
- # With "get" class method
42
- address = Correios::CEP::AddressFinder.get("54250610")
43
-
44
- address # =>
45
- {
46
- :address => "Rua Fernando Amorim",
47
- :neighborhood => "Cavaleiro",
48
- :city => "Jaboatão dos Guararapes",
49
- :state => "PE",
50
- :zipcode => "54250610",
51
- :complement => ""
52
- }
36
+ require 'correios-cep'
37
+
38
+ # With "get" instance method
39
+ finder = Correios::CEP::AddressFinder.new
40
+ address = finder.get("54250610")
41
+
42
+ # With "get" class method
43
+ address = Correios::CEP::AddressFinder.get("54250610")
44
+
45
+ address # =>
46
+ {
47
+ :address => "Rua Fernando Amorim",
48
+ :neighborhood => "Cavaleiro",
49
+ :city => "Jaboatão dos Guararapes",
50
+ :state => "PE",
51
+ :zipcode => "54250610",
52
+ :complement => ""
53
+ }
53
54
  ```
54
55
 
55
56
  ## Configurations
@@ -60,18 +61,18 @@ For default, the timeout for a request to Correios Web Service is **5 seconds**.
60
61
  You can configure this timeout using `Correios::CEP` module.
61
62
 
62
63
  ```ruby
63
- Correios::CEP.configure do |config|
64
- config.request_timeout = 3 # It configures timeout to 3 seconds
65
- end
64
+ Correios::CEP.configure do |config|
65
+ config.request_timeout = 3 # It configures timeout to 3 seconds
66
+ end
66
67
  ```
67
68
 
68
69
  ### HTTP Proxy
69
70
  If you need to use an HTTP proxy to HTTP requests, configure the HTTP proxy URL on `Correios::CEP` module.
70
71
 
71
72
  ```ruby
72
- Correios::CEP.configure do |config|
73
- config.proxy_url = "http://10.20.30.40:8888"
74
- end
73
+ Correios::CEP.configure do |config|
74
+ config.proxy_url = "http://10.20.30.40:8888"
75
+ end
75
76
  ```
76
77
 
77
78
  ### Log
@@ -81,55 +82,55 @@ For default, each request to Correios Web service is logged to STDOUT, with **:i
81
82
  Log example:
82
83
 
83
84
  ```xml
84
- I, [2014-02-14T00:10:12.718413 #76361] INFO -- : [Correios::CEP] Request:
85
- POST http://200.252.60.209/SigepCliente/AtendeClienteService
86
- <?xml version="1.0" encoding="UTF-8"?>
87
- <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cli="http://cliente.bean.master.sigep.bsb.correios.com.br/">
88
- <soapenv:Header />
89
- <soapenv:Body>
90
- <cli:consultaCEP>
85
+ I, [2014-02-14T00:10:12.718413 #76361] INFO -- : [Correios::CEP] Request:
86
+ POST http://200.252.60.209/SigepCliente/AtendeClienteService
87
+ <?xml version="1.0" encoding="UTF-8"?>
88
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cli="http://cliente.bean.master.sigep.bsb.correios.com.br/">
89
+ <soapenv:Header />
90
+ <soapenv:Body>
91
+ <cli:consultaCEP>
92
+ <cep>54250610</cep>
93
+ </cli:consultaCEP>
94
+ </soapenv:Body>
95
+ </soapenv:Envelope>
96
+
97
+ I, [2014-02-14T00:10:12.969937 #76361] INFO -- : [Correios::CEP] Response:
98
+ HTTP/1.1 200 OK
99
+ <?xml version='1.0' encoding='UTF-8'?>
100
+ <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
101
+ <S:Body>
102
+ <ns2:consultaCEPResponse xmlns:ns2="http://cliente.bean.master.sigep.bsb.correios.com.br/">
103
+ <return>
104
+ <bairro>Cavaleiro</bairro>
91
105
  <cep>54250610</cep>
92
- </cli:consultaCEP>
93
- </soapenv:Body>
94
- </soapenv:Envelope>
95
-
96
- I, [2014-02-14T00:10:12.969937 #76361] INFO -- : [Correios::CEP] Response:
97
- HTTP/1.1 200 OK
98
- <?xml version='1.0' encoding='UTF-8'?>
99
- <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
100
- <S:Body>
101
- <ns2:consultaCEPResponse xmlns:ns2="http://cliente.bean.master.sigep.bsb.correios.com.br/">
102
- <return>
103
- <bairro>Cavaleiro</bairro>
104
- <cep>54250610</cep>
105
- <cidade>Jaboatão dos Guararapes</cidade>
106
- <complemento></complemento>
107
- <complemento2></complemento2>
108
- <end>Rua Fernando Amorim</end>
109
- <id>0</id>
110
- <uf>PE</uf>
111
- </return>
112
- </ns2:consultaCEPResponse>
113
- </S:Body>
114
- </S:Envelope>
106
+ <cidade>Jaboatão dos Guararapes</cidade>
107
+ <complemento></complemento>
108
+ <complemento2></complemento2>
109
+ <end>Rua Fernando Amorim</end>
110
+ <id>0</id>
111
+ <uf>PE</uf>
112
+ </return>
113
+ </ns2:consultaCEPResponse>
114
+ </S:Body>
115
+ </S:Envelope>
115
116
  ```
116
117
 
117
118
  To disable the log and configure other log output, use **Correios::CEP** module:
118
119
 
119
120
  ```ruby
120
- Correios::CEP.configure do |config|
121
- config.log_enabled = false # It disables the log
122
- config.logger = Rails.logger # It uses Rails logger
123
- end
124
- ```
121
+ Correios::CEP.configure do |config|
122
+ config.log_enabled = false # It disables the log
123
+ config.logger = Rails.logger # It uses Rails logger
124
+ end
125
+ ```
125
126
 
126
127
  ### Configuration example
127
128
 
128
129
  ```ruby
129
- Correios::CEP.configure do |config|
130
- config.logger = Rails.logger
131
- config.request_timeout = 3
132
- end
130
+ Correios::CEP.configure do |config|
131
+ config.logger = Rails.logger
132
+ config.request_timeout = 3
133
+ end
133
134
  ```
134
135
 
135
136
  ## Changelog
@@ -137,11 +138,17 @@ To disable the log and configure other log output, use **Correios::CEP** module:
137
138
  [See the changes in each version.](CHANGELOG.md)
138
139
 
139
140
 
140
- ## Author
141
+ ## Credits
142
+
143
+ ### Author
141
144
  - [Fernando Hamasaki de Amorim (prodis)](http://prodis.blog.br)
142
145
 
143
146
  ![Prodis Logo](http://prodis.net.br/images/prodis_150.gif)
144
147
 
148
+ ### Contributors
149
+ - [Gabriel Givigier Guimarães (givigier)](https://github.com/givigier)
150
+ - [Maury M. Marques (maurymmarques)](https://github.com/maurymmarques)
151
+
145
152
 
146
153
  ## Contributing to correios-cep
147
154
 
data/Rakefile CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env rake
2
- require "bundler/gem_tasks"
2
+ require 'bundler/gem_tasks'
@@ -1,32 +1,32 @@
1
- lib = File.expand_path("../lib", __FILE__)
1
+ lib = File.expand_path('../lib', __FILE__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require "correios/cep/version"
3
+ require 'correios/cep/version'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = "correios-cep"
6
+ spec.name = 'correios-cep'
7
7
  spec.version = Correios::CEP::VERSION
8
- spec.authors = ["Prodis a.k.a. Fernando Hamasaki de Amorim"]
9
- spec.email = ["prodis@gmail.com"]
10
- spec.description = %q{Correios CEP gem gets updated Brazilian address from a zipcode, directly from Correios database. No HTML parsers.}
11
- spec.summary = spec.description
12
- spec.homepage = "http://prodis.blog.br/correios-cep-gem-para-consulta-de-enderecos-por-cep"
13
- spec.license = "MIT"
8
+ spec.author = 'Prodis a.k.a. Fernando Hamasaki de Amorim'
9
+ spec.email = 'prodis@gmail.com'
10
+ spec.summary = 'Correios CEP gem gets updated Brazilian address from a zipcode, directly from Correios database. No HTML parsers.'
11
+ spec.description = spec.summary
12
+ spec.homepage = 'http://prodis.blog.br/correios-cep-gem-para-consulta-de-enderecos-por-cep'
13
+ spec.license = 'MIT'
14
14
 
15
15
  spec.files = `git ls-files`.split($/)
16
16
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
- spec.require_paths = ["lib"]
18
+ spec.require_paths = ['lib']
19
19
 
20
- spec.platform = Gem::Platform::RUBY
21
- spec.required_ruby_version = Gem::Requirement.new(">= 1.9.2")
20
+ spec.platform = Gem::Platform::RUBY
21
+ spec.required_ruby_version = Gem::Requirement.new('>= 1.9.2')
22
22
 
23
- spec.add_dependency "log-me", "= 0.0.8"
24
- spec.add_dependency "ox", "~> 2.2"
23
+ spec.add_dependency 'log-me', '= 0.0.8'
24
+ spec.add_dependency 'ox', '~> 2.2.2'
25
25
 
26
- spec.add_development_dependency "coveralls", "~> 0.8.3"
27
- spec.add_development_dependency "pry", "~> 0.10.3"
28
- spec.add_development_dependency "rake", "~> 10.4", ">= 10.4.2"
29
- spec.add_development_dependency "rspec", "~> 3.2"
30
- spec.add_development_dependency "vcr", "~> 2.9"
31
- spec.add_development_dependency "webmock", "~> 1.15"
26
+ spec.add_development_dependency 'coveralls', '~> 0.8.3'
27
+ spec.add_development_dependency 'pry', '~> 0.10.3'
28
+ spec.add_development_dependency 'rake', '~> 10.4.2'
29
+ spec.add_development_dependency 'rspec', '~> 3.3.0'
30
+ spec.add_development_dependency 'vcr', '~> 3.0.0'
31
+ spec.add_development_dependency 'webmock', '~> 1.22.2'
32
32
  end
@@ -1,32 +1,30 @@
1
1
  module Correios
2
2
  module CEP
3
3
  class AddressFinder
4
+ def initialize(args = {})
5
+ @web_service = args.fetch(:web_service, Correios::CEP::WebService.new)
6
+ @parser = args.fetch(:parser, Correios::CEP::Parser.new)
7
+ end
8
+
4
9
  def get(zipcode)
10
+ zipcode = zipcode.to_s.strip
5
11
  validate(zipcode)
12
+
6
13
  response = web_service.request(zipcode)
7
14
  parser.address(response)
8
15
  end
9
16
 
10
- def self.get(zipcode)
11
- self.new.get(zipcode)
17
+ def self.get(zipcode, args = {})
18
+ self.new(args).get(zipcode)
12
19
  end
13
20
 
14
21
  private
15
22
 
16
- def web_service
17
- @web_service ||= Correios::CEP::WebService.new
18
- end
19
-
20
- def parser
21
- @parser ||= Correios::CEP::Parser.new
22
- end
23
-
24
- private
23
+ attr_reader :web_service, :parser
25
24
 
26
25
  def validate(zipcode)
27
- if zipcode.to_s.strip.empty? || !zipcode.to_s.match(/\A\d{5}-?\d{3}\z/)
28
- raise ArgumentError.new("invalid cep format")
29
- end
26
+ raise ArgumentError.new('zipcode is required') if zipcode.empty?
27
+ raise ArgumentError.new('zipcode in invalid format (valid format: 00000-000)') unless zipcode.match(/\A\d{5}-?\d{3}\z/)
30
28
  end
31
29
  end
32
30
  end
@@ -1,5 +1,5 @@
1
1
  module Correios
2
2
  module CEP
3
- VERSION = '0.5.0'
3
+ VERSION = '0.5.1'
4
4
  end
5
5
  end
@@ -52,15 +52,15 @@ module Correios
52
52
  end
53
53
 
54
54
  def request_body(zipcode)
55
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
56
- "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:cli=\"http://cliente.bean.master.sigep.bsb.correios.com.br/\">" +
57
- "<soapenv:Header />" +
58
- "<soapenv:Body>" +
59
- "<cli:consultaCEP>" +
55
+ '<?xml version="1.0" encoding="UTF-8"?>' +
56
+ '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cli="http://cliente.bean.master.sigep.bsb.correios.com.br/">' +
57
+ '<soapenv:Header />' +
58
+ '<soapenv:Body>' +
59
+ '<cli:consultaCEP>' +
60
60
  "<cep>#{zipcode}</cep>" +
61
- "</cli:consultaCEP>" +
62
- "</soapenv:Body>" +
63
- "</soapenv:Envelope>"
61
+ '</cli:consultaCEP>' +
62
+ '</soapenv:Body>' +
63
+ '</soapenv:Envelope>'
64
64
  end
65
65
  end
66
66
  end
@@ -1,35 +1,51 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Correios::CEP::AddressFinder do
4
- context "with invalid cep" do
5
- it "should raise ArgumentError when cep is nil" do
6
- expect{ subject.get(nil) }.to raise_error(ArgumentError)
7
- end
8
-
9
- it "should raise ArgumentError when cep does not have a valid format" do
10
- expect{ subject.get("542506-10") }.to raise_error(ArgumentError)
11
- end
12
- end
13
-
14
- context "with valid cep" do
4
+ context 'when zipcode is valid' do
15
5
  let(:cep) { '54250610' }
16
- let(:web_service_response) { "<end>Rua Fernando Amorim</end>" }
17
- let(:address) { { address: "Rua Fernando Amorim" } }
6
+ let(:web_service_response) { '<end>Rua Fernando Amorim</end>' }
7
+ let(:address) { { address: 'Rua Fernando Amorim' } }
8
+ let(:web_service) { double(Correios::CEP::WebService) }
9
+ let(:parser) { double(Correios::CEP::Parser) }
10
+ let(:dependencies) { { web_service: web_service, parser: parser } }
11
+
12
+ subject { described_class.new(dependencies) }
18
13
 
19
14
  before do
20
- allow_any_instance_of(Correios::CEP::WebService).to receive(:request).with(cep){ web_service_response }
21
- allow_any_instance_of(Correios::CEP::Parser).to receive(:address).with(web_service_response){ address }
15
+ allow(web_service).to receive(:request).with(cep).and_return(web_service_response)
16
+ allow(parser).to receive(:address).with(web_service_response).and_return(address)
22
17
  end
23
18
 
24
- describe "#get" do
25
- it "returns address" do
26
- expect(subject.get(cep)).to eql address
19
+ describe '#get' do
20
+ it 'returns address' do
21
+ expect(subject.get(cep)).to eq address
27
22
  end
28
23
  end
29
24
 
30
- describe ".get" do
31
- it "returns address" do
32
- expect(Correios::CEP::AddressFinder.get(cep)).to eql address
25
+ describe '.get' do
26
+ subject { described_class }
27
+
28
+ it 'returns address' do
29
+ expect(subject.get(cep, dependencies)).to eq address
30
+ end
31
+ end
32
+ end
33
+
34
+ {
35
+ 'zipcode is required' => {
36
+ 'is nil' => nil,
37
+ 'is empty' => ''
38
+ },
39
+ 'zipcode in invalid format (valid format: 00000-000)' => {
40
+ 'has less than 8 digits' => '1234567',
41
+ 'has invalid format' => '1234-5678'
42
+ }
43
+ }.each do |error_message, values|
44
+ values.each do |text, value|
45
+ context "when zipcode #{text}" do
46
+ it "raises ArgumentError with '#{error_message}' error message" do
47
+ expect { subject.get(value) }.to raise_error(ArgumentError, error_message)
48
+ end
33
49
  end
34
50
  end
35
51
  end
@@ -2,68 +2,66 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Correios::CEP::Parser do
5
- describe "#address" do
5
+ describe '#address' do
6
6
  let(:expected_address) do
7
7
  {
8
- address: "Rua Fernando Amorim",
9
- neighborhood: "Cavaleiro",
10
- city: "Jaboatão dos Guararapes",
11
- state: "PE",
12
- zipcode: "54250610",
13
- complement: ""
8
+ address: 'Rua Fernando Amorim',
9
+ neighborhood: 'Cavaleiro',
10
+ city: 'Jaboatão dos Guararapes',
11
+ state: 'PE',
12
+ zipcode: '54250610',
13
+ complement: ''
14
14
  }
15
15
  end
16
16
 
17
- context "when address is found" do
18
- context "and does not have complement" do
17
+ context 'when address is found' do
18
+ context 'and does not have complement' do
19
19
  let(:xml) do
20
- "<?xml version='1.0' encoding='UTF-8'?>" +
21
- "<S:Envelope>" +
22
- "<S:Body>" +
23
- "<ns2:consultaCEPResponse xmlns:ns2=\"http://cliente.bean.master.sigep.bsb.correios.com.br/\">" +
24
- "<return>" +
25
- "<bairro>Cavaleiro</bairro>" +
26
- "<cep>54250610</cep>" +
27
- "<cidade>Jaboatão dos Guararapes</cidade>" +
28
- "<complemento></complemento>" +
29
- "<complemento2></complemento2>" +
30
- "<end>Rua Fernando Amorim</end>" +
31
- "<id>0</id>" +
32
- "<uf>PE</uf>" +
33
- "</return>" +
34
- "</ns2:consultaCEPResponse>" +
35
- "</S:Body>" +
36
- "</S:Envelope>"
20
+ '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
21
+ '<soap:Body>' +
22
+ '<ns2:consultaCEPResponse xmlns:ns2="http://cliente.bean.master.sigep.bsb.correios.com.br/">' +
23
+ '<return>' +
24
+ '<bairro>Cavaleiro</bairro>' +
25
+ '<cep>54250610</cep>' +
26
+ '<cidade>Jaboatão dos Guararapes</cidade>' +
27
+ '<complemento></complemento>' +
28
+ '<complemento2></complemento2>' +
29
+ '<end>Rua Fernando Amorim</end>' +
30
+ '<id>0</id>' +
31
+ '<uf>PE</uf>' +
32
+ '</return>' +
33
+ '</ns2:consultaCEPResponse>' +
34
+ '</soap:Body>' +
35
+ '</soap:Envelope>'
37
36
  end
38
37
 
39
- it "returns address" do
38
+ it 'returns address' do
40
39
  expect(subject.address(xml)).to eq expected_address
41
40
  end
42
41
  end
43
42
 
44
43
  context 'and has one complement' do
45
44
  let(:xml) do
46
- "<?xml version='1.0' encoding='UTF-8'?>" +
47
- "<S:Envelope>" +
48
- "<S:Body>" +
49
- "<ns2:consultaCEPResponse xmlns:ns2=\"http://cliente.bean.master.sigep.bsb.correios.com.br/\">" +
50
- "<return>" +
51
- "<bairro>Cavaleiro</bairro>" +
52
- "<cep>54250610</cep>" +
53
- "<cidade>Jaboatão dos Guararapes</cidade>" +
54
- "<complemento>de 1500 até o fim</complemento>" +
55
- "<complemento2></complemento2>" +
56
- "<end>Rua Fernando Amorim</end>" +
57
- "<id>0</id>" +
58
- "<uf>PE</uf>" +
59
- "</return>" +
60
- "</ns2:consultaCEPResponse>" +
61
- "</S:Body>" +
62
- "</S:Envelope>"
45
+ '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
46
+ '<soap:Body>' +
47
+ '<ns2:consultaCEPResponse xmlns:ns2="http://cliente.bean.master.sigep.bsb.correios.com.br/">' +
48
+ '<return>' +
49
+ '<bairro>Cavaleiro</bairro>' +
50
+ '<cep>54250610</cep>' +
51
+ '<cidade>Jaboatão dos Guararapes</cidade>' +
52
+ '<complemento>de 1500 até o fim</complemento>' +
53
+ '<complemento2></complemento2>' +
54
+ '<end>Rua Fernando Amorim</end>' +
55
+ '<id>0</id>' +
56
+ '<uf>PE</uf>' +
57
+ '</return>' +
58
+ '</ns2:consultaCEPResponse>' +
59
+ '</soap:Body>' +
60
+ '</soap:Envelope>'
63
61
  end
64
62
 
65
- it "returns address" do
66
- expected_address[:complement] = "de 1500 até o fim"
63
+ it 'returns address' do
64
+ expected_address[:complement] = 'de 1500 até o fim'
67
65
 
68
66
  expect(subject.address(xml)).to eq expected_address
69
67
  end
@@ -71,27 +69,26 @@ describe Correios::CEP::Parser do
71
69
 
72
70
  context 'and has two complements' do
73
71
  let(:xml) do
74
- "<?xml version='1.0' encoding='UTF-8'?>" +
75
- "<S:Envelope>" +
76
- "<S:Body>" +
77
- "<ns2:consultaCEPResponse xmlns:ns2=\"http://cliente.bean.master.sigep.bsb.correios.com.br/\">" +
78
- "<return>" +
79
- "<bairro>Cavaleiro</bairro>" +
80
- "<cep>54250610</cep>" +
81
- "<cidade>Jaboatão dos Guararapes</cidade>" +
82
- "<complemento>de 1500 até o fim</complemento>" +
83
- "<complemento2>(zona mista)</complemento2>" +
84
- "<end>Rua Fernando Amorim</end>" +
85
- "<id>0</id>" +
86
- "<uf>PE</uf>" +
87
- "</return>" +
88
- "</ns2:consultaCEPResponse>" +
89
- "</S:Body>" +
90
- "</S:Envelope>"
72
+ '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
73
+ '<soap:Body>' +
74
+ '<ns2:consultaCEPResponse xmlns:ns2="http://cliente.bean.master.sigep.bsb.correios.com.br/">' +
75
+ '<return>' +
76
+ '<bairro>Cavaleiro</bairro>' +
77
+ '<cep>54250610</cep>' +
78
+ '<cidade>Jaboatão dos Guararapes</cidade>' +
79
+ '<complemento>de 1500 até o fim</complemento>' +
80
+ '<complemento2>(zona mista)</complemento2>' +
81
+ '<end>Rua Fernando Amorim</end>' +
82
+ '<id>0</id>' +
83
+ '<uf>PE</uf>' +
84
+ '</return>' +
85
+ '</ns2:consultaCEPResponse>' +
86
+ '</soap:Body>' +
87
+ '</soap:Envelope>'
91
88
  end
92
89
 
93
- it "returns address" do
94
- expected_address[:complement] = "de 1500 até o fim (zona mista)"
90
+ it 'returns address' do
91
+ expected_address[:complement] = 'de 1500 até o fim (zona mista)'
95
92
 
96
93
  expect(subject.address(xml)).to eq expected_address
97
94
  end
@@ -100,15 +97,20 @@ describe Correios::CEP::Parser do
100
97
 
101
98
  context 'when address is not found' do
102
99
  let(:xml) do
103
- "<?xml version='1.0' encoding='UTF-8'?>" +
104
- "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
105
- "<S:Body>" +
106
- "<ns2:consultaCEPResponse xmlns:ns2=\"http://cliente.bean.master.sigep.bsb.correios.com.br/\"/>" +
107
- "</S:Body>" +
108
- "</S:Envelope>"
100
+ '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
101
+ '<soap:Body>' +
102
+ '<soap:Fault>' +
103
+ '<faultcode>soap:Server</faultcode>' +
104
+ '<faultstring>CEP NAO ENCONTRADO</faultstring>' +
105
+ '<detail>' +
106
+ '<ns2:SigepClienteException xmlns:ns2="http://cliente.bean.master.sigep.bsb.correios.com.br/">CEP NAO ENCONTRADO</ns2:SigepClienteException>' +
107
+ '</detail>' +
108
+ '</soap:Fault>' +
109
+ '</soap:Body>' +
110
+ '</soap:Envelope>'
109
111
  end
110
112
 
111
- it "returns empty hash" do
113
+ it 'returns empty hash' do
112
114
  expect(subject.address(xml)).to eq({})
113
115
  end
114
116
  end
@@ -10,7 +10,7 @@ describe Correios::CEP::WebService do
10
10
  Correios::CEP.log_enabled = true
11
11
  end
12
12
 
13
- it 'returns HTTP response body from Correios Web Service' do
13
+ it 'returns HTTP response body from Correios web service' do
14
14
  result = subject.request(cep)
15
15
  expect(result).to include('Rua Fernando Amorim')
16
16
  end
@@ -23,7 +23,7 @@ http_interactions:
23
23
  message: OK
24
24
  headers:
25
25
  Date:
26
- - Fri, 20 Mar 2015 20:30:48 GMT
26
+ - Tue, 03 Nov 2015 00:23:04 GMT
27
27
  Content-Type:
28
28
  - text/xml;charset=UTF-8
29
29
  Vary:
@@ -44,5 +44,5 @@ http_interactions:
44
44
  ZD48dWY+UEU8L3VmPjwvcmV0dXJuPjwvbnMyOmNvbnN1bHRhQ0VQUmVzcG9u
45
45
  c2U+PC9zb2FwOkJvZHk+PC9zb2FwOkVudmVsb3BlPg==
46
46
  http_version:
47
- recorded_at: Fri, 20 Mar 2015 20:30:48 GMT
48
- recorded_with: VCR 2.9.3
47
+ recorded_at: Tue, 03 Nov 2015 00:23:06 GMT
48
+ recorded_with: VCR 3.0.0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: correios-cep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Prodis a.k.a. Fernando Hamasaki de Amorim
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-30 00:00:00.000000000 Z
11
+ date: 2015-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: log-me
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.2'
33
+ version: 2.2.2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.2'
40
+ version: 2.2.2
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: coveralls
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -71,9 +71,6 @@ dependencies:
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '10.4'
76
- - - ">="
77
74
  - !ruby/object:Gem::Version
78
75
  version: 10.4.2
79
76
  type: :development
@@ -81,9 +78,6 @@ dependencies:
81
78
  version_requirements: !ruby/object:Gem::Requirement
82
79
  requirements:
83
80
  - - "~>"
84
- - !ruby/object:Gem::Version
85
- version: '10.4'
86
- - - ">="
87
81
  - !ruby/object:Gem::Version
88
82
  version: 10.4.2
89
83
  - !ruby/object:Gem::Dependency
@@ -92,46 +86,45 @@ dependencies:
92
86
  requirements:
93
87
  - - "~>"
94
88
  - !ruby/object:Gem::Version
95
- version: '3.2'
89
+ version: 3.3.0
96
90
  type: :development
97
91
  prerelease: false
98
92
  version_requirements: !ruby/object:Gem::Requirement
99
93
  requirements:
100
94
  - - "~>"
101
95
  - !ruby/object:Gem::Version
102
- version: '3.2'
96
+ version: 3.3.0
103
97
  - !ruby/object:Gem::Dependency
104
98
  name: vcr
105
99
  requirement: !ruby/object:Gem::Requirement
106
100
  requirements:
107
101
  - - "~>"
108
102
  - !ruby/object:Gem::Version
109
- version: '2.9'
103
+ version: 3.0.0
110
104
  type: :development
111
105
  prerelease: false
112
106
  version_requirements: !ruby/object:Gem::Requirement
113
107
  requirements:
114
108
  - - "~>"
115
109
  - !ruby/object:Gem::Version
116
- version: '2.9'
110
+ version: 3.0.0
117
111
  - !ruby/object:Gem::Dependency
118
112
  name: webmock
119
113
  requirement: !ruby/object:Gem::Requirement
120
114
  requirements:
121
115
  - - "~>"
122
116
  - !ruby/object:Gem::Version
123
- version: '1.15'
117
+ version: 1.22.2
124
118
  type: :development
125
119
  prerelease: false
126
120
  version_requirements: !ruby/object:Gem::Requirement
127
121
  requirements:
128
122
  - - "~>"
129
123
  - !ruby/object:Gem::Version
130
- version: '1.15'
124
+ version: 1.22.2
131
125
  description: Correios CEP gem gets updated Brazilian address from a zipcode, directly
132
126
  from Correios database. No HTML parsers.
133
- email:
134
- - prodis@gmail.com
127
+ email: prodis@gmail.com
135
128
  executables: []
136
129
  extensions: []
137
130
  extra_rdoc_files: []