correios-cep 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/{CHANGELOG.rdoc → CHANGELOG.md} +13 -9
- data/{README.rdoc → README.md} +62 -39
- data/correios-cep.gemspec +15 -15
- data/lib/correios-cep.rb +2 -1
- data/lib/correios/cep.rb +1 -11
- data/lib/correios/cep/address_finder.rb +3 -3
- data/lib/correios/cep/config.rb +16 -0
- data/lib/correios/cep/parser.rb +8 -8
- data/lib/correios/cep/version.rb +1 -1
- data/lib/correios/cep/web_service.rb +26 -14
- data/spec/correios/cep/address_finder_spec.rb +10 -10
- data/spec/correios/cep/parser_spec.rb +11 -11
- data/spec/correios/cep/web_service_spec.rb +5 -5
- data/spec/correios/cep_spec.rb +13 -0
- data/spec/spec_helper.rb +1 -1
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 693cb4991b7c16062b0a108dcd8b66442c1502cd
|
4
|
+
data.tar.gz: c70e4e05a67fcce3be1974b0883dcb41667ffce9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adf5ec16cfa8b4d4db9167f8ea666478aba3d8794b385720c10662523a977d369067d9e82365d9b0545e216f48f3f03df816428712d3314796b9b9db5e020ff9
|
7
|
+
data.tar.gz: cd5755c58ce306f64cd5204784ef8de4a6a3faa906e8d26e54a482096bfa5a8eeb6d1c6490ea52e97d5ff4167ac8c75f41ea7d801191f184595e013f8af595d7
|
data/.travis.yml
CHANGED
@@ -1,26 +1,30 @@
|
|
1
|
-
|
1
|
+
## Version 0.3.2
|
2
|
+
- Update: Optional HTTP requests using HTTP proxy.
|
3
|
+
- Improvement: Update LogMe gem version to 0.0.9.
|
4
|
+
|
5
|
+
## Version 0.3.1
|
2
6
|
- Warning: Minimal required Ruby version is 1.9.2 again.
|
3
7
|
|
4
|
-
|
8
|
+
## Version 0.3.0
|
5
9
|
- Update: Update Correios Web Service URL.
|
6
10
|
|
7
|
-
|
11
|
+
## Version 0.2.0
|
8
12
|
- Warning: Minimal required Ruby version from now is 1.9.3.
|
9
13
|
|
10
|
-
|
14
|
+
## Version 0.1.4
|
11
15
|
- Improvement: Minimal required Ruby version now is 1.9.2.
|
12
16
|
|
13
|
-
|
17
|
+
## Version 0.1.3
|
14
18
|
- Improvement: Update LogMe gem to version 0.0.6 with support to log request and response messages.
|
15
19
|
|
16
|
-
|
20
|
+
## Version 0.1.2
|
17
21
|
- Improvement: Update LogMe gem to version 0.0.5 with support to log messages label.
|
18
22
|
|
19
|
-
|
23
|
+
## Version 0.1.1
|
20
24
|
- New: A "get" class method in AddressFinder class.
|
21
25
|
|
22
|
-
|
26
|
+
## Version 0.1.0
|
23
27
|
- First working version.
|
24
28
|
|
25
|
-
|
29
|
+
## Version 0.0.1
|
26
30
|
- First version, not working yet.
|
data/{README.rdoc → README.md}
RENAMED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# Correios CEP
|
2
2
|
|
3
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.
|
4
4
|
|
@@ -6,34 +6,40 @@ This works with an HTTP request to the form, followed by parsing the HTML result
|
|
6
6
|
|
7
7
|
Correios CEP gem solves this problem, getting data directly from Correios database.
|
8
8
|
|
9
|
-
http://prodis.net.br/images/ruby/2011/correios_logo.png
|
9
|
+
![Correios Logo](http://prodis.net.br/images/ruby/2011/correios_logo.png)
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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)
|
16
16
|
|
17
|
+
## Installing
|
17
18
|
|
18
|
-
|
19
|
+
### Gemfile
|
19
20
|
|
20
|
-
|
21
|
+
```ruby
|
21
22
|
gem 'correios-cep'
|
23
|
+
```
|
22
24
|
|
23
|
-
|
25
|
+
### Direct installation
|
26
|
+
|
27
|
+
```console
|
24
28
|
$ gem install correios-cep
|
29
|
+
```
|
25
30
|
|
26
31
|
|
27
|
-
|
32
|
+
## Using
|
28
33
|
|
34
|
+
```ruby
|
29
35
|
require 'correios-cep'
|
30
36
|
|
31
37
|
# With "get" instance method
|
32
38
|
finder = Correios::CEP::AddressFinder.new
|
33
|
-
address = finder.get
|
39
|
+
address = finder.get("54250610")
|
34
40
|
|
35
41
|
# With "get" class method
|
36
|
-
address = Correios::CEP::AddressFinder.get
|
42
|
+
address = Correios::CEP::AddressFinder.get("54250610")
|
37
43
|
|
38
44
|
address # =>
|
39
45
|
{
|
@@ -44,24 +50,37 @@ http://prodis.net.br/images/ruby/2011/correios_logo.png
|
|
44
50
|
:zipcode => "54250610",
|
45
51
|
:complement => ""
|
46
52
|
}
|
53
|
+
```
|
47
54
|
|
55
|
+
## Configurations
|
48
56
|
|
49
|
-
|
50
|
-
|
51
|
-
=== Timeout
|
57
|
+
### Timeout
|
52
58
|
|
53
|
-
For default, the timeout for a request to Correios Web Service is
|
54
|
-
You can configure this timeout using
|
59
|
+
For default, the timeout for a request to Correios Web Service is **5 seconds**. If Correios Web Service does not respond, a `Timeout::Error` exception will be raised.
|
60
|
+
You can configure this timeout using `Correios::CEP` module.
|
55
61
|
|
62
|
+
```ruby
|
56
63
|
Correios::CEP.configure do |config|
|
57
64
|
config.request_timeout = 3 # It configures timeout to 3 seconds
|
58
65
|
end
|
66
|
+
```
|
67
|
+
|
68
|
+
### HTTP Proxy
|
69
|
+
If you need to use an HTTP proxy to HTTP requests, configure the HTTP proxy URL on `Correios::CEP` module.
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
Correios::CEP.configure do |config|
|
73
|
+
config.proxy_url = "http://10.20.30.40:8888"
|
74
|
+
end
|
75
|
+
```
|
59
76
|
|
60
|
-
|
77
|
+
### Log
|
61
78
|
|
62
|
-
For default, each request to Correios Web service is logged to STDOUT, with
|
79
|
+
For default, each request to Correios Web service is logged to STDOUT, with **:info** log level, using the gem [LogMe](http://github.com/prodis/log-me).
|
63
80
|
|
64
81
|
Log example:
|
82
|
+
|
83
|
+
```xml
|
65
84
|
I, [2014-02-14T00:10:12.718413 #76361] INFO -- : [Correios::CEP] Request:
|
66
85
|
POST http://200.252.60.209/SigepCliente/AtendeClienteService
|
67
86
|
<?xml version="1.0" encoding="UTF-8"?>
|
@@ -93,50 +112,54 @@ Log example:
|
|
93
112
|
</ns2:consultaCEPResponse>
|
94
113
|
</S:Body>
|
95
114
|
</S:Envelope>
|
115
|
+
```
|
96
116
|
|
97
|
-
To disable the log and configure other log output, use
|
117
|
+
To disable the log and configure other log output, use **Correios::CEP** module:
|
98
118
|
|
119
|
+
```ruby
|
99
120
|
Correios::CEP.configure do |config|
|
100
121
|
config.log_enabled = false # It disables the log
|
101
122
|
config.logger = Rails.logger # It uses Rails logger
|
102
123
|
end
|
124
|
+
```
|
103
125
|
|
104
|
-
|
126
|
+
### Configuration example
|
105
127
|
|
128
|
+
```ruby
|
106
129
|
Correios::CEP.configure do |config|
|
107
130
|
config.logger = Rails.logger
|
108
131
|
config.request_timeout = 3
|
109
132
|
end
|
133
|
+
```
|
110
134
|
|
111
|
-
|
112
|
-
|
113
|
-
- {Fernando Hamasaki de Amorim (prodis)}[http://prodis.blog.br]
|
135
|
+
## Author
|
136
|
+
- [Fernando Hamasaki de Amorim (prodis)](http://prodis.blog.br)
|
114
137
|
|
115
138
|
|
116
|
-
|
139
|
+
## Contributing to correios-cep
|
117
140
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
141
|
+
- Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
142
|
+
- Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
143
|
+
- Fork the project.
|
144
|
+
- Start a feature/bugfix branch.
|
145
|
+
- Commit and push until you are happy with your contribution.
|
146
|
+
- Don't forget to rebase with branch master in main project before submit the pull request.
|
147
|
+
- Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
148
|
+
- Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
126
149
|
|
127
150
|
|
128
|
-
|
151
|
+
## Copyright
|
129
152
|
|
130
153
|
(The MIT License)
|
131
154
|
|
132
|
-
|
155
|
+
[Prodis a.k.a. Fernando Hamasaki de Amorim](http://prodis.blog.br)
|
133
156
|
|
134
|
-
http://prodis.net.br/images/prodis_150.gif
|
157
|
+
![Prodis Logo](http://prodis.net.br/images/prodis_150.gif)
|
135
158
|
|
136
|
-
Copyright
|
159
|
+
Copyright © 2014-2015 Prodis
|
137
160
|
|
138
161
|
Permission is hereby granted, free of charge, to any person obtaining
|
139
|
-
a copy of this software and associated documentation files (the
|
162
|
+
a copy of this software and associated documentation files (the
|
140
163
|
"Software"), to deal in the Software without restriction, including
|
141
164
|
without limitation the rights to use, copy, modify, merge, publish,
|
142
165
|
distribute, sublicense, and/or sell copies of the Software, and to
|
data/correios-cep.gemspec
CHANGED
@@ -3,30 +3,30 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
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.authors = [
|
9
|
-
spec.email = [
|
8
|
+
spec.authors = ['Prodis a.k.a. Fernando Hamasaki de Amorim']
|
9
|
+
spec.email = ['prodis@gmail.com']
|
10
10
|
spec.description = %q{Correios CEP gem gets updated Brazilian address from a zipcode, directly from Correios database. No HTML parsers.}
|
11
11
|
spec.summary = spec.description
|
12
|
-
spec.homepage =
|
13
|
-
spec.license =
|
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
20
|
spec.platform = Gem::Platform::RUBY
|
21
|
-
spec.required_ruby_version = Gem::Requirement.new(
|
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.9'
|
24
|
+
spec.add_dependency 'nokogiri', '~> 1.6'
|
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'
|
27
|
+
spec.add_development_dependency 'pry'
|
28
|
+
spec.add_development_dependency 'rake'
|
29
|
+
spec.add_development_dependency 'rspec', '~> 3.2'
|
30
|
+
spec.add_development_dependency 'vcr', '~> 2.9'
|
31
|
+
spec.add_development_dependency 'webmock', '~> 1.21'
|
32
32
|
end
|
data/lib/correios-cep.rb
CHANGED
data/lib/correios/cep.rb
CHANGED
@@ -3,16 +3,6 @@ require 'log-me'
|
|
3
3
|
module Correios
|
4
4
|
module CEP
|
5
5
|
extend LogMe
|
6
|
-
|
7
|
-
module Timeout
|
8
|
-
DEFAULT_REQUEST_TIMEOUT = 5 #seconds
|
9
|
-
attr_writer :request_timeout
|
10
|
-
|
11
|
-
def request_timeout
|
12
|
-
(@request_timeout ||= DEFAULT_REQUEST_TIMEOUT).to_i
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
extend Timeout
|
6
|
+
extend Correios::CEP::Config
|
17
7
|
end
|
18
8
|
end
|
@@ -2,12 +2,12 @@ module Correios
|
|
2
2
|
module CEP
|
3
3
|
class AddressFinder
|
4
4
|
def get(zipcode)
|
5
|
-
response = web_service.request
|
6
|
-
parser.address
|
5
|
+
response = web_service.request(zipcode)
|
6
|
+
parser.address(response)
|
7
7
|
end
|
8
8
|
|
9
9
|
def self.get(zipcode)
|
10
|
-
self.new.get
|
10
|
+
self.new.get(zipcode)
|
11
11
|
end
|
12
12
|
|
13
13
|
private
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Correios
|
2
|
+
module CEP
|
3
|
+
module Config
|
4
|
+
DEFAULT_REQUEST_TIMEOUT = 5 #seconds
|
5
|
+
attr_writer :proxy_url, :request_timeout
|
6
|
+
|
7
|
+
def proxy_url
|
8
|
+
@proxy_url ||= ''
|
9
|
+
end
|
10
|
+
|
11
|
+
def request_timeout
|
12
|
+
(@request_timeout ||= DEFAULT_REQUEST_TIMEOUT).to_i
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/correios/cep/parser.rb
CHANGED
@@ -4,17 +4,17 @@ module Correios
|
|
4
4
|
module CEP
|
5
5
|
class Parser
|
6
6
|
ADDRESS_MAP = {
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
'end' => :address,
|
8
|
+
'bairro' => :neighborhood,
|
9
|
+
'cidade' => :city,
|
10
|
+
'uf' => :state,
|
11
|
+
'cep' => :zipcode,
|
12
|
+
'complemento' => :complement,
|
13
|
+
'complemento2' => :complement2,
|
14
14
|
}.freeze
|
15
15
|
|
16
16
|
def address(xml)
|
17
|
-
result = Nokogiri::XML(xml).xpath(
|
17
|
+
result = Nokogiri::XML(xml).xpath('//return')
|
18
18
|
return if result.nil? || result.empty?
|
19
19
|
|
20
20
|
address = {}
|
data/lib/correios/cep/version.rb
CHANGED
@@ -4,38 +4,50 @@ require 'uri'
|
|
4
4
|
module Correios
|
5
5
|
module CEP
|
6
6
|
class WebService
|
7
|
-
URL =
|
7
|
+
URL = 'https://apps.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente'
|
8
8
|
|
9
9
|
def initialize
|
10
10
|
@uri = URI.parse(URL)
|
11
|
+
@proxy_uri = URI.parse(Correios::CEP.proxy_url)
|
11
12
|
end
|
12
13
|
|
13
|
-
def request
|
14
|
+
def request(zipcode)
|
14
15
|
http = build_http
|
15
16
|
|
16
|
-
request = build_request
|
17
|
-
Correios::CEP.log_request
|
17
|
+
request = build_request(zipcode)
|
18
|
+
Correios::CEP.log_request(request, uri.to_s)
|
18
19
|
|
19
|
-
response = http.request
|
20
|
-
Correios::CEP.log_response
|
20
|
+
response = http.request(request)
|
21
|
+
Correios::CEP.log_response(response)
|
22
|
+
|
23
|
+
http.finish if http.started?
|
21
24
|
|
22
25
|
response.body
|
23
26
|
end
|
24
27
|
|
25
28
|
private
|
26
29
|
|
30
|
+
attr_reader :uri, :proxy_uri
|
31
|
+
|
27
32
|
def build_http
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
+
Net::HTTP.start(
|
34
|
+
uri.host,
|
35
|
+
uri.port,
|
36
|
+
proxy_uri.host,
|
37
|
+
proxy_uri.port,
|
38
|
+
nil,
|
39
|
+
nil,
|
40
|
+
use_ssl: true,
|
41
|
+
verify_mode: OpenSSL::SSL::VERIFY_NONE,
|
42
|
+
open_timeout: Correios::CEP.request_timeout,
|
43
|
+
read_timeout: Correios::CEP.request_timeout
|
44
|
+
)
|
33
45
|
end
|
34
46
|
|
35
47
|
def build_request(zipcode)
|
36
|
-
request = Net::HTTP::Post.new(
|
37
|
-
request[
|
38
|
-
request.body = request_body
|
48
|
+
request = Net::HTTP::Post.new(uri.path)
|
49
|
+
request['Content-Type'] = 'text/xml; charset=utf-8'
|
50
|
+
request.body = request_body(zipcode)
|
39
51
|
request
|
40
52
|
end
|
41
53
|
|
@@ -1,24 +1,24 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Correios::CEP::AddressFinder do
|
4
|
-
let(:cep) {
|
5
|
-
let(:web_service_response) {
|
6
|
-
let(:address) { { address:
|
4
|
+
let(:cep) { '54250610' }
|
5
|
+
let(:web_service_response) { '<end>Rua Fernando Amorim</end>' }
|
6
|
+
let(:address) { { address: 'Rua Fernando Amorim' } }
|
7
7
|
|
8
8
|
before do
|
9
|
-
allow_any_instance_of(Correios::CEP::WebService).to receive(:request
|
9
|
+
allow_any_instance_of(Correios::CEP::WebService).to receive(:request).with(cep).and_return(web_service_response)
|
10
10
|
allow_any_instance_of(Correios::CEP::Parser).to receive(:address).with(web_service_response).and_return(address)
|
11
11
|
end
|
12
12
|
|
13
|
-
describe
|
14
|
-
it
|
15
|
-
expect(subject.get(cep)).to
|
13
|
+
describe '#get' do
|
14
|
+
it 'returns address' do
|
15
|
+
expect(subject.get(cep)).to eql address
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
describe
|
20
|
-
it
|
21
|
-
expect(Correios::CEP::AddressFinder.get(cep)).to
|
19
|
+
describe '.get' do
|
20
|
+
it 'returns address' do
|
21
|
+
expect(Correios::CEP::AddressFinder.get(cep)).to eql address
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -2,8 +2,8 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe Correios::CEP::Parser do
|
5
|
-
describe
|
6
|
-
context
|
5
|
+
describe '#address' do
|
6
|
+
context 'when address is found' do
|
7
7
|
let(:xml) do
|
8
8
|
"<?xml version='1.0' encoding='UTF-8'?>" +
|
9
9
|
"<S:Envelope>" +
|
@@ -25,21 +25,21 @@ describe Correios::CEP::Parser do
|
|
25
25
|
end
|
26
26
|
let(:expected_address) do
|
27
27
|
{
|
28
|
-
address:
|
29
|
-
neighborhood:
|
30
|
-
city:
|
31
|
-
state:
|
32
|
-
zipcode:
|
33
|
-
complement:
|
28
|
+
address: 'Rua Fernando Amorim',
|
29
|
+
neighborhood: 'Cavaleiro',
|
30
|
+
city: 'Jaboatão dos Guararapes',
|
31
|
+
state: 'PE',
|
32
|
+
zipcode: '54250610',
|
33
|
+
complement: 'de 1500 até o fim (zona mista)'
|
34
34
|
}
|
35
35
|
end
|
36
36
|
|
37
|
-
it
|
37
|
+
it 'returns address' do
|
38
38
|
expect(subject.address(xml)).to eq expected_address
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
context
|
42
|
+
context 'when address is not found' do
|
43
43
|
let(:xml) do
|
44
44
|
"<?xml version='1.0' encoding='UTF-8'?>" +
|
45
45
|
"<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
|
@@ -49,7 +49,7 @@ describe Correios::CEP::Parser do
|
|
49
49
|
"</S:Envelope>"
|
50
50
|
end
|
51
51
|
|
52
|
-
it
|
52
|
+
it 'returns nil' do
|
53
53
|
expect(subject.address(xml)).to be_nil
|
54
54
|
end
|
55
55
|
end
|
@@ -1,18 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Correios::CEP::WebService do
|
4
|
-
let(:cep) {
|
4
|
+
let(:cep) { '54250610' }
|
5
5
|
|
6
|
-
describe
|
6
|
+
describe '#request', vcr: { cassette_name: 'correios_consulta_cep_ok' } do
|
7
7
|
around do |example|
|
8
8
|
Correios::CEP.log_enabled = false
|
9
9
|
example.run
|
10
10
|
Correios::CEP.log_enabled = true
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
14
|
-
result = subject.request
|
15
|
-
expect(result).to include(
|
13
|
+
it 'returns HTTP response body from Correios Web Service' do
|
14
|
+
result = subject.request(cep)
|
15
|
+
expect(result).to include('Rua Fernando Amorim')
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
data/spec/correios/cep_spec.rb
CHANGED
@@ -1,6 +1,19 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Correios::CEP do
|
4
|
+
describe '#proxy_url' do
|
5
|
+
it 'default is empty' do
|
6
|
+
expect(Correios::CEP.proxy_url).to eql ''
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'when set proxy URL' do
|
10
|
+
it 'returns proxy URL' do
|
11
|
+
Correios::CEP.configure { |config| config.proxy_url = 'http://10.20.30.40:8888' }
|
12
|
+
expect(Correios::CEP.proxy_url).to eql 'http://10.20.30.40:8888'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
4
17
|
describe "#request_timeout" do
|
5
18
|
it "default is 5" do
|
6
19
|
expect(Correios::CEP.request_timeout).to eql 5
|
data/spec/spec_helper.rb
CHANGED
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.3.
|
4
|
+
version: 0.3.2
|
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-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: log-me
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.0.
|
19
|
+
version: 0.0.9
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.0.
|
26
|
+
version: 0.0.9
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: nokogiri
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '3.
|
89
|
+
version: '3.2'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '3.
|
96
|
+
version: '3.2'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: vcr
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,14 +114,14 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '1.
|
117
|
+
version: '1.21'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '1.
|
124
|
+
version: '1.21'
|
125
125
|
description: Correios CEP gem gets updated Brazilian address from a zipcode, directly
|
126
126
|
from Correios database. No HTML parsers.
|
127
127
|
email:
|
@@ -133,14 +133,15 @@ files:
|
|
133
133
|
- ".gitignore"
|
134
134
|
- ".rspec"
|
135
135
|
- ".travis.yml"
|
136
|
-
- CHANGELOG.
|
136
|
+
- CHANGELOG.md
|
137
137
|
- Gemfile
|
138
|
-
- README.
|
138
|
+
- README.md
|
139
139
|
- Rakefile
|
140
140
|
- correios-cep.gemspec
|
141
141
|
- lib/correios-cep.rb
|
142
142
|
- lib/correios/cep.rb
|
143
143
|
- lib/correios/cep/address_finder.rb
|
144
|
+
- lib/correios/cep/config.rb
|
144
145
|
- lib/correios/cep/parser.rb
|
145
146
|
- lib/correios/cep/version.rb
|
146
147
|
- lib/correios/cep/web_service.rb
|