pager_duty-connection 2.2.0 → 2.3.0

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
  SHA256:
3
- metadata.gz: bdd585e0292f12142b4deb85820c0bf5f9155f6d7ec607bddf53bceaf131c732
4
- data.tar.gz: 8b2f1784f52e3f4d70e135b2d70eff086de47a87b6e24b0079797211634617e3
3
+ metadata.gz: 38445eaf7e12ef537c66dca5286ec2e35cc5b76659c1df5d0972c11479f6bb56
4
+ data.tar.gz: bc79b9edd688055b9fb06631cc1573bfc4a148f5994397b39b5ffe617c771e18
5
5
  SHA512:
6
- metadata.gz: 857ce1740ca088180a548594f38aa8c4ab0af2bb5b3fe002bda1febd00e6a5c83bc89a01803596d5e518562a19186e0fd6c2f868a30f89827d6b39f7ca1988cf
7
- data.tar.gz: 7e3f96e3ea4d2eb17714eb2deb090316817cce70c3f2c77dd3cbfe306683ae462adf9e3ec34c5ac6a204523638ad005b7626b07751adf2224dc7ce78e5d20bb6
6
+ metadata.gz: 57d66bf01db4ae1de573d108609503e877d77be6d2b9f31cb8d02cf45ba8e61c73154db44ec658191466042ba60932f4bfb17e3a58e63d8c844c380d86beab2f
7
+ data.tar.gz: 6ca00d5ce74e0cd573c052db347f7eddf371d0e80949b526d711747b04e289f61c2bc5f5977dcc85d605aad0972ed0c9d4269c108892ca10b9fc737abe369cb6
@@ -1,5 +1,5 @@
1
1
  module PagerDuty
2
2
  class Connection
3
- VERSION = "2.2.0"
3
+ VERSION = "2.3.0"
4
4
  end
5
5
  end
@@ -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
- end
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 ApiError < RuntimeError
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 RateLimitError < RuntimeError
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
- # TODO May Need to check error.errors too
44
- message += "\n#{JSON.parse(error)}"
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
- TIME_KEYS.each do |key|
71
- if body.has_key?(key)
72
- body[key] = body[key].iso8601 if body[key].respond_to?(:iso8601)
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.2.0
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: 2023-08-10 00:00:00.000000000 Z
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.12
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