cep_facil 0.0.3 → 0.1.0

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.
data/README.md CHANGED
@@ -19,27 +19,56 @@ Or via RubyGems, directly:
19
19
 
20
20
  Usage
21
21
  -----
22
+
23
+ ### Fetching an address by zip code
22
24
 
23
25
  ```ruby
24
26
  require "cep_facil"
25
- cep = "5417-540"
27
+ cep = "53417-540"
26
28
  token = "1234567890" # get yours at cepfacil.com.br
27
- result = CepFacil.get_address(cep, token)
29
+ address = CepFacil.get_address(cep, token)
28
30
  # Returns the address referent to that zip code.
29
- result[:city]
31
+ address[:city]
30
32
  # Returns the city referent to that zip code.
31
33
  ```
32
34
 
35
+ Alternatively, you can do:
36
+
37
+ ```ruby
38
+ require "cep_facil"
39
+ include CepFacil
40
+ address = get_address cep, token
41
+ ```
42
+
33
43
  The response is a Hash object that contains 6 keys: cep, type, state, city, neighborhood, description.
34
44
 
35
- There are three formats for one to store Brazilian zip codes (CEPS):
45
+ There are three formats for one to store Brazilian zip codes (CEPs):
36
46
 
37
- * "12345-678"
38
- * "12345678"
39
- * 12345678 # I wouldn't use this one, really.
47
+ ```ruby
48
+ "12345-678"
49
+ "12345678"
50
+ 12345678 # I wouldn't use this one, really.
51
+ ```
40
52
 
41
53
  CepFácil works with the three of them.
42
54
 
55
+ ### Displaying an address in full mode
56
+
57
+ ```ruby
58
+ address = CepFacil.get_address(cep, token)
59
+ CepFacil.full address
60
+ ```
61
+
62
+ Or:
63
+
64
+ ````ruby
65
+ require "cep_facil"
66
+ include CepFacil
67
+
68
+ address = get_address("50050-000", token)
69
+ full(address) # => Rua da Aurora, Boa Vista, Recife-PE, Brasil.
70
+ ```
71
+
43
72
  Author
44
73
  ------
45
74
 
@@ -1,3 +1,3 @@
1
1
  module CepFacil
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/cep_facil.rb CHANGED
@@ -3,23 +3,33 @@ require "cep_facil/version"
3
3
  require "net/http"
4
4
 
5
5
  module CepFacil
6
+
7
+ module_function
6
8
 
7
9
  # Receives the zip code (CEP) and the Token (get yours at http://cepfacil.com.br) and
8
10
  # returns the address referent to that zip code as a hash object.
9
11
  #
10
- # == Exemplo
11
- # require "cep_facil"
12
- # cep = "5417-540"
13
- # token = "1234567890"
14
- # address = CepFacil.get_address(cep, token)
15
- # address is a hash with 6 keys: cep, type, state, city, neighborhood, description
12
+ # == Example
13
+ # require "cep_facil"
14
+ # cep = "5417-540"
15
+ # token = "1234567890"
16
+ # address = CepFacil.get_address(cep, token)
17
+ #
18
+ # == You can also do:
19
+ # require "cep_facil"
20
+ # include CepFacil
21
+ # get_address cep, token
22
+ #
23
+ # # address is a hash with 6 keys: cep, type, state, city, neighborhood, description
24
+ #
16
25
  # Reading them:
17
- # address[:city]
18
- # address[:state]
26
+ # address[:city]
27
+ # address[:state]
28
+ #
19
29
  # Some applications store Brazilian zip codes (CEPs) in formats like "22222222", or "22222-222"
20
30
  # or even as an integer. This method accept these three possible formats so you don´t need to format it yourself.
21
31
 
22
- def self.get_address(zip_code, token)
32
+ def get_address(zip_code, token)
23
33
  zip_code = zip_code.to_s
24
34
 
25
35
  if zip_code.match(/^[0-9]{5}[-]?[0-9]{3}/)
@@ -56,12 +66,19 @@ module CepFacil
56
66
  end
57
67
 
58
68
  # 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)
69
+ # == Example
70
+ # address = CepFacil.get_address "53417-540", "1234456677886545"
71
+ # CepFacil.full address
72
+ # # => Rua Panelas, Artur Lundgren II, Paulista-PE, Brasil.
73
+ #
74
+ # == You can also do:
75
+ # require "cep_facil"
76
+ # include CepFacil
77
+ # address = CepFacil.get_address "53417-540", "1234456677886545"
78
+ # full address
79
+
80
+ def full(address)
65
81
  "#{address[:type]} #{address[:description]}, #{address[:neighborhood]}, #{address[:city]}-#{address[:state]}, Brasil."
66
82
  end
83
+
67
84
  end
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.3
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-03 00:00:00.000000000 Z
12
+ date: 2012-01-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70346151186340 !ruby/object:Gem::Requirement
16
+ requirement: &70307525443140 !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: *70346151186340
24
+ version_requirements: *70307525443140
25
25
  description: Wrapper Ruby para o serviço cepfacil.com.br
26
26
  email:
27
27
  - rodrigo@atela.com.br