via_cep 2.0.1 → 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
2
  SHA256:
3
- metadata.gz: 00df8646dc3a6b1717bad27a4d433d4390707f3c1fec92cfc9f6eb872e514d8e
4
- data.tar.gz: 51ddd7c7c2ee022c4fc807a5e52175f6639d89488e3ad0bdc7a98fffecb5ba6e
3
+ metadata.gz: 6acf1f1df8168ec0213dba8cb0f8bc4a1604db9268b29fa30593a9d7323c1eb1
4
+ data.tar.gz: 9c16eaef9491ad33989a63c49d9c4faaac68b07e572b72a215c676474c96d633
5
5
  SHA512:
6
- metadata.gz: ca4c5852b3f90bac32c6d4de7bc23c8ad368a920683b4dba0f80fdaee52724a352b4720247eb82bdd4b9656bccb95597d4cb6bf1aa2c0001300323065fe52650
7
- data.tar.gz: e5f88bf4f73af01835d8b17ffe3365c7240cca292231c0aabada1c4065277da307b65930c4cbc73d106003e89b5f1ac3a066b1efa39602943c7dffb275f31b01
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 CHANGED
@@ -1,9 +1,12 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.2
3
-
4
- Style/Encoding:
5
- EnforcedStyle: always
6
- Enabled: true
7
-
8
- Style/FrozenStringLiteralComment:
9
- EnforcedStyle: always
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,13 +1,6 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  source 'https://rubygems.org'
5
4
 
6
5
  # Specify your gem's dependencies in via_cep.gemspec
7
6
  gemspec
8
-
9
- group :test do
10
- gem 'codeclimate-test-reporter', '~> 0.6'
11
- gem 'rubocop', '~> 0.49.0'
12
- gem 'rspec', '~> 3.5'
13
- end
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/Rakefile CHANGED
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  require 'bundler/gem_tasks'
data/bin/console CHANGED
@@ -1,7 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: utf-8
3
2
  # frozen_string_literal: true
4
- # encoding: utf-8
5
3
 
6
4
  require 'bundler/setup'
7
5
  require 'via_cep'
data/bin/zipcode CHANGED
@@ -1,12 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: utf-8
3
2
  # frozen_string_literal: true
4
- # encoding: utf-8
5
3
 
6
- $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
4
+ $LOAD_PATH.unshift(File.expand_path("#{File.dirname(__FILE__)}/../lib"))
7
5
  require 'via_cep'
8
6
 
9
- if ARGV.count > 0
7
+ if ARGV.count.positive?
10
8
  ARGV.each do |zipcode|
11
9
  address = ViaCep::Address.new(zipcode)
12
10
  puts "#{zipcode}:"
data/lib/via_cep.rb CHANGED
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  require 'via_cep/version'
@@ -6,22 +5,30 @@ require 'net/http'
6
5
  require 'uri'
7
6
  require 'json'
8
7
 
8
+ # Validators
9
+ require 'via_cep/validators'
10
+
11
+ # HTTP
12
+ require 'via_cep/http'
13
+
9
14
  # Core
10
- require 'via_cep/address'
11
15
  require 'via_cep/methods'
16
+ require 'via_cep/instance'
17
+ require 'via_cep/address'
12
18
  require 'via_cep/search_by_address'
13
19
 
14
- # Validators
15
- require 'via_cep/validators/zipcode'
16
- require 'via_cep/validators/state'
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
17
27
 
18
- # Errors
19
- require 'via_cep/errors/invalid_zipcode_format'
20
- require 'via_cep/errors/invalid_state_format'
21
- require 'via_cep/errors/zipcode_not_found'
22
- require 'via_cep/errors/address_not_found'
28
+ class InvalidStateFormat < StandardError; end
23
29
 
24
- # Utils
25
- require 'via_cep/utils/utils'
30
+ class InvalidAddressFormat < StandardError; end
26
31
 
27
- BASE_URL = 'https://viacep.com.br/ws'.freeze
32
+ class AddressNotFound < StandardError; end
33
+ end
34
+ end
@@ -1,29 +1,29 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
- require_relative 'methods'
5
-
6
3
  module ViaCep
7
4
  # Address class
8
- class Address
5
+ class Address < Instance
6
+ attr_reader :zipcode
7
+
9
8
  def initialize(zipcode)
10
- uri = URI("#{BASE_URL}/#{zipcode}/json/")
11
- request = Net::HTTP.get_response(uri)
9
+ @zipcode = zipcode
10
+ valid?
11
+ call_service
12
+ rescue JSON::ParserError, Net::HTTPBadRequest
13
+ raise ViaCep::Errors::ZipcodeNotFound
14
+ end
12
15
 
13
- raise ViaCep::Errors::InvalidZipcodeFormat unless ViaCep::Validators::
14
- Zipcode.valid?(zipcode)
16
+ private
15
17
 
16
- if request.code === '200'
17
- @response = JSON.parse(request.body)
18
+ def call_service
19
+ response = JSON.parse(ViaCep::HTTP.get(path: zipcode).body)
20
+ raise ViaCep::Errors::ZipcodeNotFound if response['erro']
18
21
 
19
- raise ViaCep::Errors::ZipcodeNotFound if @response['erro']
20
- end
22
+ define_attributes(response)
21
23
  end
22
24
 
23
- ViaCep::METHODS.each do |method_name, response_method_name|
24
- define_method(method_name) do
25
- @response[response_method_name]
26
- end
25
+ def valid?
26
+ raise ViaCep::Errors::InvalidZipcodeFormat unless ViaCep::Validators::Zipcode.valid?(zipcode)
27
27
  end
28
28
  end
29
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,16 +1,16 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module ViaCep
5
4
  # Translate methods allows us to use metaprogramming.
6
5
  METHODS = {
7
- zipcode: 'cep',
8
- street: 'logradouro',
9
- complement: 'complemento',
10
- neighborhood: 'bairro',
11
- city: 'localidade',
12
- state: 'uf',
13
- ibge: 'ibge',
14
- gia: 'gia'
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
15
  }.freeze
16
16
  end
@@ -1,28 +1,36 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
- require_relative 'methods'
5
-
6
3
  module ViaCep
7
4
  # Search an address
8
- class SearchByAddress
5
+ class SearchByAddress < Instance
6
+ attr_reader :state, :city, :street
7
+
9
8
  def initialize(state:, city:, street:)
10
- city = ViaCep::Utils.parameterize(city)
11
- street = ViaCep::Utils.parameterize(street)
9
+ @state = state
10
+ @city = city
11
+ @street = street
12
12
 
13
- raise ViaCep::Errors::InvalidStateFormat unless ViaCep::Validators::State.valid?(state)
13
+ valid?
14
+ call_service
15
+ rescue JSON::ParserError, Net::HTTPBadRequest
16
+ raise ViaCep::Errors::AddressNotFound
17
+ end
14
18
 
15
- uri = URI("#{BASE_URL}/#{state}/#{city}/#{street}/json")
16
- request = Net::HTTP.get_response(uri)
19
+ private
17
20
 
18
- @response = JSON.parse(request.body) if request.code === '200'
19
- raise ViaCep::Errors::AddressNotFound if @response.include?('Bad Request')
21
+ def valid?
22
+ raise ViaCep::Errors::InvalidStateFormat unless ViaCep::Validators::State.valid?(state)
23
+ raise ViaCep::Errors::InvalidAddressFormat unless city || state
20
24
  end
21
25
 
22
- ViaCep::METHODS.each do |method_name, response_method_name|
23
- define_method(method_name) do
24
- @response.first[response_method_name]
25
- end
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])
26
34
  end
27
35
  end
28
36
  end
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module ViaCep
@@ -7,15 +6,21 @@ module ViaCep
7
6
  module State
8
7
  class << self
9
8
  def valid?(state)
10
- states.include?(state.to_s)
11
- end
12
-
13
- def states
14
9
  %w[
15
10
  AC AL AP AM BA CE DF ES GO
16
11
  MA MT MS MG PR PB PA PE PI
17
12
  RJ RN RS RO RR SC SE SP TO
18
- ]
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}$/)
19
24
  end
20
25
  end
21
26
  end
@@ -1,6 +1,5 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module ViaCep
5
- VERSION = '2.0.1'.freeze
4
+ VERSION = '3.1.3'
6
5
  end
data/via_cep.gemspec CHANGED
@@ -1,26 +1,29 @@
1
- # coding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
- lib = File.expand_path('../lib', __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
5
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
5
  require 'via_cep/version'
7
6
 
8
- Gem::Specification.new do |s|
9
- s.name = 'via_cep'
10
- s.version = ViaCep::VERSION
11
- s.authors = ['Marcelo Barreto (@marcelobarreto)']
12
- s.email = ['marcelobarretojunior@gmail.com']
13
- s.summary = 'Brazillian zip-code information'
14
- s.homepage = 'http://www.github.com/marcelobarreto/via_cep'
15
- 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
16
 
17
- s.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
18
  f.match(%r{^(test|spec|features)/})
19
19
  end
20
20
 
21
- s.bindir = 'bin'
22
- s.executables = ['zipcode']
23
- s.require_paths = ['lib']
21
+ spec.bindir = 'bin'
22
+ spec.executables = ['zipcode']
23
+ spec.require_paths = ['lib']
24
24
 
25
- s.add_dependency 'activesupport', '~> 5.0'
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'
26
29
  end
metadata CHANGED
@@ -1,29 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: via_cep
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 3.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcelo Barreto (@marcelobarreto)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-20 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: activesupport
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: '5.0'
20
- type: :runtime
19
+ version: '0.6'
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: '5.0'
26
+ version: '0.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 13.0.3
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 13.0.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.12.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.12.0
27
69
  description:
28
70
  email:
29
71
  - marcelobarretojunior@gmail.com
@@ -36,10 +78,14 @@ files:
36
78
  - ".gitignore"
37
79
  - ".rspec"
38
80
  - ".rubocop.yml"
81
+ - ".ruby-gemset"
82
+ - ".ruby-version"
39
83
  - ".travis.yml"
40
84
  - CODE_OF_CONDUCT.md
41
85
  - Gemfile
86
+ - Gemfile.lock
42
87
  - LICENSE.txt
88
+ - Makefile
43
89
  - README.md
44
90
  - Rakefile
45
91
  - bin/console
@@ -47,15 +93,11 @@ files:
47
93
  - bin/zipcode
48
94
  - lib/via_cep.rb
49
95
  - lib/via_cep/address.rb
50
- - lib/via_cep/errors/address_not_found.rb
51
- - lib/via_cep/errors/invalid_state_format.rb
52
- - lib/via_cep/errors/invalid_zipcode_format.rb
53
- - lib/via_cep/errors/zipcode_not_found.rb
96
+ - lib/via_cep/http.rb
97
+ - lib/via_cep/instance.rb
54
98
  - lib/via_cep/methods.rb
55
99
  - lib/via_cep/search_by_address.rb
56
- - lib/via_cep/utils/utils.rb
57
- - lib/via_cep/validators/state.rb
58
- - lib/via_cep/validators/zipcode.rb
100
+ - lib/via_cep/validators.rb
59
101
  - lib/via_cep/version.rb
60
102
  - via_cep.gemspec
61
103
  homepage: http://www.github.com/marcelobarreto/via_cep
@@ -70,15 +112,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
112
  requirements:
71
113
  - - ">="
72
114
  - !ruby/object:Gem::Version
73
- version: '0'
115
+ version: '2.6'
74
116
  required_rubygems_version: !ruby/object:Gem::Requirement
75
117
  requirements:
76
118
  - - ">="
77
119
  - !ruby/object:Gem::Version
78
120
  version: '0'
79
121
  requirements: []
80
- rubyforge_project:
81
- rubygems_version: 2.7.9
122
+ rubygems_version: 3.0.9
82
123
  signing_key:
83
124
  specification_version: 4
84
125
  summary: Brazillian zip-code information
@@ -1,15 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
-
4
- module ViaCep
5
- module Errors
6
- # This class is responsible to show an error
7
- class AddressNotFound < ArgumentError
8
- attr_reader :message
9
-
10
- def initialize
11
- @message = 'Not found anything for that address'
12
- end
13
- end
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
-
4
- module ViaCep
5
- module Errors
6
- # This class is responsible to show an error
7
- class InvalidStateFormat < ArgumentError
8
- attr_reader :message
9
-
10
- def initialize
11
- @message = 'State has an invalid format'
12
- end
13
- end
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
-
4
- module ViaCep
5
- module Errors
6
- # This class is responsible to show an error
7
- class InvalidZipcodeFormat < ArgumentError
8
- attr_reader :message
9
-
10
- def initialize
11
- @message = 'Zipcode has an invalid format'
12
- end
13
- end
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
-
4
- module ViaCep
5
- module Errors
6
- # This class is responsible to show an error
7
- class ZipcodeNotFound < StandardError
8
- attr_reader :message
9
-
10
- def initialize
11
- @message = 'Not found anything for that zipcode'
12
- end
13
- end
14
- end
15
- end
@@ -1,24 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
-
4
- require 'active_support/all'
5
-
6
- module ViaCep
7
- # Utils module
8
- class Utils
9
- class << self
10
- def handle_whitespaces(string)
11
- string.split(' ').join('%20')
12
- end
13
-
14
- def handle_accents(string)
15
- ActiveSupport::Inflector.transliterate(string)
16
- end
17
-
18
- def parameterize(string)
19
- string = handle_accents(string)
20
- handle_whitespaces(string)
21
- end
22
- end
23
- end
24
- end
@@ -1,22 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
-
4
- module ViaCep
5
- module Validators
6
- # Zipcode validator
7
- module Zipcode
8
- class << self
9
- def valid?(zipcode)
10
- zipcode = zipcode.to_s
11
-
12
- return true if match_regex?(zipcode)
13
- end
14
-
15
- def match_regex?(zipcode)
16
- zipcode = zipcode.to_s
17
- zipcode.match(/^[0-9]{5}(-)[0-9]{3}$/) || zipcode.match(/^[0-9]{8}$/)
18
- end
19
- end
20
- end
21
- end
22
- end