via_cep 0.2.4 → 3.1.3

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
- SHA1:
3
- metadata.gz: c8d1daae20313725996e5fd0304ca40f27588cd0
4
- data.tar.gz: 531434accc95eee1beec369b04b07f6ebd84fafe
2
+ SHA256:
3
+ metadata.gz: 6acf1f1df8168ec0213dba8cb0f8bc4a1604db9268b29fa30593a9d7323c1eb1
4
+ data.tar.gz: 9c16eaef9491ad33989a63c49d9c4faaac68b07e572b72a215c676474c96d633
5
5
  SHA512:
6
- metadata.gz: 1c9f9e2c3ca871ba2b37ed6734b11994a5f95574bd4d2b48b5bf0813daada4916a6bd4bc48ab0febd49958c1bb39de8427c3933050d8eda59a4f065ceef498c3
7
- data.tar.gz: 22b0cb9e44a9ac8b368b7d672fac8ee4de83a4eca082805eb9d7a836420932404ea8b2030d0c4e00868571179c32ae6bf4e9e5f0c8a322a19957062d7b53d4cd
6
+ metadata.gz: ef87668c195c9c3f288909972af1964c037b77985d76d55d8d3b1f50191bf6cddd762401a66e73778f64d6bc9a1c68e699b330e56da0608b578aa13a5eaed524
7
+ data.tar.gz: 35ac112a7acc2337c70e5184b15f18961d9e03169aca0e54a4332a243e6f47a853277a16d48357b43f017d9aea8a2d07eab6dbf569329a2a33b3c17a2d9a2f28
data/.gitignore CHANGED
@@ -1,6 +1,5 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
- /Gemfile.lock
4
3
  /_yardoc/
5
4
  /coverage/
6
5
  /doc/
data/.rubocop.yml ADDED
@@ -0,0 +1,12 @@
1
+ AllCops:
2
+ SuggestExtensions: false
3
+ Exclude:
4
+ - 'spec/**/*.rb'
5
+ Style/Documentation:
6
+ Enabled: false
7
+ Style/HashEachMethods:
8
+ Enabled: false
9
+ Lint/MissingSuper:
10
+ Enabled: false
11
+ Lint/UriEscapeUnescap:
12
+ Enabled: false
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ via_cep
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.3
data/.travis.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.3
4
- before_install: gem install bundler -v 1.10.6
3
+ - 2.6.3
4
+ before_install: gem install bundler:2.1.4
5
5
  addons:
6
6
  code_climate:
7
7
  repo_token: c70e0538e62cddacecb3cb86033e4595d0e3a36653ab9dfeb51328f7be55a0f3
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in via_cep.gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,63 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ via_cep (3.1.3)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ codeclimate-test-reporter (0.6.0)
11
+ simplecov (>= 0.7.1, < 1.0.0)
12
+ diff-lcs (1.4.4)
13
+ docile (1.3.2)
14
+ parallel (1.20.1)
15
+ parser (3.0.0.0)
16
+ ast (~> 2.4.1)
17
+ rainbow (3.0.0)
18
+ rake (13.0.3)
19
+ regexp_parser (2.1.1)
20
+ rexml (3.2.4)
21
+ rspec (3.9.0)
22
+ rspec-core (~> 3.9.0)
23
+ rspec-expectations (~> 3.9.0)
24
+ rspec-mocks (~> 3.9.0)
25
+ rspec-core (3.9.3)
26
+ rspec-support (~> 3.9.3)
27
+ rspec-expectations (3.9.2)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.9.0)
30
+ rspec-mocks (3.9.1)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.9.0)
33
+ rspec-support (3.9.3)
34
+ rubocop (1.12.0)
35
+ parallel (~> 1.10)
36
+ parser (>= 3.0.0.0)
37
+ rainbow (>= 2.2.2, < 4.0)
38
+ regexp_parser (>= 1.8, < 3.0)
39
+ rexml
40
+ rubocop-ast (>= 1.2.0, < 2.0)
41
+ ruby-progressbar (~> 1.7)
42
+ unicode-display_width (>= 1.4.0, < 3.0)
43
+ rubocop-ast (1.4.1)
44
+ parser (>= 2.7.1.5)
45
+ ruby-progressbar (1.11.0)
46
+ simplecov (0.19.0)
47
+ docile (~> 1.1)
48
+ simplecov-html (~> 0.11)
49
+ simplecov-html (0.12.3)
50
+ unicode-display_width (2.0.0)
51
+
52
+ PLATFORMS
53
+ ruby
54
+
55
+ DEPENDENCIES
56
+ codeclimate-test-reporter (~> 0.6)
57
+ rake (~> 13.0.3)
58
+ rspec (~> 3.5)
59
+ rubocop (~> 1.12.0)
60
+ via_cep!
61
+
62
+ BUNDLED WITH
63
+ 2.1.4
data/Makefile ADDED
@@ -0,0 +1,2 @@
1
+ default:
2
+ ./bin/console
data/README.md CHANGED
@@ -1,9 +1,8 @@
1
1
  # ViaCep
2
2
 
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
-
5
3
  ## 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)
4
+ [![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)[![RubyGems](http://img.shields.io/gem/dt/via_cep.svg?style=flat)](http://rubygems.org/gems/via_cep)
5
+
7
6
 
8
7
  ## Installation
9
8
 
@@ -55,6 +54,13 @@ It will return 2 address with its information
55
54
  SP
56
55
  ```
57
56
 
57
+ And also search for a zipcode by an address
58
+
59
+ ```ruby
60
+ search = ViaCep::SearchByAddress.new(state: 'SP', city: 'São Paulo', street: 'Praça da Sé')
61
+
62
+ search.zipcode # => "01001-000"
63
+ ```
58
64
 
59
65
  ### Available methods
60
66
 
@@ -68,7 +74,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
68
74
 
69
75
  ## Contributing
70
76
 
71
- 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.
77
+ 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](CODE_OF_CONDUCT.md) code of conduct.
72
78
 
73
79
 
74
80
  ## License
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
data/bin/console CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "via_cep"
4
+ require 'bundler/setup'
5
+ require 'via_cep'
5
6
 
6
7
  # You can add fixtures and/or initialization code here to make experimenting
7
8
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +11,5 @@ require "via_cep"
10
11
  # require "pry"
11
12
  # Pry.start
12
13
 
13
- require "irb"
14
+ require 'irb'
14
15
  IRB.start
data/bin/zipcode CHANGED
@@ -1,9 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
4
+ $LOAD_PATH.unshift(File.expand_path("#{File.dirname(__FILE__)}/../lib"))
4
5
  require 'via_cep'
5
6
 
6
- if ARGV.count > 0
7
+ if ARGV.count.positive?
7
8
  ARGV.each do |zipcode|
8
9
  address = ViaCep::Address.new(zipcode)
9
10
  puts "#{zipcode}:"
data/lib/via_cep.rb CHANGED
@@ -1,17 +1,34 @@
1
- require 'httparty'
1
+ # frozen_string_literal: true
2
+
2
3
  require 'via_cep/version'
4
+ require 'net/http'
5
+ require 'uri'
6
+ require 'json'
7
+
8
+ # Validators
9
+ require 'via_cep/validators'
10
+
11
+ # HTTP
12
+ require 'via_cep/http'
3
13
 
4
14
  # Core
5
- require 'via_cep/address'
6
15
  require 'via_cep/methods'
7
- require 'via_cep/search_by_zipcode'
16
+ require 'via_cep/instance'
17
+ require 'via_cep/address'
18
+ require 'via_cep/search_by_address'
8
19
 
9
- # Validators
10
- require 'via_cep/validators/zipcode'
20
+ module ViaCep
21
+ BASE_URL = 'https://viacep.com.br'
22
+
23
+ module Errors
24
+ class ZipcodeNotFound < StandardError; end
25
+
26
+ class InvalidZipcodeFormat < StandardError; end
27
+
28
+ class InvalidStateFormat < StandardError; end
11
29
 
12
- # Errors
13
- require 'via_cep/errors/invalid_zipcode_format'
14
- require 'via_cep/errors/zipcode_not_found'
30
+ class InvalidAddressFormat < StandardError; end
15
31
 
16
- # Utils
17
- require 'via_cep/utils/utils'
32
+ class AddressNotFound < StandardError; end
33
+ end
34
+ end
@@ -1,21 +1,29 @@
1
- require_relative 'methods'
1
+ # frozen_string_literal: true
2
2
 
3
3
  module ViaCep
4
- class Address
4
+ # Address class
5
+ class Address < Instance
6
+ attr_reader :zipcode
7
+
5
8
  def initialize(zipcode)
6
- @response = HTTParty.get("https://viacep.com.br/ws/#{zipcode}/json/")
9
+ @zipcode = zipcode
10
+ valid?
11
+ call_service
12
+ rescue JSON::ParserError, Net::HTTPBadRequest
13
+ raise ViaCep::Errors::ZipcodeNotFound
14
+ end
15
+
16
+ private
17
+
18
+ def call_service
19
+ response = JSON.parse(ViaCep::HTTP.get(path: zipcode).body)
20
+ raise ViaCep::Errors::ZipcodeNotFound if response['erro']
7
21
 
8
- if !ViaCep::Validators::Zipcode.valid?(zipcode)
9
- raise ViaCep::Errors::InvalidZipcodeFormat
10
- elsif @response['erro']
11
- raise ViaCep::Errors::ZipcodeNotFound
12
- end
22
+ define_attributes(response)
13
23
  end
14
24
 
15
- ViaCep::METHODS.each do |method_name, response_method_name|
16
- define_method(method_name) do
17
- @response[response_method_name]
18
- end
25
+ def valid?
26
+ raise ViaCep::Errors::InvalidZipcodeFormat unless ViaCep::Validators::Zipcode.valid?(zipcode)
19
27
  end
20
28
  end
21
29
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ViaCep
4
+ module HTTP
5
+ def self.get(path:, query: {})
6
+ uri = URI(BASE_URL)
7
+ uri.path = "/ws/#{URI.encode(path)}/json"
8
+ uri.query = URI.encode_www_form(query)
9
+
10
+ Net::HTTP.get_response(uri)
11
+ end
12
+
13
+ def self.was_successful?(request)
14
+ request.code.eql?('200')
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ViaCep
4
+ class Instance
5
+ def define_attributes(response)
6
+ ViaCep::METHODS.each do |method_name, response_key|
7
+ value = response[response_key.to_s]
8
+
9
+ instance_variable_set("@#{method_name}", value)
10
+ self.class.define_method(method_name) do
11
+ instance_variable_get("@#{method_name}")
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,12 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ViaCep
4
+ # Translate methods allows us to use metaprogramming.
2
5
  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
- }
6
+ zipcode: :cep,
7
+ street: :logradouro,
8
+ complement: :complemento,
9
+ neighborhood: :bairro,
10
+ city: :localidade,
11
+ state: :uf,
12
+ ibge: :ibge,
13
+ gia: :gia,
14
+ error: :erro
15
+ }.freeze
12
16
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ViaCep
4
+ # Search an address
5
+ class SearchByAddress < Instance
6
+ attr_reader :state, :city, :street
7
+
8
+ def initialize(state:, city:, street:)
9
+ @state = state
10
+ @city = city
11
+ @street = street
12
+
13
+ valid?
14
+ call_service
15
+ rescue JSON::ParserError, Net::HTTPBadRequest
16
+ raise ViaCep::Errors::AddressNotFound
17
+ end
18
+
19
+ private
20
+
21
+ def valid?
22
+ raise ViaCep::Errors::InvalidStateFormat unless ViaCep::Validators::State.valid?(state)
23
+ raise ViaCep::Errors::InvalidAddressFormat unless city || state
24
+ end
25
+
26
+ def call_service
27
+ request = HTTP.get(path: "#{state}/#{city}/#{street}")
28
+ raise ViaCep::Errors::AddressNotFound unless HTTP.was_successful?(request)
29
+
30
+ response = JSON.parse(request.body)
31
+ raise ViaCep::Errors::AddressNotFound if response.length.eql?(0)
32
+
33
+ define_attributes(response[0])
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ViaCep
4
+ module Validators
5
+ # State validator
6
+ module State
7
+ class << self
8
+ def valid?(state)
9
+ %w[
10
+ AC AL AP AM BA CE DF ES GO
11
+ MA MT MS MG PR PB PA PE PI
12
+ RJ RN RS RO RR SC SE SP TO
13
+ ].include?(state.to_s)
14
+ end
15
+ end
16
+ end
17
+
18
+ # Zipcode validator
19
+ module Zipcode
20
+ class << self
21
+ def valid?(zipcode)
22
+ zipcode = zipcode.to_s
23
+ !!zipcode.match(/^[0-9]{5}(-)[0-9]{3}$/) || !!zipcode.match(/^[0-9]{8}$/)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ViaCep
2
- VERSION = '0.2.4'
4
+ VERSION = '3.1.3'
3
5
  end
data/via_cep.gemspec CHANGED
@@ -1,27 +1,29 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'via_cep/version'
5
6
 
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{Brazillian zip-code information}
12
- s.homepage = "http://www.github.com/marcelobarreto/via_cep"
13
- s.license = "MIT"
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'via_cep'
9
+ spec.version = ViaCep::VERSION
10
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.6')
11
+ spec.authors = ['Marcelo Barreto (@marcelobarreto)']
12
+ spec.email = ['marcelobarretojunior@gmail.com']
13
+ spec.summary = 'Brazillian zip-code information'
14
+ spec.homepage = 'http://www.github.com/marcelobarreto/via_cep'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
14
20
 
15
- s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
- s.bindir = "bin"
17
- s.executables = ["zipcode"]
18
- s.require_paths = ["lib"]
21
+ spec.bindir = 'bin'
22
+ spec.executables = ['zipcode']
23
+ spec.require_paths = ['lib']
19
24
 
20
- s.add_development_dependency 'bundler', '~> 1.10'
21
- s.add_development_dependency 'rake', '~> 10.0'
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
+ spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.6'
26
+ spec.add_development_dependency 'rake', '~> 13.0.3'
27
+ spec.add_development_dependency 'rspec', '~> 3.5'
28
+ spec.add_development_dependency 'rubocop', '~> 1.12.0'
27
29
  end
metadata CHANGED
@@ -1,113 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: via_cep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 3.1.3
5
5
  platform: ruby
6
6
  authors:
7
- - Marcelo Barreto
7
+ - Marcelo Barreto (@marcelobarreto)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-22 00:00:00.000000000 Z
11
+ date: 2021-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: codeclimate-test-reporter
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.10'
19
+ version: '0.6'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.10'
26
+ version: '0.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: 13.0.3
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: 13.0.3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.4'
47
+ version: '3.5'
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: '3.4'
54
+ version: '3.5'
55
55
  - !ruby/object:Gem::Dependency
56
- name: codeclimate-test-reporter
56
+ name: rubocop
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.5'
61
+ version: 1.12.0
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.5'
69
- - !ruby/object:Gem::Dependency
70
- name: httparty
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
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
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '0.7'
104
- type: :runtime
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '0.7'
68
+ version: 1.12.0
111
69
  description:
112
70
  email:
113
71
  - marcelobarretojunior@gmail.com
@@ -119,10 +77,15 @@ files:
119
77
  - ".codeclimate.yml"
120
78
  - ".gitignore"
121
79
  - ".rspec"
80
+ - ".rubocop.yml"
81
+ - ".ruby-gemset"
82
+ - ".ruby-version"
122
83
  - ".travis.yml"
123
84
  - CODE_OF_CONDUCT.md
124
85
  - Gemfile
86
+ - Gemfile.lock
125
87
  - LICENSE.txt
88
+ - Makefile
126
89
  - README.md
127
90
  - Rakefile
128
91
  - bin/console
@@ -130,12 +93,11 @@ files:
130
93
  - bin/zipcode
131
94
  - lib/via_cep.rb
132
95
  - lib/via_cep/address.rb
133
- - lib/via_cep/errors/invalid_zipcode_format.rb
134
- - lib/via_cep/errors/zipcode_not_found.rb
96
+ - lib/via_cep/http.rb
97
+ - lib/via_cep/instance.rb
135
98
  - lib/via_cep/methods.rb
136
- - lib/via_cep/search_by_zipcode.rb
137
- - lib/via_cep/utils/utils.rb
138
- - lib/via_cep/validators/zipcode.rb
99
+ - lib/via_cep/search_by_address.rb
100
+ - lib/via_cep/validators.rb
139
101
  - lib/via_cep/version.rb
140
102
  - via_cep.gemspec
141
103
  homepage: http://www.github.com/marcelobarreto/via_cep
@@ -150,15 +112,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
150
112
  requirements:
151
113
  - - ">="
152
114
  - !ruby/object:Gem::Version
153
- version: '0'
115
+ version: '2.6'
154
116
  required_rubygems_version: !ruby/object:Gem::Requirement
155
117
  requirements:
156
118
  - - ">="
157
119
  - !ruby/object:Gem::Version
158
120
  version: '0'
159
121
  requirements: []
160
- rubyforge_project:
161
- rubygems_version: 2.4.8
122
+ rubygems_version: 3.0.9
162
123
  signing_key:
163
124
  specification_version: 4
164
125
  summary: Brazillian zip-code information
@@ -1,11 +0,0 @@
1
- module ViaCep
2
- module Errors
3
- class InvalidZipcodeFormat < ArgumentError
4
- attr_reader :message
5
-
6
- def initialize
7
- @message = 'Zipcode has an invalid format'
8
- end
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- module ViaCep
2
- module Errors
3
- class ZipcodeNotFound < StandardError
4
- attr_reader :message
5
-
6
- def initialize
7
- @message = "Not found anything for that zipcode"
8
- end
9
- end
10
- end
11
- end
@@ -1,28 +0,0 @@
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
@@ -1,20 +0,0 @@
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,18 +0,0 @@
1
- module ViaCep
2
- module Validators
3
- module Zipcode
4
- class << self
5
- def valid?(zipcode)
6
- zipcode = zipcode.to_s
7
-
8
- return true if self.match_regex?(zipcode)
9
- end
10
-
11
- def match_regex?(zipcode)
12
- zipcode = zipcode.to_s
13
- zipcode.match(/^[0-9]{5}(-)[0-9]{3}$/) || zipcode.match(/^[0-9]{8}$/)
14
- end
15
- end
16
- end
17
- end
18
- end