via_cep 1.0.0 → 2.0.0

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
- SHA1:
3
- metadata.gz: 0bfebba5a73a67cffa9d1784375e8cdeb9e68e22
4
- data.tar.gz: 3b037be00bf894557952433a442e16328fbcf953
2
+ SHA256:
3
+ metadata.gz: 2c47f019e683e78ad6436610c51e507dc2311b74d53a42df494e41faefa6b60f
4
+ data.tar.gz: 1f7284f3a988f16686562e712ad0ca7644d83f0dec7369dbc7b5fc6a5067b266
5
5
  SHA512:
6
- metadata.gz: a55d2404351cc6870708a9aee357cd4547a10fe34956a5a16a6a54717fbdc054476566578393d0ff60f83adb1b86a775741bd3d2b2c7fdb3e33309c1fa7b3ffe
7
- data.tar.gz: 216fb6603769db7e3a701b19a6a65bb704dd578100663d01276384416a8dd7f2f1ec5f3cc567fdb67fdc51b0d073f0db29b613d80dac8f88e6f6aac58a793c18
6
+ metadata.gz: c04098b38db1b418ab54111ec725130de3d9c6e63ae55c64f1158ae223b74940e35fc10cd89a13603b55e82900545d0457dad7e5ac9ddb6d462d9da1f3870e7d
7
+ data.tar.gz: f8300ae0079173af606e1a3bd753901ddd0cca10cb73241620e975c69665b3ee9cc6a5008363f9f02205af4593319f36856b042d30ec6c5709957570786d0b79
data/Gemfile CHANGED
@@ -1,5 +1,6 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
+
3
4
  source 'https://rubygems.org'
4
5
 
5
6
  # Specify your gem's dependencies in via_cep.gemspec
data/README.md CHANGED
@@ -1,8 +1,7 @@
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) [![Ebert](https://ebertapp.io/badges/N68FgrgxUFWYFU43eLvEK4qb.svg)](https://ebertapp.io/repos/85)
5
- [![RubyGems](http://img.shields.io/gem/dt/via_cep.svg?style=flat)](http://rubygems.org/gems/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)
6
5
 
7
6
 
8
7
  ## Installation
data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
+
3
4
  require 'bundler/gem_tasks'
4
5
  require 'rspec/core/rake_task'
5
6
 
data/lib/via_cep.rb CHANGED
@@ -1,7 +1,10 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
- require 'httparty'
3
+
4
4
  require 'via_cep/version'
5
+ require 'net/http'
6
+ require 'uri'
7
+ require 'json'
5
8
 
6
9
  # Core
7
10
  require 'via_cep/address'
@@ -20,3 +23,5 @@ require 'via_cep/errors/address_not_found'
20
23
 
21
24
  # Utils
22
25
  require 'via_cep/utils/utils'
26
+
27
+ BASE_URL = 'https://viacep.com.br/ws'.freeze
@@ -1,16 +1,23 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
+
3
4
  require_relative 'methods'
4
5
 
5
6
  module ViaCep
6
7
  # Address class
7
8
  class Address
8
9
  def initialize(zipcode)
9
- @response = HTTParty.get("https://viacep.com.br/ws/#{zipcode}/json/")
10
+ uri = URI("#{BASE_URL}/#{zipcode}/json/")
11
+ request = Net::HTTP.get_response(uri)
10
12
 
11
- raise ViaCep::Errors::ZipcodeNotFound if @response['erro']
12
13
  raise ViaCep::Errors::InvalidZipcodeFormat unless ViaCep::Validators::
13
14
  Zipcode.valid?(zipcode)
15
+
16
+ if request.code === '200'
17
+ @response = JSON.parse(request.body)
18
+
19
+ raise ViaCep::Errors::ZipcodeNotFound if @response['erro']
20
+ end
14
21
  end
15
22
 
16
23
  ViaCep::METHODS.each do |method_name, response_method_name|
@@ -1,5 +1,6 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
+
3
4
  module ViaCep
4
5
  module Errors
5
6
  # This class is responsible to show an error
@@ -1,5 +1,6 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
+
3
4
  module ViaCep
4
5
  module Errors
5
6
  # This class is responsible to show an error
@@ -1,5 +1,6 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
+
3
4
  module ViaCep
4
5
  module Errors
5
6
  # This class is responsible to show an error
@@ -1,5 +1,6 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
+
3
4
  module ViaCep
4
5
  module Errors
5
6
  # This class is responsible to show an error
@@ -1,5 +1,6 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
+
3
4
  module ViaCep
4
5
  # Translate methods allows us to use metaprogramming.
5
6
  METHODS = {
@@ -1,5 +1,6 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
+
3
4
  require_relative 'methods'
4
5
 
5
6
  module ViaCep
@@ -9,11 +10,12 @@ module ViaCep
9
10
  city = ViaCep::Utils.parameterize(city)
10
11
  street = ViaCep::Utils.parameterize(street)
11
12
 
12
- raise ViaCep::Errors::InvalidStateFormat unless ViaCep::Validators::State
13
- .valid?(state)
13
+ raise ViaCep::Errors::InvalidStateFormat unless ViaCep::Validators::State.valid?(state)
14
14
 
15
- @response = HTTParty.get("#{base_url}/#{state}/#{city}/#{street}/json")
15
+ uri = URI("#{BASE_URL}/#{state}/#{city}/#{street}/json")
16
+ request = Net::HTTP.get_response(uri)
16
17
 
18
+ @response = JSON.parse(request.body) if request.code === '200'
17
19
  raise ViaCep::Errors::AddressNotFound if @response.include?('Bad Request')
18
20
  end
19
21
 
@@ -22,11 +24,5 @@ module ViaCep
22
24
  @response.first[response_method_name]
23
25
  end
24
26
  end
25
-
26
- private
27
-
28
- def base_url
29
- 'https://viacep.com.br/ws'
30
- end
31
27
  end
32
28
  end
@@ -1,5 +1,6 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
+
3
4
  require 'active_support/all'
4
5
 
5
6
  module ViaCep
@@ -1,5 +1,6 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
+
3
4
  module ViaCep
4
5
  module Validators
5
6
  # State validator
@@ -10,11 +11,11 @@ module ViaCep
10
11
  end
11
12
 
12
13
  def states
13
- %w(
14
+ %w[
14
15
  AC AL AP AM BA CE DF ES GO
15
16
  MA MT MS MG PR PB PA PE PI
16
17
  RJ RN RS RO RR SC SE SP TO
17
- )
18
+ ]
18
19
  end
19
20
  end
20
21
  end
@@ -1,5 +1,6 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
+
3
4
  module ViaCep
4
5
  module Validators
5
6
  # Zipcode validator
@@ -1,5 +1,6 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
+
3
4
  module ViaCep
4
- VERSION = '1.0.0'.freeze
5
+ VERSION = '2.0.0'.freeze
5
6
  end
data/via_cep.gemspec CHANGED
@@ -1,5 +1,6 @@
1
1
  # coding: utf-8
2
2
  # frozen_string_literal: true
3
+
3
4
  lib = File.expand_path('../lib', __FILE__)
4
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
6
  require 'via_cep/version'
@@ -7,7 +8,7 @@ require 'via_cep/version'
7
8
  Gem::Specification.new do |s|
8
9
  s.name = 'via_cep'
9
10
  s.version = ViaCep::VERSION
10
- s.authors = ['Marcelo Barreto']
11
+ s.authors = ['Marcelo Barreto (@marcelobarreto)']
11
12
  s.email = ['marcelobarretojunior@gmail.com']
12
13
  s.summary = 'Brazillian zip-code information'
13
14
  s.homepage = 'http://www.github.com/marcelobarreto/via_cep'
@@ -21,12 +22,8 @@ Gem::Specification.new do |s|
21
22
  s.executables = ['zipcode']
22
23
  s.require_paths = ['lib']
23
24
 
24
- s.add_development_dependency 'bundler', '~> 1.13'
25
- s.add_development_dependency 'rake', '~> 11.2'
26
25
  s.add_development_dependency 'rspec', '~> 3.5'
27
26
  s.add_development_dependency 'codeclimate-test-reporter', '~> 0.6'
28
27
  s.add_development_dependency 'rubocop', '~> 0.49.0'
29
- s.add_dependency 'httparty', '~> 0.14'
30
28
  s.add_dependency 'activesupport', '~> 5.0'
31
- s.add_dependency 'i18n', '~> 0.7'
32
29
  end
metadata CHANGED
@@ -1,43 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: via_cep
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
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: 2018-05-15 00:00:00.000000000 Z
11
+ date: 2019-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.13'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.13'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '11.2'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '11.2'
41
13
  - !ruby/object:Gem::Dependency
42
14
  name: rspec
43
15
  requirement: !ruby/object:Gem::Requirement
@@ -80,20 +52,6 @@ dependencies:
80
52
  - - "~>"
81
53
  - !ruby/object:Gem::Version
82
54
  version: 0.49.0
83
- - !ruby/object:Gem::Dependency
84
- name: httparty
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '0.14'
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '0.14'
97
55
  - !ruby/object:Gem::Dependency
98
56
  name: activesupport
99
57
  requirement: !ruby/object:Gem::Requirement
@@ -108,20 +66,6 @@ dependencies:
108
66
  - - "~>"
109
67
  - !ruby/object:Gem::Version
110
68
  version: '5.0'
111
- - !ruby/object:Gem::Dependency
112
- name: i18n
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: '0.7'
118
- type: :runtime
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: '0.7'
125
69
  description:
126
70
  email:
127
71
  - marcelobarretojunior@gmail.com
@@ -176,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
120
  version: '0'
177
121
  requirements: []
178
122
  rubyforge_project:
179
- rubygems_version: 2.6.14
123
+ rubygems_version: 2.7.9
180
124
  signing_key:
181
125
  specification_version: 4
182
126
  summary: Brazillian zip-code information