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 +4 -4
- data/CHANGELOG.md +16 -40
- data/Gemfile +1 -1
- data/README.md +80 -73
- data/Rakefile +1 -1
- data/correios-cep.gemspec +20 -20
- data/lib/correios/cep/address_finder.rb +12 -14
- data/lib/correios/cep/version.rb +1 -1
- data/lib/correios/cep/web_service.rb +8 -8
- data/spec/correios/cep/address_finder_spec.rb +38 -22
- data/spec/correios/cep/parser_spec.rb +74 -72
- data/spec/correios/cep/web_service_spec.rb +1 -1
- data/spec/fixtures/cassettes/correios_consulta_cep_ok.yml +3 -3
- metadata +11 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16943d9f8d0f187364d858f8d0df8bb83e19c5ec
|
4
|
+
data.tar.gz: 0250306e8ce1b0039d25a6d1c52af6221e0e2229
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b57fd6f6a44b73442094e683d1222e36cc0f9330acb96d08bc94ea0053be22f3b37368bfd34354e8ef78ed4eca7475f029773d69143d27c19ea22a8c49b423d
|
7
|
+
data.tar.gz: 5dd164f88e74adfcae72e905d1c62d1e7c4acdc421fa4309708c650a7b4c62ad9d8ce041535e96f4aa7e89efdfb3e18771f5e0304dcb8d8bf6189060137b464a
|
data/CHANGELOG.md
CHANGED
@@ -1,40 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
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/
|
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.
|
12
|
-
[![Build Status](https://travis-ci.org/prodis/correios-cep.
|
13
|
-
[![Coverage Status](https://coveralls.io/repos/prodis/correios-cep/badge.
|
14
|
-
[![Code Climate](https://codeclimate.com/github/prodis/correios-cep.
|
15
|
-
[![Dependency Status](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
|
-
|
23
|
+
gem 'correios-cep'
|
23
24
|
```
|
24
25
|
|
25
26
|
### Direct installation
|
26
27
|
|
27
28
|
```console
|
28
|
-
|
29
|
+
$ gem install correios-cep
|
29
30
|
```
|
30
31
|
|
31
32
|
|
32
33
|
## Using
|
33
34
|
|
34
35
|
```ruby
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
64
|
-
|
65
|
-
|
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
|
-
|
73
|
-
|
74
|
-
|
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
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
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
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
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
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
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
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
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
|
-
##
|
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
|
2
|
+
require 'bundler/gem_tasks'
|
data/correios-cep.gemspec
CHANGED
@@ -1,32 +1,32 @@
|
|
1
|
-
lib = File.expand_path(
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require
|
3
|
+
require 'correios/cep/version'
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name =
|
6
|
+
spec.name = 'correios-cep'
|
7
7
|
spec.version = Correios::CEP::VERSION
|
8
|
-
spec.
|
9
|
-
spec.email =
|
10
|
-
spec.
|
11
|
-
spec.
|
12
|
-
spec.homepage =
|
13
|
-
spec.license =
|
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 = [
|
18
|
+
spec.require_paths = ['lib']
|
19
19
|
|
20
|
-
spec.platform
|
21
|
-
spec.required_ruby_version = Gem::Requirement.new(
|
20
|
+
spec.platform = Gem::Platform::RUBY
|
21
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 1.9.2')
|
22
22
|
|
23
|
-
spec.add_dependency
|
24
|
-
spec.add_dependency
|
23
|
+
spec.add_dependency 'log-me', '= 0.0.8'
|
24
|
+
spec.add_dependency 'ox', '~> 2.2.2'
|
25
25
|
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.add_development_dependency
|
30
|
-
spec.add_development_dependency
|
31
|
-
spec.add_development_dependency
|
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
|
-
|
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.
|
28
|
-
|
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
|
data/lib/correios/cep/version.rb
CHANGED
@@ -52,15 +52,15 @@ module Correios
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def request_body(zipcode)
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
62
|
-
|
63
|
-
|
61
|
+
'</cli:consultaCEP>' +
|
62
|
+
'</soapenv:Body>' +
|
63
|
+
'</soapenv:Envelope>'
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
@@ -1,35 +1,51 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Correios::CEP::AddressFinder do
|
4
|
-
context
|
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) {
|
17
|
-
let(:address) { { address:
|
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
|
-
|
21
|
-
|
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
|
25
|
-
it
|
26
|
-
expect(subject.get(cep)).to
|
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
|
31
|
-
|
32
|
-
|
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
|
5
|
+
describe '#address' do
|
6
6
|
let(:expected_address) do
|
7
7
|
{
|
8
|
-
address:
|
9
|
-
neighborhood:
|
10
|
-
city:
|
11
|
-
state:
|
12
|
-
zipcode:
|
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
|
18
|
-
context
|
17
|
+
context 'when address is found' do
|
18
|
+
context 'and does not have complement' do
|
19
19
|
let(:xml) do
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
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
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
|
66
|
-
expected_address[:complement] =
|
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
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
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
|
94
|
-
expected_address[:complement] =
|
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
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
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
|
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
|
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
|
-
-
|
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:
|
48
|
-
recorded_with: VCR
|
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.
|
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-
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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: []
|