pager_duty-connection 2.2.0 → 2.3.0
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/pager_duty/connection/version.rb +1 -1
- data/lib/pager_duty/connection.rb +47 -10
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38445eaf7e12ef537c66dca5286ec2e35cc5b76659c1df5d0972c11479f6bb56
|
4
|
+
data.tar.gz: bc79b9edd688055b9fb06631cc1573bfc4a148f5994397b39b5ffe617c771e18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57d66bf01db4ae1de573d108609503e877d77be6d2b9f31cb8d02cf45ba8e61c73154db44ec658191466042ba60932f4bfb17e3a58e63d8c844c380d86beab2f
|
7
|
+
data.tar.gz: 6ca00d5ce74e0cd573c052db347f7eddf371d0e80949b526d711747b04e289f61c2bc5f5977dcc85d605aad0972ed0c9d4269c108892ca10b9fc737abe369cb6
|
@@ -12,15 +12,39 @@ module PagerDuty
|
|
12
12
|
API_VERSION = 2
|
13
13
|
API_PREFIX = "https://api.pagerduty.com/"
|
14
14
|
|
15
|
-
class FileNotFoundError < RuntimeError
|
16
|
-
|
15
|
+
class FileNotFoundError < RuntimeError; end
|
16
|
+
|
17
|
+
class ApiError < RuntimeError; end
|
18
|
+
|
19
|
+
class RateLimitError < RuntimeError; end
|
20
|
+
|
21
|
+
class UnauthorizedError < RuntimeError; end
|
22
|
+
|
23
|
+
class ForbiddenError < RuntimeError; end
|
17
24
|
|
18
|
-
class
|
25
|
+
class RaiseUnauthorizedOn401 < Faraday::Middleware
|
26
|
+
def call(env)
|
27
|
+
response = @app.call(env)
|
28
|
+
if response.status == 401
|
29
|
+
raise PagerDuty::Connection::UnauthorizedError, response.env[:url].to_s
|
30
|
+
else
|
31
|
+
response
|
32
|
+
end
|
33
|
+
end
|
19
34
|
end
|
20
35
|
|
21
|
-
class
|
36
|
+
class RaiseForbiddenOn403 < Faraday::Middleware
|
37
|
+
def call(env)
|
38
|
+
response = @app.call(env)
|
39
|
+
if response.status == 403
|
40
|
+
raise PagerDuty::Connection::ForbiddenError, response.env[:url].to_s
|
41
|
+
else
|
42
|
+
response
|
43
|
+
end
|
44
|
+
end
|
22
45
|
end
|
23
46
|
|
47
|
+
|
24
48
|
class RaiseFileNotFoundOn404 < Faraday::Middleware
|
25
49
|
def call(env)
|
26
50
|
response = @app.call env
|
@@ -40,10 +64,13 @@ module PagerDuty
|
|
40
64
|
message = "Got HTTP #{response.status}: #{response.reason_phrase}\nFrom #{url}"
|
41
65
|
|
42
66
|
if error = response.body
|
43
|
-
|
44
|
-
|
67
|
+
begin
|
68
|
+
# TODO May Need to check error.errors too
|
69
|
+
message += "\n#{JSON.parse(error)}"
|
70
|
+
rescue JSON::ParserError
|
71
|
+
message += "\n#{error}"
|
72
|
+
end
|
45
73
|
end
|
46
|
-
|
47
74
|
raise ApiError, message
|
48
75
|
else
|
49
76
|
response
|
@@ -67,9 +94,11 @@ module PagerDuty
|
|
67
94
|
def call(env)
|
68
95
|
|
69
96
|
body = env[:body]
|
70
|
-
|
71
|
-
|
72
|
-
|
97
|
+
unless body.nil?
|
98
|
+
TIME_KEYS.each do |key|
|
99
|
+
if body.has_key?(key)
|
100
|
+
body[key] = body[key].iso8601 if body[key].respond_to?(:iso8601)
|
101
|
+
end
|
73
102
|
end
|
74
103
|
end
|
75
104
|
|
@@ -180,12 +209,20 @@ module PagerDuty
|
|
180
209
|
conn.use RaiseApiErrorOnNon200
|
181
210
|
conn.use RaiseFileNotFoundOn404
|
182
211
|
conn.use RaiseRateLimitOn429
|
212
|
+
conn.use RaiseForbiddenOn403
|
213
|
+
conn.use RaiseUnauthorizedOn401
|
183
214
|
|
184
215
|
conn.adapter Faraday.default_adapter
|
185
216
|
end
|
186
217
|
end
|
187
218
|
|
188
219
|
def get(path, request = {})
|
220
|
+
# The run_request() method body argument defaults to {}, which is incorrect for GET requests
|
221
|
+
# https://github.com/technicalpickles/pager_duty-connection/issues/56
|
222
|
+
# NOTE: PagerDuty support discourages GET requests with bodies, but not throwing an ArgumentError to prevent breaking
|
223
|
+
# corner-case implementations.
|
224
|
+
request[:body] = nil if !request[:body]
|
225
|
+
|
189
226
|
# paginate anything being 'get'ed, because the offset/limit isn't intuitive
|
190
227
|
request[:query_params] = {} if !request[:query_params]
|
191
228
|
page = request[:query_params].fetch(:page, 1).to_i
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pager_duty-connection
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Nichols
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
126
|
requirements: []
|
127
|
-
rubygems_version: 3.4.
|
127
|
+
rubygems_version: 3.4.18
|
128
128
|
signing_key:
|
129
129
|
specification_version: 4
|
130
130
|
summary: Written with the power of faraday, pager_duty-connection tries to be a simple
|