monogoto_api 0.3.1 → 0.4.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/lib/monogoto_api/client.rb +30 -3
- data/lib/monogoto_api/errors.rb +28 -0
- data/lib/monogoto_api/version.rb +1 -1
- data/lib/monogoto_api.rb +1 -0
- metadata +5 -10
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 415575db04a1d796416c5f1ff06d61e74a78fa63d5997e0b60237bc616abcd10
|
|
4
|
+
data.tar.gz: 7ad358ca896c2221aaa870b4ffa915a47cd22e91fc84e4fc2537d7e6219d83e1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1685aa5d8f77ab2076b01401da12d599ee0ad2d561cd1ed84047f761e09f1f63ae9a2583f2ec909377d2cf1568515972fdedb86bd6f170fac626a059c1fa3948
|
|
7
|
+
data.tar.gz: ae16006cdea9a72e2b99f93f67468edabcfb82974d0157024f4c86f15765bbc6ce6875ea58a6f1f0f4f0c3bfdd45108bd45779d3660f5b0e4b03ab6105341274
|
data/lib/monogoto_api/client.rb
CHANGED
|
@@ -10,7 +10,7 @@ module MonogotoApi
|
|
|
10
10
|
|
|
11
11
|
def initialize(user, password)
|
|
12
12
|
auth = { "UserName" => user, "Password" => password }
|
|
13
|
-
jwt_response =
|
|
13
|
+
jwt_response = post(
|
|
14
14
|
"/Auth",
|
|
15
15
|
body: auth.to_json, headers: { "Content-Type" => "application/json" }
|
|
16
16
|
)
|
|
@@ -75,11 +75,38 @@ module MonogotoApi
|
|
|
75
75
|
end
|
|
76
76
|
|
|
77
77
|
def get(path, headers: {})
|
|
78
|
-
self.class.get(path, headers:)
|
|
78
|
+
request { self.class.get(path, headers:) }
|
|
79
79
|
end
|
|
80
80
|
|
|
81
81
|
def post(path, body: {}, headers: {})
|
|
82
|
-
self.class.post(path, body:, headers:)
|
|
82
|
+
request { self.class.post(path, body:, headers:) }
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def request
|
|
86
|
+
response = begin
|
|
87
|
+
yield
|
|
88
|
+
rescue SocketError, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET,
|
|
89
|
+
Errno::ECONNREFUSED, Errno::ENETUNREACH, Net::ProtocolError,
|
|
90
|
+
OpenSSL::SSL::SSLError => e
|
|
91
|
+
raise MonogotoApi::ConnectionError, "Network connection failed: #{e.message}"
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
handle_response(response)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def handle_response(response)
|
|
98
|
+
return response if response.success?
|
|
99
|
+
|
|
100
|
+
case response.code
|
|
101
|
+
when 401, 403
|
|
102
|
+
raise MonogotoApi::UnauthorizedError, response
|
|
103
|
+
when 404
|
|
104
|
+
raise MonogotoApi::NotFoundError, response
|
|
105
|
+
when 500..599
|
|
106
|
+
raise MonogotoApi::ServerError, response
|
|
107
|
+
else
|
|
108
|
+
raise MonogotoApi::HTTPError, response
|
|
109
|
+
end
|
|
83
110
|
end
|
|
84
111
|
end
|
|
85
112
|
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module MonogotoApi
|
|
4
|
+
# Base error class for Monogoto API library
|
|
5
|
+
class Error < StandardError; end
|
|
6
|
+
|
|
7
|
+
# Raised when a network or timeout connection error occurs
|
|
8
|
+
class ConnectionError < Error; end
|
|
9
|
+
|
|
10
|
+
# Base class for HTTP errors (non-2xx responses)
|
|
11
|
+
class HTTPError < Error
|
|
12
|
+
attr_reader :response
|
|
13
|
+
|
|
14
|
+
def initialize(response)
|
|
15
|
+
@response = response
|
|
16
|
+
super("HTTP Request failed with status #{response.code}: #{response.body}")
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Raised on 401 or 403 responses
|
|
21
|
+
class UnauthorizedError < HTTPError; end
|
|
22
|
+
|
|
23
|
+
# Raised on 404 responses
|
|
24
|
+
class NotFoundError < HTTPError; end
|
|
25
|
+
|
|
26
|
+
# Raised on 5xx server responses
|
|
27
|
+
class ServerError < HTTPError; end
|
|
28
|
+
end
|
data/lib/monogoto_api/version.rb
CHANGED
data/lib/monogoto_api.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: monogoto_api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Javier Contreras Ferrada
|
|
@@ -43,20 +43,14 @@ dependencies:
|
|
|
43
43
|
requirements:
|
|
44
44
|
- - "~>"
|
|
45
45
|
- !ruby/object:Gem::Version
|
|
46
|
-
version: '0.
|
|
47
|
-
- - ">="
|
|
48
|
-
- !ruby/object:Gem::Version
|
|
49
|
-
version: 0.21.0
|
|
46
|
+
version: '0.24'
|
|
50
47
|
type: :runtime
|
|
51
48
|
prerelease: false
|
|
52
49
|
version_requirements: !ruby/object:Gem::Requirement
|
|
53
50
|
requirements:
|
|
54
51
|
- - "~>"
|
|
55
52
|
- !ruby/object:Gem::Version
|
|
56
|
-
version: '0.
|
|
57
|
-
- - ">="
|
|
58
|
-
- !ruby/object:Gem::Version
|
|
59
|
-
version: 0.21.0
|
|
53
|
+
version: '0.24'
|
|
60
54
|
- !ruby/object:Gem::Dependency
|
|
61
55
|
name: base64
|
|
62
56
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -96,6 +90,7 @@ files:
|
|
|
96
90
|
- LICENSE
|
|
97
91
|
- lib/monogoto_api.rb
|
|
98
92
|
- lib/monogoto_api/client.rb
|
|
93
|
+
- lib/monogoto_api/errors.rb
|
|
99
94
|
- lib/monogoto_api/event.rb
|
|
100
95
|
- lib/monogoto_api/event/list.rb
|
|
101
96
|
- lib/monogoto_api/ip.rb
|
|
@@ -123,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
123
118
|
- !ruby/object:Gem::Version
|
|
124
119
|
version: '0'
|
|
125
120
|
requirements: []
|
|
126
|
-
rubygems_version: 3.
|
|
121
|
+
rubygems_version: 3.7.2
|
|
127
122
|
specification_version: 4
|
|
128
123
|
summary: Unofficial Ruby gem for Monogoto API
|
|
129
124
|
test_files: []
|