via_cep 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +7 -0
- data/.travis.yml +3 -0
- data/Gemfile +0 -1
- data/README.md +16 -4
- data/lib/via_cep/address.rb +22 -0
- data/lib/via_cep/methods.rb +12 -0
- data/lib/via_cep/version.rb +1 -1
- data/lib/via_cep.rb +3 -44
- data/via_cep.gemspec +18 -16
- metadata +34 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28ae07ae24ba0766a1ebb411a759ba179d4efbfa
|
4
|
+
data.tar.gz: 42dda2251888df5160c8ac65bc31dced889d8da5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29567bac66005ab75b5ad35be22282b4f6e7259e7ec78f45bb60db846dd09669bd74bffb95248b6d2aafac86a1d682d2e5ef4e46c40e3c08985b3577c8c05080
|
7
|
+
data.tar.gz: 11a604452e5e61db02dbfcda264504c93762a246e1d480938b0b637e880dbb440e9febc6d5c4c0636c7dc0db5c8f9f2262604ca662a212be9845f9e53d2657b8
|
data/.codeclimate.yml
ADDED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,8 @@
|
|
2
2
|
|
3
3
|
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/via_cep`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
4
|
|
5
|
-
|
5
|
+
## Status
|
6
|
+
[![Build Status](https://api.travis-ci.org/marcelobarreto/via_cep.svg?branch=master)](https://travis-ci.org/marcelobarreto/via_cep) [![Code Climate](https://codeclimate.com/github/marcelobarreto/via_cep.svg)](https://codeclimate.com/github/marcelobareto/via_cep) [![Code Climate](https://codeclimate.com/github/marcelobarreto/via_cep/coverage.svg)](https://codeclimate.com/github/marcelobarreto/via_cep)
|
6
7
|
|
7
8
|
## Installation
|
8
9
|
|
@@ -22,7 +23,19 @@ Or install it yourself as:
|
|
22
23
|
|
23
24
|
## Usage
|
24
25
|
|
25
|
-
|
26
|
+
On terminal you can use via_cep like this:
|
27
|
+
```ruby
|
28
|
+
require 'via_cep'
|
29
|
+
|
30
|
+
address = ViaCep::Address.new('01001-000')
|
31
|
+
address = ViaCep::Address.new(01001000)
|
32
|
+
|
33
|
+
address.street # Returns "Praça da Sé"
|
34
|
+
```
|
35
|
+
|
36
|
+
### Available methods
|
37
|
+
|
38
|
+
zipcode, street, complement, neighborhood, city, state, ibge, gia.
|
26
39
|
|
27
40
|
## Development
|
28
41
|
|
@@ -32,10 +45,9 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
45
|
|
33
46
|
## Contributing
|
34
47
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
48
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/marcelobarreto/via_cep. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
36
49
|
|
37
50
|
|
38
51
|
## License
|
39
52
|
|
40
53
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
-
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module ViaCep
|
2
|
+
class Address
|
3
|
+
attr_reader :response
|
4
|
+
|
5
|
+
def initialize(zipcode)
|
6
|
+
begin
|
7
|
+
@response = HTTParty.get("https://viacep.com.br/ws/#{zipcode}/json/")
|
8
|
+
raise ArgumentError, 'Invalid zipcode format' unless has_valid_format?(zipcode)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def has_valid_format?(zipcode)
|
13
|
+
zipcode.to_s.match(/\d{5}(-)\d{3}\z/) || zipcode.to_s.match(/\d{8}/)
|
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
|
+
end
|
22
|
+
end
|
data/lib/via_cep/version.rb
CHANGED
data/lib/via_cep.rb
CHANGED
@@ -1,46 +1,5 @@
|
|
1
1
|
require 'via_cep/version'
|
2
|
+
require 'via_cep/methods'
|
3
|
+
require 'via_cep/format'
|
4
|
+
require 'via_cep/address'
|
2
5
|
require 'httparty'
|
3
|
-
|
4
|
-
module ViaCep
|
5
|
-
class CEP
|
6
|
-
def initialize(cep)
|
7
|
-
begin
|
8
|
-
@cep = cep.to_s
|
9
|
-
@response = HTTParty.get("https://viacep.com.br/ws/#{@cep}/json/")
|
10
|
-
raise RuntimeError unless correct_format(cep.to_s)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def street
|
15
|
-
@response["logradouro"]
|
16
|
-
end
|
17
|
-
|
18
|
-
def complement
|
19
|
-
@response["complemento"]
|
20
|
-
end
|
21
|
-
|
22
|
-
def neighborhood
|
23
|
-
@response["bairro"]
|
24
|
-
end
|
25
|
-
|
26
|
-
def city
|
27
|
-
@response["localidade"]
|
28
|
-
end
|
29
|
-
|
30
|
-
def state
|
31
|
-
@response["uf"]
|
32
|
-
end
|
33
|
-
|
34
|
-
def ibge
|
35
|
-
@response["ibge"]
|
36
|
-
end
|
37
|
-
|
38
|
-
def gia
|
39
|
-
@response["gia"]
|
40
|
-
end
|
41
|
-
|
42
|
-
def correct_format(cep)
|
43
|
-
return true if cep.match(/\d{5}(-)\d{3}\z/) or cep.match(/\d{8}/)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
data/via_cep.gemspec
CHANGED
@@ -3,22 +3,24 @@ lib = File.expand_path('../lib', __FILE__)
|
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
require 'via_cep/version'
|
5
5
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "via_cep"
|
8
|
+
s.version = ViaCep::VERSION
|
9
|
+
s.authors = ["Marcelo Barreto"]
|
10
|
+
s.email = ["marcelobarretojunior@gmail.com"]
|
11
|
+
s.summary = %q{Get brazillian zip-code information}
|
12
|
+
s.homepage = "http://www.github.com/marcelobarreto/via_cep"
|
13
|
+
s.license = "MIT"
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
s.bindir = 'exe'
|
17
|
+
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
s.add_development_dependency 'bundler', '~> 1.10'
|
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_development_dependency 'pry'
|
25
|
+
s.add_dependency 'httparty'
|
24
26
|
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.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcelo Barreto
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,34 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: codeclimate-test-reporter
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
84
|
name: httparty
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -73,6 +101,7 @@ executables: []
|
|
73
101
|
extensions: []
|
74
102
|
extra_rdoc_files: []
|
75
103
|
files:
|
104
|
+
- ".codeclimate.yml"
|
76
105
|
- ".gitignore"
|
77
106
|
- ".rspec"
|
78
107
|
- ".travis.yml"
|
@@ -84,6 +113,8 @@ files:
|
|
84
113
|
- bin/console
|
85
114
|
- bin/setup
|
86
115
|
- lib/via_cep.rb
|
116
|
+
- lib/via_cep/address.rb
|
117
|
+
- lib/via_cep/methods.rb
|
87
118
|
- lib/via_cep/version.rb
|
88
119
|
- via_cep.gemspec
|
89
120
|
homepage: http://www.github.com/marcelobarreto/via_cep
|
@@ -109,5 +140,5 @@ rubyforge_project:
|
|
109
140
|
rubygems_version: 2.4.8
|
110
141
|
signing_key:
|
111
142
|
specification_version: 4
|
112
|
-
summary: Get
|
143
|
+
summary: Get brazillian zip-code information
|
113
144
|
test_files: []
|