cep_facil 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  module CepFacil
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/cep_facil.rb CHANGED
@@ -54,4 +54,14 @@ module CepFacil
54
54
  }
55
55
 
56
56
  end
57
+
58
+ # Receives and address hash and returns its extense version
59
+ # = Example
60
+ # address = CepFacil.get_address "53417-540", "1234456677886545"
61
+ # CepFacil.full address
62
+ # => Rua Panelas, Artur Lundgren II, Paulista-PE, Brasil.
63
+
64
+ def self.full(address)
65
+ "#{address[:type]} #{address[:description]}, #{address[:neighborhood]}, #{address[:city]}-#{address[:state]}, Brasil."
66
+ end
57
67
  end
@@ -1,9 +1,70 @@
1
+ # coding: utf-8
1
2
  require File.expand_path('spec/spec_helper')
2
3
 
3
4
  describe CepFacil do
5
+ before(:each) do
6
+ @token = "0E2ACA03-FC7F-4E87-9046-A8C46637BA9D"
7
+ end
4
8
 
5
9
  it "has a version" do
6
10
  CepFacil::VERSION.should =~ /^\d+\.\d+\.\d+$/
7
11
  end
8
12
 
9
- end
13
+ it "can fetch an address from a CEP" do
14
+ cep = "53417-540"
15
+
16
+ address = CepFacil.get_address cep, @token
17
+ address.should_not be_nil
18
+
19
+ address[:type].should eql("Rua")
20
+ address[:city].should eql("Paulista")
21
+ end
22
+
23
+ it "works with non formatted zip codes (CEPs)" do
24
+ cep = "53417540"
25
+ address = CepFacil.get_address cep, @token
26
+ address.should_not be_nil
27
+ end
28
+
29
+ it "works even with zip codes (CEPs) stored as integers" do
30
+ cep = 53417540
31
+ address = CepFacil.get_address cep, @token
32
+ address.should_not be_nil
33
+ end
34
+
35
+ it "can get all 6 attributes (cep, type, state, city, neighborhood, description) from a given CEP" do
36
+ cep = "52060-010"
37
+ address = CepFacil.get_address cep, @token
38
+
39
+ address[:cep].should eql("52060010")
40
+ address[:type].should eql("Rua")
41
+ address[:state].should eql("PE")
42
+ address[:city].should eql("Recife")
43
+ address[:neighborhood].should eql("Parnamirim")
44
+ address[:description].should include("Tude de Melo")
45
+
46
+ address[:cep].should_not be_nil
47
+ address[:type].should_not be_nil
48
+ address[:state].should_not be_nil
49
+ address[:city].should_not be_nil
50
+ address[:neighborhood].should_not be_nil
51
+ address[:description].should_not be_nil
52
+
53
+ address.should have_key(:cep)
54
+ address.should have_key(:type)
55
+ address.should have_key(:state)
56
+ address.should have_key(:city)
57
+ address.should have_key(:neighborhood)
58
+ address.should have_key(:description)
59
+ end
60
+
61
+ it "can return a string with the full address" do
62
+ cep = "53417-540"
63
+ address = CepFacil.get_address cep, @token
64
+ full_version = CepFacil.full address
65
+ full_version.should_not be_nil
66
+ full_version.should eql("Rua Panelas, Artur Lundgren II, Paulista-PE, Brasil.")
67
+ end
68
+
69
+ end
70
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cep_facil
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-01-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70231872781820 !ruby/object:Gem::Requirement
16
+ requirement: &70346151186340 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '2'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70231872781820
24
+ version_requirements: *70346151186340
25
25
  description: Wrapper Ruby para o serviço cepfacil.com.br
26
26
  email:
27
27
  - rodrigo@atela.com.br