postal_codes_ruby_client 0.1.4 → 0.1.5
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 +4 -4
- data/lib/postal_codes_ruby_client/client.rb +10 -12
- data/lib/postal_codes_ruby_client/configuration.rb +1 -1
- data/lib/postal_codes_ruby_client/resources/postal_codes.rb +2 -2
- data/lib/postal_codes_ruby_client/version.rb +1 -1
- data/lib/postal_codes_ruby_client.rb +5 -5
- metadata +15 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d654929fa98f22676a1eb822b8cc74c709b980275043467399548ca1cdc10eda
|
|
4
|
+
data.tar.gz: 856da79b975fe3b443ef35de70387d6b80140d99f643d8b08a28430a841ec2f7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 58c0e4f02f1e0ca59ae8c3ffa995d3950135fdcb8e365a26ef3032401d8bda50de136ebe83c6db643c5a20df5ee7a74259946d52e3c64db76bfd606881e75874
|
|
7
|
+
data.tar.gz: a757c3d0e9a2bc3ab175f9864136499e1d01f5bb6c79c091a1ea0a247a7343114ac81ef0dc435d94604c59555ccda322baa15f139925efc10c03b9f806b081e1
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
5
|
-
require
|
|
3
|
+
require 'net/http'
|
|
4
|
+
require 'uri'
|
|
5
|
+
require 'json'
|
|
6
6
|
|
|
7
7
|
module PostalCodesRubyClient
|
|
8
8
|
class Client
|
|
@@ -17,9 +17,7 @@ module PostalCodesRubyClient
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
# Update the API token (e.g. after login or token regeneration).
|
|
20
|
-
|
|
21
|
-
@api_token = token
|
|
22
|
-
end
|
|
20
|
+
attr_writer :api_token
|
|
23
21
|
|
|
24
22
|
# Perform a GET request.
|
|
25
23
|
def get(path, params = {})
|
|
@@ -34,7 +32,7 @@ module PostalCodesRubyClient
|
|
|
34
32
|
request = Net::HTTP::Post.new(uri)
|
|
35
33
|
if body
|
|
36
34
|
request.body = JSON.generate(body)
|
|
37
|
-
request[
|
|
35
|
+
request['Content-Type'] = 'application/json'
|
|
38
36
|
end
|
|
39
37
|
execute(uri, request)
|
|
40
38
|
end
|
|
@@ -48,11 +46,11 @@ module PostalCodesRubyClient
|
|
|
48
46
|
end
|
|
49
47
|
|
|
50
48
|
def execute(uri, request)
|
|
51
|
-
request[
|
|
52
|
-
request[
|
|
49
|
+
request['Authorization'] = "Bearer #{@api_token}" if @api_token
|
|
50
|
+
request['Accept'] = 'application/json'
|
|
53
51
|
|
|
54
52
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
55
|
-
http.use_ssl = uri.scheme ==
|
|
53
|
+
http.use_ssl = uri.scheme == 'https'
|
|
56
54
|
http.open_timeout = @timeout
|
|
57
55
|
http.read_timeout = @timeout
|
|
58
56
|
|
|
@@ -67,10 +65,10 @@ module PostalCodesRubyClient
|
|
|
67
65
|
when 200, 201
|
|
68
66
|
body
|
|
69
67
|
when 401
|
|
70
|
-
raise AuthenticationError, body&.dig(:error) ||
|
|
68
|
+
raise AuthenticationError, body&.dig(:error) || 'Unauthorized'
|
|
71
69
|
when 422
|
|
72
70
|
raise ValidationError.new(
|
|
73
|
-
body&.dig(:error) ||
|
|
71
|
+
body&.dig(:error) || 'Validation failed',
|
|
74
72
|
errors: body&.dig(:errors) || []
|
|
75
73
|
)
|
|
76
74
|
else
|
|
@@ -17,14 +17,14 @@ module PostalCodesRubyClient
|
|
|
17
17
|
params = { q: q }
|
|
18
18
|
params[:country] = country if country
|
|
19
19
|
params[:limit] = limit if limit
|
|
20
|
-
@client.get(
|
|
20
|
+
@client.get('/api/v1/postal_codes', params)
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
# List all available country codes.
|
|
24
24
|
#
|
|
25
25
|
# @return [Hash] { countries: ["AT", "CH", "DE", ...] }
|
|
26
26
|
def countries
|
|
27
|
-
@client.get(
|
|
27
|
+
@client.get('/api/v1/postal_codes/countries')
|
|
28
28
|
end
|
|
29
29
|
end
|
|
30
30
|
end
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative
|
|
4
|
-
require_relative
|
|
5
|
-
require_relative
|
|
6
|
-
require_relative
|
|
7
|
-
require_relative
|
|
3
|
+
require_relative 'postal_codes_ruby_client/version'
|
|
4
|
+
require_relative 'postal_codes_ruby_client/configuration'
|
|
5
|
+
require_relative 'postal_codes_ruby_client/errors'
|
|
6
|
+
require_relative 'postal_codes_ruby_client/resources/postal_codes'
|
|
7
|
+
require_relative 'postal_codes_ruby_client/client'
|
|
8
8
|
|
|
9
9
|
module PostalCodesRubyClient
|
|
10
10
|
class << self
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: postal_codes_ruby_client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- zauberware technologies
|
|
@@ -52,6 +52,20 @@ dependencies:
|
|
|
52
52
|
- - "~>"
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '3.0'
|
|
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.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.0'
|
|
55
69
|
- !ruby/object:Gem::Dependency
|
|
56
70
|
name: webmock
|
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|