tops_connect 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tops_connect/client.rb +29 -7
- data/lib/tops_connect/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4b4ccf4ab5dad5fd3680bff0ea869b7683b3c74
|
4
|
+
data.tar.gz: '0328eed8bce785b4bf4a57f1ca50bb7c3de23727'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efd3af5e304363d9701b9f7d49a63e0857c7abb6d8b36624c5426e575febbeb8a9a4f6fef3a627c4b41cbed3f545b715d107b90d386c761e1a3cf9b86436126e
|
7
|
+
data.tar.gz: e743ec9665adf8f358aabf9e8cd1f78bb61d1564138e2e6d17a4ddd0a4f43885770ec4a360e0067fb12cc2087ccbf6b57b32821a619c54eb303ceec5e9feaeac
|
data/lib/tops_connect/client.rb
CHANGED
@@ -33,24 +33,46 @@ module TopsConnect
|
|
33
33
|
headers: headers.merge('community-api-key' => @community_api_key)
|
34
34
|
)
|
35
35
|
|
36
|
+
raise_exception(response) unless response.code == 200
|
37
|
+
|
38
|
+
response.parsed_response
|
39
|
+
end
|
40
|
+
|
41
|
+
protected
|
42
|
+
|
43
|
+
def raise_exception(response)
|
36
44
|
case response.code
|
37
|
-
when
|
38
|
-
response
|
45
|
+
when 404
|
46
|
+
raise TopsConnect::NotFoundError, response
|
39
47
|
when 400..499
|
40
|
-
raise TopsConnect::
|
48
|
+
raise TopsConnect::ClientError, response
|
41
49
|
when 500..599
|
42
|
-
raise TopsConnect::InternalError, response
|
50
|
+
raise TopsConnect::InternalError, response
|
43
51
|
else
|
44
|
-
|
45
|
-
|
52
|
+
# As far as I'm aware, Tops does not return 100 - 199 or 201 - 399.
|
53
|
+
raise TopsConnect::ApiError, response
|
46
54
|
end
|
47
55
|
end
|
48
56
|
end
|
49
57
|
|
50
58
|
class ApiError < ::RuntimeError
|
59
|
+
def initialize(response)
|
60
|
+
@response = response
|
61
|
+
end
|
62
|
+
|
63
|
+
def to_s
|
64
|
+
'%{code}: %{message} (%{uri})'.format(
|
65
|
+
code: @response.code,
|
66
|
+
message: @response.parsed_response&.dig('Message'),
|
67
|
+
uri: @response.request.last_uri.to_s
|
68
|
+
)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
class ClientError < ApiError
|
51
73
|
end
|
52
74
|
|
53
|
-
class
|
75
|
+
class NotFoundError < ClientError
|
54
76
|
end
|
55
77
|
|
56
78
|
class InternalError < ApiError
|
data/lib/tops_connect/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tops_connect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Hoffman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|