via_cep 0.2.4 → 0.2.4.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: c8d1daae20313725996e5fd0304ca40f27588cd0
4
- data.tar.gz: 531434accc95eee1beec369b04b07f6ebd84fafe
3
+ metadata.gz: 90b732c4ac01dc31ba7527b70c3b9fae38fa52b2
4
+ data.tar.gz: 96a08bd42aa9172fea057472c08b5d207ffdabd7
5
5
  SHA512:
6
- metadata.gz: 1c9f9e2c3ca871ba2b37ed6734b11994a5f95574bd4d2b48b5bf0813daada4916a6bd4bc48ab0febd49958c1bb39de8427c3933050d8eda59a4f065ceef498c3
7
- data.tar.gz: 22b0cb9e44a9ac8b368b7d672fac8ee4de83a4eca082805eb9d7a836420932404ea8b2030d0c4e00868571179c32ae6bf4e9e5f0c8a322a19957062d7b53d4cd
6
+ metadata.gz: 75192cd19005764d836e21109c9532ffd665d9b820a9a33fb56beac876472703787d3907363b11ed676bd8321432cf7ae5f9f543384f7255d9bed1ba4424e84c
7
+ data.tar.gz: b9bb07c8bdb56ecbc493cecfaaa87e4c446a67888761c0bca84fb02a052c9ffef476e492eed519ff58403583ee2653224fecced106eede9fc7a3b583e766ddf0
data/lib/via_cep.rb CHANGED
@@ -11,6 +11,7 @@ require 'via_cep/validators/zipcode'
11
11
 
12
12
  # Errors
13
13
  require 'via_cep/errors/invalid_zipcode_format'
14
+ require 'via_cep/errors/invalid_state_format'
14
15
  require 'via_cep/errors/zipcode_not_found'
15
16
 
16
17
  # Utils
@@ -0,0 +1,11 @@
1
+ module ViaCep
2
+ module Errors
3
+ class InvalidStateFormat < ArgumentError
4
+ attr_reader :message
5
+
6
+ def initialize
7
+ @message = 'State has an invalid format'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -7,15 +7,19 @@ module ViaCep
7
7
  street = ViaCep::Utils.parameterize(street)
8
8
 
9
9
  if state.size != 2
10
- raise ArgumentError, 'State must have only abbreviations. Eg.: SP'
10
+ raise ViaCep::Errors::InvalidStateFormat
11
11
  end
12
12
 
13
- @response = HTTParty.get("#{base_url}/#{state}/#{city}/#{street}/json").first
13
+ @response = HTTParty.get("#{base_url}/#{state}/#{city}/#{street}/json")
14
+
15
+ if @response.include?('Bad Request')
16
+ raise ViaCep::Errors::ZipcodeNotFound
17
+ end
14
18
  end
15
19
 
16
20
  ViaCep::METHODS.each do |method_name, response_method_name|
17
21
  define_method(method_name) do
18
- @response[response_method_name]
22
+ @response.first[response_method_name]
19
23
  end
20
24
  end
21
25
 
@@ -1,3 +1,3 @@
1
1
  module ViaCep
2
- VERSION = '0.2.4'
2
+ VERSION = '0.2.4.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
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: 0.2.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcelo Barreto
@@ -130,6 +130,7 @@ files:
130
130
  - bin/zipcode
131
131
  - lib/via_cep.rb
132
132
  - lib/via_cep/address.rb
133
+ - lib/via_cep/errors/invalid_state_format.rb
133
134
  - lib/via_cep/errors/invalid_zipcode_format.rb
134
135
  - lib/via_cep/errors/zipcode_not_found.rb
135
136
  - lib/via_cep/methods.rb