synsbasen_api 1.0.13 → 1.0.14
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/synsbasen_api/client.rb +30 -22
- data/lib/synsbasen_api/error.rb +7 -0
- data/lib/synsbasen_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b3e082cca5c5eee71faf49856116fc9ec29c3413b3fe796804651f0647756686
|
|
4
|
+
data.tar.gz: a8a10e871246d73f00f901fcb1d98479391fb6a7d0a4ac802372a0a85e759c79
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a9194013eef9bffb68530e20495abdb22636f7114ab7b5ed47a72f27e36310b02dffb89c3034a33456966e436a451214a4f2201aaf077b5d302eee7718a9e557
|
|
7
|
+
data.tar.gz: 50f4f3e3c61636f9d3b51bb033c2199f946297db594980a7c29e3917509261dfef30eabb316a9d447453800395848d6358505afee5c36e4a7e1087f4acf3c8f0
|
data/lib/synsbasen_api/client.rb
CHANGED
|
@@ -22,7 +22,7 @@ module SynsbasenApi
|
|
|
22
22
|
def get(path, params: {}, expand: [])
|
|
23
23
|
request = build_request(path, method: Net::HTTP::Get, params: params, expand: expand)
|
|
24
24
|
|
|
25
|
-
response =
|
|
25
|
+
response = perform_request(request)
|
|
26
26
|
|
|
27
27
|
raise_errors(response)
|
|
28
28
|
|
|
@@ -42,7 +42,7 @@ module SynsbasenApi
|
|
|
42
42
|
def post(path, params: {}, body: {}, expand: [])
|
|
43
43
|
request = build_request(path, method: Net::HTTP::Post, params: params, body: body, expand: expand)
|
|
44
44
|
|
|
45
|
-
response =
|
|
45
|
+
response = perform_request(request)
|
|
46
46
|
|
|
47
47
|
raise_errors(response)
|
|
48
48
|
|
|
@@ -61,7 +61,7 @@ module SynsbasenApi
|
|
|
61
61
|
def delete(path, params = {}, body = {})
|
|
62
62
|
request = build_request(path, method: Net::HTTP::Delete, params: params, body: body)
|
|
63
63
|
|
|
64
|
-
response =
|
|
64
|
+
response = perform_request(request)
|
|
65
65
|
|
|
66
66
|
raise_errors(response)
|
|
67
67
|
|
|
@@ -106,29 +106,37 @@ module SynsbasenApi
|
|
|
106
106
|
request
|
|
107
107
|
end
|
|
108
108
|
|
|
109
|
+
# Sends a request and translates transport-level timeouts into a public gem error.
|
|
110
|
+
#
|
|
111
|
+
# @param request [Net::HTTPRequest] The request to send.
|
|
112
|
+
# @return [Net::HTTPResponse] The response returned by the API.
|
|
113
|
+
# @raise [RequestTimeoutError] Raised when the request times out before a response is received.
|
|
114
|
+
def perform_request(request)
|
|
115
|
+
connection.request(request)
|
|
116
|
+
rescue Net::OpenTimeout, Net::ReadTimeout, Net::WriteTimeout => e
|
|
117
|
+
raise RequestTimeoutError.new(e.message)
|
|
118
|
+
end
|
|
119
|
+
|
|
109
120
|
# Raises specific errors based on the type of Net::HTTP error encountered.
|
|
110
121
|
#
|
|
111
|
-
# @param
|
|
112
|
-
# @raise [ClientError, ServerError, BadRequestError, UnauthorizedError, ForbiddenError, NotFoundError, ConflictError, UnprocessableEntityError, InternalServerError] Raised for errors.
|
|
122
|
+
# @param response [Net::HTTPResponse] The response to handle.
|
|
123
|
+
# @raise [ClientError, ServerError, BadRequestError, UnauthorizedError, ForbiddenError, NotFoundError, ConflictError, UnprocessableEntityError, RequestTimeoutError, GatewayTimeoutError, InternalServerError] Raised for errors.
|
|
113
124
|
def raise_errors(response)
|
|
114
125
|
return unless response.is_a?(Net::HTTPClientError) || response.is_a?(Net::HTTPServerError)
|
|
115
126
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
raise error_class.new(response.message, response.code, parse_json(response.body))
|
|
131
|
-
end
|
|
127
|
+
error_class = {
|
|
128
|
+
"400" => BadRequestError,
|
|
129
|
+
"401" => UnauthorizedError,
|
|
130
|
+
"403" => ForbiddenError,
|
|
131
|
+
"404" => NotFoundError,
|
|
132
|
+
"408" => RequestTimeoutError,
|
|
133
|
+
"409" => ConflictError,
|
|
134
|
+
"422" => UnprocessableEntityError,
|
|
135
|
+
"500" => InternalServerError,
|
|
136
|
+
"504" => GatewayTimeoutError
|
|
137
|
+
}[response.code] || (response.is_a?(Net::HTTPClientError) ? ClientError : ServerError)
|
|
138
|
+
|
|
139
|
+
raise error_class.new(response.message, response.code, parse_json(response.body))
|
|
132
140
|
end
|
|
133
141
|
|
|
134
142
|
# Calls the after_request callback if configured in the SynsbasenApi.
|
|
@@ -146,7 +154,7 @@ module SynsbasenApi
|
|
|
146
154
|
# @param data [String] The JSON string to parse.
|
|
147
155
|
# @return [Hash] The parsed JSON string as a hash with symbolized keys.
|
|
148
156
|
def parse_json(data)
|
|
149
|
-
data
|
|
157
|
+
return {} if data.nil? || data.empty?
|
|
150
158
|
|
|
151
159
|
deep_symbolize_keys(JSON.parse(data))
|
|
152
160
|
end
|
data/lib/synsbasen_api/error.rb
CHANGED
|
@@ -30,6 +30,13 @@ module SynsbasenApi
|
|
|
30
30
|
# The `ServerError` class represents errors that occur on the server side (5xx status codes).
|
|
31
31
|
class ServerError < Error; end
|
|
32
32
|
|
|
33
|
+
# The `RequestTimeoutError` class represents requests that did not complete within the
|
|
34
|
+
# configured timeout, including HTTP 408 responses and transport-level timeouts.
|
|
35
|
+
class RequestTimeoutError < Error; end
|
|
36
|
+
|
|
37
|
+
# The `GatewayTimeoutError` class represents an HTTP 504 response from the API.
|
|
38
|
+
class GatewayTimeoutError < RequestTimeoutError; end
|
|
39
|
+
|
|
33
40
|
%w[BadRequestError UnauthorizedError ForbiddenError NotFoundError
|
|
34
41
|
ConflictError UnprocessableEntityError].each do |error|
|
|
35
42
|
klass = Class.new(ClientError)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: synsbasen_api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.14
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jimmy Poulsen
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2026-08-03 00:00:00.000000000 Z
|
|
13
13
|
dependencies: []
|
|
14
14
|
description: Synsbasen API is the easiest way to get access to the Danish vehicle
|
|
15
15
|
registry. See https://api.synsbasen.dk for details.
|