pager_duty-connection 2.1.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: 6ec4e78b2def787e07a82a8dfb19838dcace837e98647e386209af24003f26e9
4
- data.tar.gz: 7d0885571bbf8e088de58ec22a12bff3354935b5c036017c0548babf8422e933
3
+ metadata.gz: 38445eaf7e12ef537c66dca5286ec2e35cc5b76659c1df5d0972c11479f6bb56
4
+ data.tar.gz: bc79b9edd688055b9fb06631cc1573bfc4a148f5994397b39b5ffe617c771e18
5
5
  SHA512:
6
- metadata.gz: e30277c8080331cd8ae89dcf520d7d9df945a5ed5456f4b0acba12a40d43fa9ca038a5860650091762d47a08cd46c1149bbc5f93000d13b68f2fd793490e43c2
7
- data.tar.gz: d47249fc1dab34ed3100177c81d13fc15b83f60201cbad4c9b1516f295da6cb156a723a54afbd753448e1cdfb1e7e2d6ba33c72eeffc53fb72ee9e87ae1e87db
6
+ metadata.gz: 57d66bf01db4ae1de573d108609503e877d77be6d2b9f31cb8d02cf45ba8e61c73154db44ec658191466042ba60932f4bfb17e3a58e63d8c844c380d86beab2f
7
+ data.tar.gz: 6ca00d5ce74e0cd573c052db347f7eddf371d0e80949b526d711747b04e289f61c2bc5f5977dcc85d605aad0972ed0c9d4269c108892ca10b9fc737abe369cb6
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7.5
1
+ 3.2.2
@@ -1,5 +1,5 @@
1
1
  module PagerDuty
2
2
  class Connection
3
- VERSION = "2.1.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
17
20
 
18
- class ApiError < RuntimeError
21
+ class UnauthorizedError < RuntimeError; end
22
+
23
+ class ForbiddenError < RuntimeError; end
24
+
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
 
@@ -154,13 +183,13 @@ module PagerDuty
154
183
  @connection = Faraday.new do |conn|
155
184
  conn.url_prefix = url
156
185
 
157
- token_arg =
158
- case token_type
159
- when :Token then { token: token }
160
- when :Bearer then token
161
- else raise ArgumentError, "invalid token_type: #{token_type.inspect}"
162
- end
163
- conn.authorization(token_type, token_arg)
186
+ case token_type
187
+ when :Token
188
+ conn.request :token_auth, token
189
+ when :Bearer
190
+ conn.request :authorization, 'Bearer', token
191
+ else raise ArgumentError, "invalid token_type: #{token_type.inspect}"
192
+ end
164
193
 
165
194
  conn.use ConvertTimesParametersToISO8601
166
195
 
@@ -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.1.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Nichols
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-13 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
@@ -109,7 +109,7 @@ files:
109
109
  homepage: http://github.com/technicalpickles/pager_duty-connection
110
110
  licenses: []
111
111
  metadata: {}
112
- post_install_message:
112
+ post_install_message:
113
113
  rdoc_options: []
114
114
  require_paths:
115
115
  - lib
@@ -124,8 +124,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
126
  requirements: []
127
- rubygems_version: 3.3.10
128
- signing_key:
127
+ rubygems_version: 3.4.18
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
131
131
  and usable Ruby API wrapper for the PagerDuty REST API