via_cep 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f9fea70f5ce5d76c4cdcf6b2ad7c02946ea77c24
4
- data.tar.gz: 5991fcd4f164cccbf9fdb35b83a9948e2a8e426d
3
+ metadata.gz: c8d1daae20313725996e5fd0304ca40f27588cd0
4
+ data.tar.gz: 531434accc95eee1beec369b04b07f6ebd84fafe
5
5
  SHA512:
6
- metadata.gz: ca7584afa6251255a2214229f96b3f7e4fee10cb6e36b9cc66195121ac68b80dc9c5921e55fa141f24e771ae456e491c926e439543e39ddba2c447ec577ee371
7
- data.tar.gz: 8b1728062681d03e38da3048a398ae149fd343fa4866a10dde4a2f2f8a8f9c2e43afdc37636805b3168f202ed0749b2d3b9cdb65da11dd0a8a30a215460ecc30
6
+ metadata.gz: 1c9f9e2c3ca871ba2b37ed6734b11994a5f95574bd4d2b48b5bf0813daada4916a6bd4bc48ab0febd49958c1bb39de8427c3933050d8eda59a4f065ceef498c3
7
+ data.tar.gz: 22b0cb9e44a9ac8b368b7d672fac8ee4de83a4eca082805eb9d7a836420932404ea8b2030d0c4e00868571179c32ae6bf4e9e5f0c8a322a19957062d7b53d4cd
data/README.md CHANGED
@@ -33,6 +33,29 @@ On terminal you can use via_cep like this:
33
33
  address.street # Returns "Praça da Sé"
34
34
  ```
35
35
 
36
+ You can use from terminal either
37
+
38
+ ```bash
39
+ $ zipcode 01001-000 01406000
40
+ ```
41
+ It will return 2 address with its information
42
+
43
+ ```bash
44
+
45
+ 01001-000:
46
+ Praça da Sé
47
+
48
+ São Paulo
49
+ SP
50
+
51
+ 01406000:
52
+ Avenida Nove de Julho
53
+ Jardim Paulista
54
+ São Paulo
55
+ SP
56
+ ```
57
+
58
+
36
59
  ### Available methods
37
60
 
38
61
  zipcode, street, complement, neighborhood, city, state, ibge, gia.
@@ -4,6 +4,7 @@ require 'via_cep/version'
4
4
  # Core
5
5
  require 'via_cep/address'
6
6
  require 'via_cep/methods'
7
+ require 'via_cep/search_by_zipcode'
7
8
 
8
9
  # Validators
9
10
  require 'via_cep/validators/zipcode'
@@ -11,3 +12,6 @@ require 'via_cep/validators/zipcode'
11
12
  # Errors
12
13
  require 'via_cep/errors/invalid_zipcode_format'
13
14
  require 'via_cep/errors/zipcode_not_found'
15
+
16
+ # Utils
17
+ require 'via_cep/utils/utils'
@@ -0,0 +1,28 @@
1
+ require_relative 'methods'
2
+
3
+ module ViaCep
4
+ class SearchByAddress
5
+ def initialize(state:, city:, street:)
6
+ city = ViaCep::Utils.parameterize(city)
7
+ street = ViaCep::Utils.parameterize(street)
8
+
9
+ if state.size != 2
10
+ raise ArgumentError, 'State must have only abbreviations. Eg.: SP'
11
+ end
12
+
13
+ @response = HTTParty.get("#{base_url}/#{state}/#{city}/#{street}/json").first
14
+ end
15
+
16
+ ViaCep::METHODS.each do |method_name, response_method_name|
17
+ define_method(method_name) do
18
+ @response[response_method_name]
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def base_url
25
+ "https://viacep.com.br/ws"
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,20 @@
1
+ require 'active_support/all'
2
+
3
+ module ViaCep
4
+ class Utils
5
+ class << self
6
+ def handle_whitespaces(string)
7
+ string.split(' ').join('%20')
8
+ end
9
+
10
+ def handle_accents(string)
11
+ ActiveSupport::Inflector.transliterate(string)
12
+ end
13
+
14
+ def parameterize(string)
15
+ string = handle_accents(string)
16
+ handle_whitespaces(string)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module ViaCep
2
- VERSION = '0.2.3'
2
+ VERSION = '0.2.4'
3
3
  end
@@ -19,7 +19,9 @@ Gem::Specification.new do |s|
19
19
 
20
20
  s.add_development_dependency 'bundler', '~> 1.10'
21
21
  s.add_development_dependency 'rake', '~> 10.0'
22
- s.add_development_dependency 'rspec'
23
- s.add_development_dependency 'codeclimate-test-reporter'
24
- s.add_dependency 'httparty'
22
+ s.add_development_dependency 'rspec', '~> 3.4'
23
+ s.add_development_dependency 'codeclimate-test-reporter', '~> 0.5'
24
+ s.add_dependency 'httparty', '~> 0.13'
25
+ s.add_dependency 'activesupport', '~> 4.0'
26
+ s.add_dependency 'i18n', '~> 0.7'
25
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: via_cep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcelo Barreto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-19 00:00:00.000000000 Z
11
+ date: 2016-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -42,44 +42,72 @@ dependencies:
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '3.4'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '3.4'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: codeclimate-test-reporter
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '0.5'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '0.5'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: httparty
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.13'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.13'
83
+ - !ruby/object:Gem::Dependency
84
+ name: activesupport
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '4.0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '4.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: i18n
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
74
102
  - !ruby/object:Gem::Version
75
- version: '0'
103
+ version: '0.7'
76
104
  type: :runtime
77
105
  prerelease: false
78
106
  version_requirements: !ruby/object:Gem::Requirement
79
107
  requirements:
80
- - - ">="
108
+ - - "~>"
81
109
  - !ruby/object:Gem::Version
82
- version: '0'
110
+ version: '0.7'
83
111
  description:
84
112
  email:
85
113
  - marcelobarretojunior@gmail.com
@@ -105,6 +133,8 @@ files:
105
133
  - lib/via_cep/errors/invalid_zipcode_format.rb
106
134
  - lib/via_cep/errors/zipcode_not_found.rb
107
135
  - lib/via_cep/methods.rb
136
+ - lib/via_cep/search_by_zipcode.rb
137
+ - lib/via_cep/utils/utils.rb
108
138
  - lib/via_cep/validators/zipcode.rb
109
139
  - lib/via_cep/version.rb
110
140
  - via_cep.gemspec