correios-cep 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/correios-cep.gemspec +7 -7
- data/lib/correios/cep/parser.rb +19 -7
- data/lib/correios/cep/version.rb +1 -1
- data/spec/correios/cep/parser_spec.rb +88 -29
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4205b263bcf608493677f1f0f6ce7a9cbf4fea6
|
4
|
+
data.tar.gz: b39d686fef4ff806416993478d88885a05fe694a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 102b1121be45c66e6963b59ab0490cefd5a7431c8509f98f9285cfc34cee7db68b49dee7efa15c97dfa4a855dc5919da27c9b4be21f00bc6dccc59f382f18f46
|
7
|
+
data.tar.gz: c9ea444975185a81518c5a71b5fcfd787d6c6c53d69c13645482e45c34aa2c4eb036d490d9ae940fef9996ff960b26af4276b5439ff34e6024c98de0cbe65812
|
data/CHANGELOG.md
CHANGED
data/correios-cep.gemspec
CHANGED
@@ -21,12 +21,12 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.required_ruby_version = Gem::Requirement.new('>= 1.9.2')
|
22
22
|
|
23
23
|
spec.add_dependency 'log-me', '= 0.0.8'
|
24
|
-
spec.add_dependency
|
24
|
+
spec.add_dependency "ox", "~> 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"
|
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.15"
|
32
32
|
end
|
data/lib/correios/cep/parser.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'ox'
|
2
2
|
|
3
3
|
module Correios
|
4
4
|
module CEP
|
@@ -14,21 +14,33 @@ module Correios
|
|
14
14
|
}.freeze
|
15
15
|
|
16
16
|
def address(xml)
|
17
|
-
|
18
|
-
|
17
|
+
doc = Ox.parse(xml)
|
18
|
+
return_node = find_node(doc.nodes, 'return')
|
19
|
+
return if return_node.nil?
|
19
20
|
|
20
21
|
address = {}
|
21
|
-
|
22
|
-
address[ADDRESS_MAP[element.name]] = element
|
22
|
+
return_node.nodes.each do |element|
|
23
|
+
address[ADDRESS_MAP[element.name]] = text_for(element) if ADDRESS_MAP[element.name]
|
23
24
|
end
|
24
25
|
|
25
|
-
join_complements
|
26
|
+
join_complements(address)
|
26
27
|
address
|
27
28
|
end
|
28
29
|
|
29
30
|
private
|
30
31
|
|
31
|
-
def
|
32
|
+
def find_node(nodes, name)
|
33
|
+
node = nodes.first
|
34
|
+
return node if node.nil? || node.name == name
|
35
|
+
|
36
|
+
find_node(node.nodes, name)
|
37
|
+
end
|
38
|
+
|
39
|
+
def text_for(element)
|
40
|
+
element.text.to_s.force_encoding(Encoding::UTF_8)
|
41
|
+
end
|
42
|
+
|
43
|
+
def join_complements(address)
|
32
44
|
address[:complement] += " #{address.delete(:complement2)}"
|
33
45
|
address[:complement].strip!
|
34
46
|
end
|
data/lib/correios/cep/version.rb
CHANGED
@@ -3,39 +3,98 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe Correios::CEP::Parser do
|
5
5
|
describe '#address' do
|
6
|
+
let(:expected_address) do
|
7
|
+
{
|
8
|
+
address: 'Rua Fernando Amorim',
|
9
|
+
neighborhood: 'Cavaleiro',
|
10
|
+
city: 'Jaboatão dos Guararapes',
|
11
|
+
state: 'PE',
|
12
|
+
zipcode: '54250610',
|
13
|
+
complement: ''
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
6
17
|
context 'when address is found' do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
"<S:
|
11
|
-
"<
|
12
|
-
"<
|
13
|
-
"<
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
context 'and does not have complement' do
|
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>"
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'returns address' do
|
40
|
+
expect(subject.address(xml)).to eq expected_address
|
41
|
+
end
|
25
42
|
end
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
43
|
+
|
44
|
+
context 'and has one complement' do
|
45
|
+
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>"
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'returns address' do
|
66
|
+
expected_address[:complement] = 'de 1500 até o fim'
|
67
|
+
|
68
|
+
expect(subject.address(xml)).to eq expected_address
|
69
|
+
end
|
35
70
|
end
|
36
71
|
|
37
|
-
|
38
|
-
|
72
|
+
context 'and has two complements' do
|
73
|
+
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>"
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'returns address' do
|
94
|
+
expected_address[:complement] = 'de 1500 até o fim (zona mista)'
|
95
|
+
|
96
|
+
expect(subject.address(xml)).to eq expected_address
|
97
|
+
end
|
39
98
|
end
|
40
99
|
end
|
41
100
|
|
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.
|
4
|
+
version: 0.4.0
|
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-04-
|
11
|
+
date: 2015-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: log-me
|
@@ -25,19 +25,19 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.0.8
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: ox
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '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'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: coveralls
|
43
43
|
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.15'
|
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.15'
|
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:
|