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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 19a89de51b4fad2837169e4dd2078b8b3b4551de
4
- data.tar.gz: e177fe46477c0ac7493e0b78dbc96e3828e12a65
3
+ metadata.gz: 28ae07ae24ba0766a1ebb411a759ba179d4efbfa
4
+ data.tar.gz: 42dda2251888df5160c8ac65bc31dced889d8da5
5
5
  SHA512:
6
- metadata.gz: b7886e783cc04870f72a3bc9e559bd54dc4ba1ddaf7db769712d13abbed9a1d6571934de4cab2965b54a3444f9740f7c90eb2bdd5f1e9ac7237ace2eb2e4d7dd
7
- data.tar.gz: d035e7ec0feb57b755ee6fcc93d3d8f86a6b77ffb061ad00d0021edec296bb0fc891979f8fc5b7f79b29f5d8298f9bbf01b70ed8ecff8644671bfdb25caa9543
6
+ metadata.gz: 29567bac66005ab75b5ad35be22282b4f6e7259e7ec78f45bb60db846dd09669bd74bffb95248b6d2aafac86a1d682d2e5ef4e46c40e3c08985b3577c8c05080
7
+ data.tar.gz: 11a604452e5e61db02dbfcda264504c93762a246e1d480938b0b637e880dbb440e9febc6d5c4c0636c7dc0db5c8f9f2262604ca662a212be9845f9e53d2657b8
data/.codeclimate.yml ADDED
@@ -0,0 +1,7 @@
1
+ engines:
2
+ rubocop:
3
+ enabled: true
4
+ ratings:
5
+ paths:
6
+ - Gemfile.lock
7
+ - "**.rb"
data/.travis.yml CHANGED
@@ -2,3 +2,6 @@ language: ruby
2
2
  rvm:
3
3
  - 2.2.3
4
4
  before_install: gem install bundler -v 1.10.6
5
+ addons:
6
+ code_climate:
7
+ repo_token: c70e0538e62cddacecb3cb86033e4595d0e3a36653ab9dfeb51328f7be55a0f3
data/Gemfile CHANGED
@@ -2,4 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in via_cep.gemspec
4
4
  gemspec
5
- gem 'httparty'
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
- TODO: Delete this and the text above, and describe your gem
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
- TODO: Write usage instructions here
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/[USERNAME]/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.
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
@@ -0,0 +1,12 @@
1
+ module ViaCep
2
+ METHODS = {
3
+ zipcode: 'cep',
4
+ street: 'logradouro',
5
+ complement: 'complemento',
6
+ neighborhood: 'bairro',
7
+ city: 'localidade',
8
+ state: 'uf',
9
+ ibge: 'ibge',
10
+ gia: 'gia'
11
+ }
12
+ end
@@ -1,3 +1,3 @@
1
1
  module ViaCep
2
- VERSION = "0.1.0"
2
+ VERSION = '0.2.1'
3
3
  end
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 |spec|
7
- spec.name = "via_cep"
8
- spec.version = ViaCep::VERSION
9
- spec.authors = ["Marcelo Barreto"]
10
- spec.email = ["marcelobarretojunior@gmail.com"]
11
- spec.summary = %q{Get Brazil zip-code}
12
- spec.homepage = "http://www.github.com/marcelobarreto/via_cep"
13
- spec.license = "MIT"
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
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
- spec.bindir = "exe"
17
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
- spec.require_paths = ["lib"]
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
- spec.add_development_dependency "bundler", "~> 1.10"
21
- spec.add_development_dependency "rake", "~> 10.0"
22
- spec.add_development_dependency "rspec"
23
- spec.add_dependency 'httparty'
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.0
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-03-04 00:00:00.000000000 Z
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 Brazil zip-code
143
+ summary: Get brazillian zip-code information
113
144
  test_files: []