cep-aberto 0.1.2 → 0.1.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f9d4140860329970af79ea89a40fe79302440aeb
4
- data.tar.gz: 8e33fbe4e0815c4968027870f1ab3743e988ff38
3
+ metadata.gz: 881699ff45db088d1ca531edc631fa44c2b27cf1
4
+ data.tar.gz: 53aad4d89d5b119cec1c06fe9d61364e261f82cb
5
5
  SHA512:
6
- metadata.gz: 806f68fb463b30f3ff3dfae8a10cbc02e2a9b82ec0d5d48b7e6531994fbf782e63f91347b06f1c56071cbd4e24892c6b34b729d6c64870e343b0e2af1da6da49
7
- data.tar.gz: 4b0243428f6aa846dedd999c328d18a9338b7fd09ee81c61fc1a60f526ccbce09369ce0eb6f826a733d37f23e99740149edcaa4540efa5c0af492b7b2617d194
6
+ metadata.gz: bbd4aed738ffc448585f67739fae79f32ef8e14340f717dd6ab1eca2faf976d7b46fdf227364944e3b00e1ff0c0408f5b02e4a5b7c1096ba47d7451fa5b07d0d
7
+ data.tar.gz: 7d808af07845d13c62f1f2c6ad9f2759c72180b3ca6afe347114267bfd75636b12deec3afd1e4274a849934acaaad0f67332c336d968ee98c79d4b24e06827d4
data/README.md CHANGED
@@ -8,7 +8,7 @@ gem 'cep-aberto'
8
8
  ```
9
9
  And bundle with:
10
10
  ```bash
11
- bundle
11
+ bundle
12
12
  ```
13
13
  Or execute manually:
14
14
  ```bash
@@ -16,7 +16,8 @@ gem install cep-aberto
16
16
  ```
17
17
 
18
18
  ## Usage
19
- First, you need a Token Authorization to use this gem. Go to [CEP Aberto site](http://www.cepaberto.com/) and sign up for free.
19
+ First, you need an authorization token to use this gem. Go to [CEP Aberto](http://www.cepaberto.com/)
20
+ and sign up for free.
20
21
 
21
22
  ### Find address
22
23
  Run:
@@ -39,7 +40,7 @@ This method return a hash with the full address for the zipcode:
39
40
  "estado"=>"SP"}
40
41
  ```
41
42
 
42
- ### List cities
43
+ ### List cities
43
44
  To list cities from a given state, do this:
44
45
  ```ruby
45
46
  require "cep-aberto"
@@ -49,15 +50,32 @@ And the result is:
49
50
  ```ruby
50
51
  => ["Adamantina",
51
52
  "Adolfo",
52
- "Agisse (Rancharia)",
53
53
  "Aguaí",
54
54
  "Águas da Prata",
55
55
  "Águas de Lindóia",
56
56
  "Águas de Santa Bárbara",
57
57
  "Águas de São Pedro",
58
- "Água Vermelha (São Carlos)",
59
58
  ...
60
59
  ```
60
+ ### List cities (including districts)
61
+ To list cities and districts from a state, do this:
62
+ ```ruby
63
+ require "cep-aberto"
64
+ CepAberto::Cep::cities_with_districts("SP", "1234567890abcdef01234567890abcde")
65
+ ```
66
+ And the result is:
67
+ ```ruby
68
+ => ["Adamantina",
69
+ "Adolfo",
70
+ "Agisse (Rancharia)",
71
+ "Aguaí",
72
+ "Águas da Prata",
73
+ "Águas de Lindóia",
74
+ "Águas de Santa Bárbara",
75
+ ...
76
+ ```
77
+
78
+
61
79
 
62
80
  ## Thanks
63
81
 
data/cep-aberto.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'cep-aberto'
3
- s.version = '0.1.2'
4
- s.date = '2017-08-08'
3
+ s.version = '0.1.4'
4
+ s.date = '2017-08-11'
5
5
  s.summary = "Ruby Connector for the CEP ABERTO API (www.cepaberto.com). A token is required to use this gem."
6
6
  s.description = s.summary
7
7
  s.authors = ["Jefferson Felix"]
@@ -10,4 +10,4 @@ Gem::Specification.new do |s|
10
10
  s.homepage =
11
11
  'https://github.com/jsfelix/cep-aberto'
12
12
  s.license = 'MIT'
13
- end
13
+ end
@@ -1,18 +1,18 @@
1
1
  # Main module CepAberto.
2
2
  # Author:: Jefferson Felix
3
3
  module CepAberto
4
- # This class holds the methods to find zipcodes and address using the CEP
4
+ # This class holds the methods to find zipcodes and addresses using the CEP
5
5
  # Aberto API.
6
6
  class Cep
7
-
7
+
8
8
  require "net/http"
9
9
  require "uri"
10
10
  require "json"
11
-
11
+
12
12
  # CEP Aberto API (v2)
13
13
  @domain = "http://www.cepaberto.com/api/v2/"
14
14
 
15
- # Find an address from a zipcode using the CEP Aberto API.
15
+ # Find an address from a zipcode using the CEP Aberto API. <br />
16
16
  # Params:
17
17
  # +zipcode+:: the zipcode to be searched by CEP Aberto API
18
18
  # +token+:: the user authorization token
@@ -28,12 +28,12 @@ module CepAberto
28
28
  return address
29
29
  end
30
30
 
31
- # Returns a list of cities from a given state.
31
+ # Returns a list of cities from a given state, including their districts. <br />
32
32
  # Params:
33
33
  # +state+:: State acronym (e.g. SP)
34
34
  # +token+:: the user authorization token
35
35
  # Returns an array with all cities from the state
36
- def Cep::cities(state, token)
36
+ def Cep::cities_with_districts(state, token)
37
37
  uri = URI("#{@domain}cities.json")
38
38
  params = {'estado' => state}
39
39
  all_cities = request_cep(uri, params, token)
@@ -43,16 +43,30 @@ module CepAberto
43
43
  end
44
44
  return cities_arr
45
45
  end
46
-
46
+
47
+ # Returns a list of cities from a given state. This method excludes districts. <br />
48
+ # Params:
49
+ # +state+:: State acronym (e.g. SP)
50
+ # +token+:: the user authorization token
51
+ # Returns an array with all cities from the state
52
+ def Cep::cities(state, token)
53
+ all_cities = cities_with_districts(state, token)
54
+ cities_arr = Array.new
55
+ all_cities.each do |c|
56
+ cities_arr.push(c) unless c.end_with?(')')
57
+ end
58
+ return cities_arr
59
+ end
60
+
47
61
  private
48
-
62
+
49
63
  # Validate cep entry
50
64
  # * Must be a string
51
65
  # * Must be 8 characters
52
66
  def Cep::validate_cep(str)
53
67
  raise ArgumentError, 'Argument is not string with 8 characters' unless str.is_a? String and str.length == 8
54
68
  end
55
-
69
+
56
70
  # Request API
57
71
  def Cep::request_cep(uri, params, token)
58
72
  headers = { "Authorization" => "Token token=#{token}" }
@@ -63,6 +77,6 @@ module CepAberto
63
77
  response = http.request(request).body
64
78
  JSON.parse(response)
65
79
  end
66
-
80
+
67
81
  end
68
82
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cep-aberto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jefferson Felix
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-08 00:00:00.000000000 Z
11
+ date: 2017-08-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby Connector for the CEP ABERTO API (www.cepaberto.com). A token is
14
14
  required to use this gem.