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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 345f5053904bc5be6db1f16a2b862d926c0822ce
4
- data.tar.gz: 05222a7f429dcdfc451f163630058426e3a140b6
3
+ metadata.gz: c4b4ccf4ab5dad5fd3680bff0ea869b7683b3c74
4
+ data.tar.gz: '0328eed8bce785b4bf4a57f1ca50bb7c3de23727'
5
5
  SHA512:
6
- metadata.gz: 1b24a11f52aad027934c00cb69b84c3932660828b5928329763c0f67169ffe939cf194f6ef74e29df8a322ccaafb7cb9d9a98f9f3d9235d2d32d23486b40c616
7
- data.tar.gz: c29194c29660d1d478808527a8bd8bfa5fe7cfb0c41ec4188c8bfe3c48d0f3a5ea529d3e9aeac66dbc3b9d3353b1379fd4a112e499d5d9751901ad3be0619c80
6
+ metadata.gz: efd3af5e304363d9701b9f7d49a63e0857c7abb6d8b36624c5426e575febbeb8a9a4f6fef3a627c4b41cbed3f545b715d107b90d386c761e1a3cf9b86436126e
7
+ data.tar.gz: e743ec9665adf8f358aabf9e8cd1f78bb61d1564138e2e6d17a4ddd0a4f43885770ec4a360e0067fb12cc2087ccbf6b57b32821a619c54eb303ceec5e9feaeac
@@ -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 200
38
- response.parsed_response
45
+ when 404
46
+ raise TopsConnect::NotFoundError, response
39
47
  when 400..499
40
- raise TopsConnect::BadRequest, response.parsed_response['Message']
48
+ raise TopsConnect::ClientError, response
41
49
  when 500..599
42
- raise TopsConnect::InternalError, response.parsed_response['Message']
50
+ raise TopsConnect::InternalError, response
43
51
  else
44
- raise TopsConnect::ApiError,
45
- "#{response.code}: #{response.parsed_response['Message']}"
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 BadRequest < ApiError
75
+ class NotFoundError < ClientError
54
76
  end
55
77
 
56
78
  class InternalError < ApiError
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module TopsConnect
3
- VERSION = '0.4.1'
3
+ VERSION = '0.4.2'
4
4
  end
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.1
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-13 00:00:00.000000000 Z
11
+ date: 2017-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler