via_cep 3.1.3 → 3.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6acf1f1df8168ec0213dba8cb0f8bc4a1604db9268b29fa30593a9d7323c1eb1
4
- data.tar.gz: 9c16eaef9491ad33989a63c49d9c4faaac68b07e572b72a215c676474c96d633
3
+ metadata.gz: a5b87542eabffdf88cf0c29abc14f443096126c90ebbe62cca399977cd32ddf6
4
+ data.tar.gz: 5aab5e128777294d118d7b79547f2b220b11551f74bf39eddb8e6367758ccf91
5
5
  SHA512:
6
- metadata.gz: ef87668c195c9c3f288909972af1964c037b77985d76d55d8d3b1f50191bf6cddd762401a66e73778f64d6bc9a1c68e699b330e56da0608b578aa13a5eaed524
7
- data.tar.gz: 35ac112a7acc2337c70e5184b15f18961d9e03169aca0e54a4332a243e6f47a853277a16d48357b43f017d9aea8a2d07eab6dbf569329a2a33b3c17a2d9a2f28
6
+ metadata.gz: 165e86cfe16bbdcbeeac1f279969fe347aaa5b5988cf28f1b049a7bdc50102e1998822ccf7f14dd01446a9fb9c70385e75527bb26b601e21af2a658f2be39f42
7
+ data.tar.gz: cb3130b542ef1b02b5f1345f1205c4c30c587d14d674b1e8043b015e49c314d5a77580293c5052381e43a6daf49239bc0d978f4bd1d75d3aa700b1d09a31e587
data/.codeclimate.yml CHANGED
@@ -1,7 +1,10 @@
1
- engines:
1
+ version: "2"
2
+ plugins:
2
3
  rubocop:
3
4
  enabled: true
4
- ratings:
5
- paths:
6
- - Gemfile.lock
7
- - "**.rb"
5
+ channel: rubocop-0-60
6
+ config:
7
+ file: ".rubocop.yml"
8
+ exclude_patterns:
9
+ - "spec/"
10
+ - "!spec/support/helpers"
@@ -0,0 +1,18 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: bundler
4
+ directory: "/"
5
+ schedule:
6
+ interval: weekly
7
+ time: "09:00"
8
+ open-pull-requests-limit: 10
9
+ ignore:
10
+ - dependency-name: rspec
11
+ versions:
12
+ - 3.10.0
13
+ - dependency-name: rubocop
14
+ versions:
15
+ - 1.10.0
16
+ - 1.11.0
17
+ - 1.8.1
18
+ - 1.9.1
@@ -0,0 +1,19 @@
1
+ # Overview
2
+
3
+ ## Implementation Details
4
+
5
+ ## Required Documentation Updates
6
+
7
+ None.
8
+
9
+ ## Testing Notes
10
+
11
+ None.
12
+
13
+ ## API Changes
14
+
15
+ None.
16
+
17
+ ## External Dependency Changes
18
+
19
+ None.
data/.rubocop.yml CHANGED
@@ -8,5 +8,5 @@ Style/HashEachMethods:
8
8
  Enabled: false
9
9
  Lint/MissingSuper:
10
10
  Enabled: false
11
- Lint/UriEscapeUnescap:
11
+ Lint/UriEscapeUnescape:
12
12
  Enabled: false
data/.travis.yml CHANGED
@@ -1,7 +1,15 @@
1
+ env:
2
+ global:
3
+ - CC_TEST_REPORTER_ID=$CODE_CLIMATE_TOKEN
1
4
  language: ruby
2
5
  rvm:
3
6
  - 2.6.3
4
- before_install: gem install bundler:2.1.4
5
- addons:
6
- code_climate:
7
- repo_token: c70e0538e62cddacecb3cb86033e4595d0e3a36653ab9dfeb51328f7be55a0f3
7
+ before_script:
8
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
9
+ - chmod +x ./cc-test-reporter
10
+ - ./cc-test-reporter before-build
11
+ - gem install bundler:2.1.4
12
+ script:
13
+ - bundle exec rspec
14
+ after_script:
15
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
data/FUNDING.yml ADDED
@@ -0,0 +1,3 @@
1
+ # These are supported funding model platforms
2
+
3
+ patreon: marcelobarreto
data/Gemfile.lock CHANGED
@@ -1,23 +1,22 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- via_cep (3.1.3)
4
+ via_cep (3.1.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  ast (2.4.2)
10
- codeclimate-test-reporter (0.6.0)
11
- simplecov (>= 0.7.1, < 1.0.0)
12
10
  diff-lcs (1.4.4)
13
- docile (1.3.2)
14
- parallel (1.20.1)
15
- parser (3.0.0.0)
11
+ docile (1.4.1)
12
+ json (2.6.3)
13
+ parallel (1.22.1)
14
+ parser (3.2.0.0)
16
15
  ast (~> 2.4.1)
17
- rainbow (3.0.0)
16
+ rainbow (3.1.1)
18
17
  rake (13.0.3)
19
- regexp_parser (2.1.1)
20
- rexml (3.2.4)
18
+ regexp_parser (2.6.1)
19
+ rexml (3.2.5)
21
20
  rspec (3.9.0)
22
21
  rspec-core (~> 3.9.0)
23
22
  rspec-expectations (~> 3.9.0)
@@ -31,32 +30,35 @@ GEM
31
30
  diff-lcs (>= 1.2.0, < 2.0)
32
31
  rspec-support (~> 3.9.0)
33
32
  rspec-support (3.9.3)
34
- rubocop (1.12.0)
33
+ rubocop (1.43.0)
34
+ json (~> 2.3)
35
35
  parallel (~> 1.10)
36
- parser (>= 3.0.0.0)
36
+ parser (>= 3.2.0.0)
37
37
  rainbow (>= 2.2.2, < 4.0)
38
38
  regexp_parser (>= 1.8, < 3.0)
39
- rexml
40
- rubocop-ast (>= 1.2.0, < 2.0)
39
+ rexml (>= 3.2.5, < 4.0)
40
+ rubocop-ast (>= 1.24.1, < 2.0)
41
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)
42
+ unicode-display_width (>= 2.4.0, < 3.0)
43
+ rubocop-ast (1.24.1)
44
+ parser (>= 3.1.1.0)
45
45
  ruby-progressbar (1.11.0)
46
- simplecov (0.19.0)
46
+ simplecov (0.22.0)
47
47
  docile (~> 1.1)
48
48
  simplecov-html (~> 0.11)
49
- simplecov-html (0.12.3)
50
- unicode-display_width (2.0.0)
49
+ simplecov_json_formatter (~> 0.1)
50
+ simplecov-html (0.13.0)
51
+ simplecov_json_formatter (0.1.4)
52
+ unicode-display_width (2.4.2)
51
53
 
52
54
  PLATFORMS
53
55
  ruby
54
56
 
55
57
  DEPENDENCIES
56
- codeclimate-test-reporter (~> 0.6)
57
58
  rake (~> 13.0.3)
58
59
  rspec (~> 3.5)
59
- rubocop (~> 1.12.0)
60
+ rubocop (~> 1.43.0)
61
+ simplecov (~> 0.22.0)
60
62
  via_cep!
61
63
 
62
64
  BUNDLED WITH
data/README.md CHANGED
@@ -1,7 +1,12 @@
1
1
  # ViaCep
2
2
 
3
3
  ## Status
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)
4
+
5
+ [![Build Status](https://api.travis-ci.org/marcelobarreto/via_cep.svg?branch=master)](https://travis-ci.org/marcelobarreto/via_cep)
6
+ [![Code Climate](https://codeclimate.com/github/marcelobarreto/via_cep.svg)](https://codeclimate.com/github/marcelobareto/via_cep)
7
+ [![Code Climate](https://codeclimate.com/github/marcelobarreto/via_cep/coverage.svg)](https://codeclimate.com/github/marcelobarreto/via_cep)
8
+ [![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop/rubocop)
9
+ [![RubyGems](http://img.shields.io/gem/dt/via_cep.svg?style=flat)](http://rubygems.org/gems/via_cep)
5
10
 
6
11
 
7
12
  ## Installation
@@ -14,28 +19,29 @@ gem 'via_cep'
14
19
 
15
20
  And then execute:
16
21
 
17
- $ bundle
22
+ ```$ bundle```
18
23
 
19
24
  Or install it yourself as:
20
25
 
21
- $ gem install via_cep
26
+ ```$ gem install via_cep```
22
27
 
23
28
  ## Usage
24
29
 
25
30
  On terminal you can use via_cep like this:
31
+
26
32
  ```ruby
27
- require 'via_cep'
33
+ require 'via_cep'
28
34
 
29
- address = ViaCep::Address.new('01001-000')
30
- address = ViaCep::Address.new(01001000)
35
+ address = ViaCep::Address.new('01001-000')
36
+ address = ViaCep::Address.new(01001000)
31
37
 
32
- address.street # Returns "Praça da Sé"
38
+ address.street # Returns "Praça da Sé"
33
39
  ```
34
40
 
35
41
  You can use from terminal either
36
42
 
37
43
  ```bash
38
- $ zipcode 01001-000 01406000
44
+ $ zipcode 01001-000 01406000
39
45
  ```
40
46
  It will return 2 address with its information
41
47
 
@@ -64,7 +70,7 @@ search.zipcode # => "01001-000"
64
70
 
65
71
  ### Available methods
66
72
 
67
- zipcode, street, complement, neighborhood, city, state, ibge, gia.
73
+ zipcode, street, complement, neighborhood, city, state, ibge, gia.
68
74
 
69
75
  ## Development
70
76
 
@@ -1,10 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ViaCep
4
- # Address class
5
4
  class Address < Instance
6
5
  attr_reader :zipcode
7
6
 
7
+ #
8
+ # Initialize an instance of ViaCep::Address and retrieve the CEP using the ViaCep WS API.
9
+ #
10
+ # Retrieve a zipcode
11
+ # ViaCep::Address.new('01001000')
12
+ # #=> #<ViaCep::Address:0x0000558da60b3770 @zipcode="01001-000",
13
+ # @street="Praca da Se", @complement="lado impar", @neighborhood="Se", @city="Sao Paulo", @state="SP",
14
+ # @ibge="3550308", @gia="1004", @error=nil>
15
+ #
16
+ # Retrieve a zipcode with a formatted string
17
+ # ViaCep::Address.new('01001-000')
18
+ # #=> #<ViaCep::Address:0x000055e5429aef98 @zipcode="01001-000", @street="Praca da Se", @complement="lado impar",
19
+ # @neighborhood="Se", @city="Sao Paulo", @state="SP", @ibge="3550308", @gia="1004", @error=nil>
20
+ #
21
+ # raise [ArgumentError] Error raised when zipcode is nil.
22
+ # raise [ViaCep::Errors::InvalidZipcodeFormat] Errorraised when zipcode format is invalid.
23
+ # raise [ViaCep::Errors::ZipcodeNotFound] Error raised when the external API is down or the CEP does not exist.
24
+ #
25
+ # return [ViaCep::Address]
26
+ #
27
+
8
28
  def initialize(zipcode)
9
29
  @zipcode = zipcode
10
30
  valid?
data/lib/via_cep/http.rb CHANGED
@@ -2,16 +2,24 @@
2
2
 
3
3
  module ViaCep
4
4
  module HTTP
5
+ #
6
+ # Main HTTP module using Net::HTTP
7
+ #
8
+ # return [Net::HTTPOK] | [Net::HTTPBadRequest]
9
+ #
5
10
  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
+ Net::HTTP.get_response(ViaCep::HTTP.uri(path: path, query: query))
11
12
  end
12
13
 
13
14
  def self.was_successful?(request)
14
15
  request.code.eql?('200')
15
16
  end
17
+
18
+ def self.uri(path:, query: {})
19
+ base_uri = URI(BASE_URL)
20
+ base_uri.path = "/ws/#{URI::Parser.new.escape(path)}/json"
21
+ base_uri.query = URI.encode_www_form(query)
22
+ base_uri
23
+ end
16
24
  end
17
25
  end
@@ -2,6 +2,11 @@
2
2
 
3
3
  module ViaCep
4
4
  class Instance
5
+ #
6
+ # Default class to define methods based on the response
7
+ #
8
+ # return [ViaCep::Instance]
9
+ #
5
10
  def define_attributes(response)
6
11
  ViaCep::METHODS.each do |method_name, response_key|
7
12
  value = response[response_key.to_s]
@@ -1,7 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ViaCep
4
- # Translate methods allows us to use metaprogramming.
4
+ #
5
+ # Constant with the params mapped
6
+ #
7
+ # return Hash
8
+ #
5
9
  METHODS = {
6
10
  zipcode: :cep,
7
11
  street: :logradouro,
@@ -11,6 +15,8 @@ module ViaCep
11
15
  state: :uf,
12
16
  ibge: :ibge,
13
17
  gia: :gia,
14
- error: :erro
18
+ error: :erro,
19
+ ddd: :ddd,
20
+ siafi: :siafi
15
21
  }.freeze
16
22
  end
@@ -1,10 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ViaCep
4
- # Search an address
5
4
  class SearchByAddress < Instance
6
5
  attr_reader :state, :city, :street
7
6
 
7
+ #
8
+ # Initialize an instance of ViaCep::SearchByAddress and retrieve the CEP using the ViaCep WS API.
9
+ #
10
+ # Search for a zipcode through the address
11
+ # ViaCep::SearchByAddress.new(state: 'SP', city: 'Sao Paulo', street: 'Praca da Se')
12
+ # #=> #<ViaCep::SearchByAddress:0x000055e542d90210 @state="SP", @city="Sao Paulo", @street="Praca da Se",
13
+ # @zipcode="01001-000", @complement="lado impar", @neighborhood="Se", @ibge="3550308", @gia="1004", @error=nil>
14
+ #
15
+ # raise [ViaCep::Errors::InvalidAddressFormat] Error raised when there is any address field empty.
16
+ # raise [ViaCep::Errors::InvalidStateFormat] Error raised when the state is not a valid one
17
+ #
18
+ # return [ViaCep::SearchByAddress]
19
+ #
20
+
8
21
  def initialize(state:, city:, street:)
9
22
  @state = state
10
23
  @city = city
@@ -19,8 +32,8 @@ module ViaCep
19
32
  private
20
33
 
21
34
  def valid?
35
+ raise ViaCep::Errors::InvalidAddressFormat unless state && city && street
22
36
  raise ViaCep::Errors::InvalidStateFormat unless ViaCep::Validators::State.valid?(state)
23
- raise ViaCep::Errors::InvalidAddressFormat unless city || state
24
37
  end
25
38
 
26
39
  def call_service
@@ -2,9 +2,19 @@
2
2
 
3
3
  module ViaCep
4
4
  module Validators
5
- # State validator
6
5
  module State
7
6
  class << self
7
+ #
8
+ # Validates if the state passed is a valid one.
9
+ #
10
+ # Return if is valid or not
11
+ # ViaCep::Validators::State.valid?('foo')
12
+ # #=> false
13
+ # ViaCep::Validators::State.valid?('RJ')
14
+ # #=> true
15
+ #
16
+ # return Boolean
17
+ #
8
18
  def valid?(state)
9
19
  %w[
10
20
  AC AL AP AM BA CE DF ES GO
@@ -18,6 +28,17 @@ module ViaCep
18
28
  # Zipcode validator
19
29
  module Zipcode
20
30
  class << self
31
+ #
32
+ # Validates if the zipcode passed is a valid one.
33
+ #
34
+ # Return if is valid or not
35
+ # ViaCep::Validators::Zipcode.valid?('0')
36
+ # #=> false
37
+ # ViaCep::Validators::Zipcode.valid?('01001000')
38
+ # #=> true
39
+ #
40
+ # return Boolean
41
+ #
21
42
  def valid?(zipcode)
22
43
  zipcode = zipcode.to_s
23
44
  !!zipcode.match(/^[0-9]{5}(-)[0-9]{3}$/) || !!zipcode.match(/^[0-9]{8}$/)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ViaCep
4
- VERSION = '3.1.3'
4
+ VERSION = '3.1.4'
5
5
  end
data/via_cep.gemspec CHANGED
@@ -22,8 +22,8 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = ['zipcode']
23
23
  spec.require_paths = ['lib']
24
24
 
25
- spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.6'
26
25
  spec.add_development_dependency 'rake', '~> 13.0.3'
27
26
  spec.add_development_dependency 'rspec', '~> 3.5'
28
- spec.add_development_dependency 'rubocop', '~> 1.12.0'
27
+ spec.add_development_dependency 'rubocop', '~> 1.43.0'
28
+ spec.add_development_dependency 'simplecov', '~> 0.22.0'
29
29
  end
metadata CHANGED
@@ -1,72 +1,72 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: via_cep
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.3
4
+ version: 3.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcelo Barreto (@marcelobarreto)
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-03 00:00:00.000000000 Z
11
+ date: 2024-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: codeclimate-test-reporter
14
+ name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.6'
19
+ version: 13.0.3
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: '0.6'
26
+ version: 13.0.3
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 13.0.3
33
+ version: '3.5'
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: 13.0.3
40
+ version: '3.5'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
42
+ name: rubocop
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.5'
47
+ version: 1.43.0
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.5'
54
+ version: 1.43.0
55
55
  - !ruby/object:Gem::Dependency
56
- name: rubocop
56
+ name: simplecov
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 1.12.0
61
+ version: 0.22.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: 1.12.0
69
- description:
68
+ version: 0.22.0
69
+ description:
70
70
  email:
71
71
  - marcelobarretojunior@gmail.com
72
72
  executables:
@@ -75,6 +75,8 @@ extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
77
  - ".codeclimate.yml"
78
+ - ".github/dependabot.yml"
79
+ - ".github/pull_request_template.md"
78
80
  - ".gitignore"
79
81
  - ".rspec"
80
82
  - ".rubocop.yml"
@@ -82,6 +84,7 @@ files:
82
84
  - ".ruby-version"
83
85
  - ".travis.yml"
84
86
  - CODE_OF_CONDUCT.md
87
+ - FUNDING.yml
85
88
  - Gemfile
86
89
  - Gemfile.lock
87
90
  - LICENSE.txt
@@ -104,7 +107,7 @@ homepage: http://www.github.com/marcelobarreto/via_cep
104
107
  licenses:
105
108
  - MIT
106
109
  metadata: {}
107
- post_install_message:
110
+ post_install_message:
108
111
  rdoc_options: []
109
112
  require_paths:
110
113
  - lib
@@ -119,8 +122,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
122
  - !ruby/object:Gem::Version
120
123
  version: '0'
121
124
  requirements: []
122
- rubygems_version: 3.0.9
123
- signing_key:
125
+ rubygems_version: 3.4.6
126
+ signing_key:
124
127
  specification_version: 4
125
128
  summary: Brazillian zip-code information
126
129
  test_files: []