traveltime-api 1.4.1 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/traveltime_api.rb +13 -11
- metadata +2 -2
data/lib/traveltime_api.rb
CHANGED
@@ -31,32 +31,30 @@ class TravelTimeAPI
|
|
31
31
|
|
32
32
|
# Raised if API user made bad request.
|
33
33
|
class BadRequest < RuntimeError
|
34
|
-
# Server provided String code for this error.
|
35
|
-
attr_reader :code
|
36
34
|
# Server provided String explanation of error.
|
37
35
|
attr_reader :details
|
38
36
|
|
39
|
-
def initialize(
|
40
|
-
@code = code
|
37
|
+
def initialize(details)
|
41
38
|
@details = details
|
42
39
|
end
|
43
40
|
|
44
41
|
def to_s
|
45
|
-
"TravelTimeAPI::BadRequest[#{
|
42
|
+
"TravelTimeAPI::BadRequest[#{details}]"
|
46
43
|
end
|
47
44
|
end
|
48
45
|
|
49
46
|
# Raised if API server has encountered an error.
|
50
47
|
class ServerError < RuntimeError
|
51
48
|
# Human readable error message.
|
52
|
-
attr_reader :error
|
49
|
+
attr_reader :error, :http_code
|
53
50
|
|
54
|
-
def initialize(error)
|
51
|
+
def initialize(error, http_code)
|
55
52
|
@error = error
|
53
|
+
@http_code = http_code
|
56
54
|
end
|
57
55
|
|
58
56
|
def to_s
|
59
|
-
"TravelTimeAPI::ServerError[#{@error}]"
|
57
|
+
"TravelTimeAPI::ServerError[http code: #{@http_code} | #{@error}]"
|
60
58
|
end
|
61
59
|
end
|
62
60
|
|
@@ -235,9 +233,13 @@ private
|
|
235
233
|
)
|
236
234
|
JSON.parse(response)
|
237
235
|
rescue RestClient::ExceptionWithResponse => e
|
238
|
-
|
239
|
-
|
240
|
-
|
236
|
+
if e.http_code == 400
|
237
|
+
raise BadRequest.new(e.http_body)
|
238
|
+
else
|
239
|
+
raise ServerError.new(
|
240
|
+
e.http_code, "server error, http_body: #{e.http_body}"
|
241
|
+
)
|
242
|
+
end
|
241
243
|
rescue JSON::ParserError => e
|
242
244
|
raise ServerError.new("Cannot parse server response as JSON: #{response}")
|
243
245
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: traveltime-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2014-03-31 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rest-client
|