oyi 0.1.0 → 0.1.1
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/Gemfile.lock +1 -1
- data/lib/oyi/client.rb +10 -10
- data/lib/oyi/errors.rb +7 -3
- data/lib/oyi/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: 9e18f073318951ff7e8d4c3125d50e0541edb06326a0a3f73fd69ff62222d4d5
|
4
|
+
data.tar.gz: 685b78c33caedd82af3b610375d2b6aa1bf544a574b96643c47b091fe62c4078
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac0e3b6b561bb3e2cca1cd2728f267cf7c9167a195c2bb684b3560614b4da88e6ff7a7c6ad51014ff7d56fe4f42d35ee6ea1b80dfb62ee02110bd44d1708d2d4
|
7
|
+
data.tar.gz: b792b269f921603510564e5baf622eb3adaedef9076a1dda279f77168a8392d1a10287d74f48f67ba2b785fefb1bf6ff6792af5764691d3baf57674deeef3a0b
|
data/Gemfile.lock
CHANGED
data/lib/oyi/client.rb
CHANGED
@@ -25,33 +25,33 @@ module Oyi
|
|
25
25
|
'X-OY-Username': @api_username,
|
26
26
|
'X-Api-Key': @api_key
|
27
27
|
}
|
28
|
-
@
|
28
|
+
@status = response.code
|
29
29
|
@message = begin
|
30
30
|
JSON.parse(response.body)
|
31
31
|
rescue JSON::ParserError
|
32
32
|
response.body
|
33
33
|
end
|
34
34
|
rescue RestClient::RequestFailed => e
|
35
|
-
@
|
35
|
+
@status = e.http_code
|
36
36
|
@message = e.message
|
37
37
|
end
|
38
|
-
|
39
|
-
if @
|
40
|
-
raise ApiError.new(message: @message['message']) if
|
38
|
+
custom_status = @message['status']
|
39
|
+
if @status == HTTP_OK_CODE
|
40
|
+
raise ApiError.new(message: @message['message']) if custom_status == false
|
41
41
|
|
42
|
-
custom_error_code =
|
42
|
+
custom_error_code = custom_status.is_a?(Hash) && custom_status['code']
|
43
43
|
if custom_error_code && !VALID_CODES.include?(custom_error_code)
|
44
|
-
raise ApiError.new(
|
44
|
+
raise ApiError.new(status: custom_error_code, message: @message['status']&.[]('message'))
|
45
45
|
end
|
46
46
|
|
47
47
|
return @message
|
48
48
|
end
|
49
49
|
|
50
|
-
raise error_class(@
|
50
|
+
raise error_class(@status).new(status: @status, message: @message)
|
51
51
|
end
|
52
52
|
|
53
|
-
def error_class(
|
54
|
-
case
|
53
|
+
def error_class(status)
|
54
|
+
case status
|
55
55
|
when HTTP_BAD_REQUEST_CODE
|
56
56
|
BadRequestError
|
57
57
|
when HTTP_UNAUTHORIZED_CODE
|
data/lib/oyi/errors.rb
CHANGED
@@ -3,12 +3,16 @@
|
|
3
3
|
module Oyi
|
4
4
|
# Custom Error Classes
|
5
5
|
class Error < StandardError
|
6
|
-
attr_accessor :
|
6
|
+
attr_accessor :status, :message
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
@
|
8
|
+
def initialize(status: nil, message:)
|
9
|
+
@status = status
|
10
10
|
@message = message
|
11
11
|
end
|
12
|
+
|
13
|
+
def type
|
14
|
+
self.class.name
|
15
|
+
end
|
12
16
|
end
|
13
17
|
|
14
18
|
BadRequestError = Class.new(Error)
|
data/lib/oyi/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oyi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ganesh Gunasegaran
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-12-
|
11
|
+
date: 2020-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|