pager_duty-connection 3.0.0 → 3.1.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/.github/workflows/standardrb.yaml +13 -0
- data/Gemfile +4 -3
- data/README.md +13 -11
- data/examples/find-users.rb +8 -8
- data/examples/shifts-with-incidents-and-log-entries.rb +15 -15
- data/lib/pager_duty/connection/version.rb +1 -1
- data/lib/pager_duty/connection.rb +22 -25
- data/lib/pager_duty.rb +2 -3
- data/pager_duty-connection.gemspec +12 -14
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62d5837515647a768626a48a20621bf19c937139f0bf10605d4aa945cdd0bb0a
|
4
|
+
data.tar.gz: c25658b8e8b25eeb8b18839490c90e4c28c424f08cbaaa4a8d209775dcb77d98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cd5c6cb6967d8f2936e2063d3f898ca007045eb94c1bebb48da18a8e259a40edcc8a6e23cc1b3487e480742415c5196aa1759573fd74e30c201cfb8398a5c26
|
7
|
+
data.tar.gz: 42b5626e27ac9a4be206aed56d07546a02f252e8632704d9e997969d11ae3358ef0845ef8d7f9b7ccdf277952e06707fca32649b10e2c28c440024a690d280e5
|
data/Gemfile
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
source
|
1
|
+
source "https://rubygems.org"
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in pager_duty-connection.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
6
|
# for tests & running examples
|
7
7
|
group :development do
|
8
|
-
gem
|
9
|
-
gem
|
8
|
+
gem "dotenv"
|
9
|
+
gem "pry"
|
10
|
+
gem "standardrb"
|
10
11
|
end
|
data/README.md
CHANGED
@@ -31,7 +31,9 @@ And this is what it doesn't do:
|
|
31
31
|
|
32
32
|
Add this line to your application's Gemfile:
|
33
33
|
|
34
|
-
|
34
|
+
```ruby
|
35
|
+
gem "pager_duty-connection"
|
36
|
+
```
|
35
37
|
|
36
38
|
And then execute:
|
37
39
|
|
@@ -54,22 +56,22 @@ pagerduty = PagerDuty::Connection.new(token)
|
|
54
56
|
pagerduty = PagerDuty::Connection.new(token, token_type: :Bearer)
|
55
57
|
|
56
58
|
# setup to use a custom domain
|
57
|
-
pagerduty = PagerDuty::Connection.new(token, token_type: :Bearer, url:
|
59
|
+
pagerduty = PagerDuty::Connection.new(token, token_type: :Bearer, url: "https://custom.domain.com")
|
58
60
|
|
59
61
|
# 4 main methods: `get`, `post`, `put`, and `delete`:
|
60
62
|
|
61
|
-
response = pagerduty.get(
|
62
|
-
response = pagerduty.post(
|
63
|
-
response = pagerduty.delete(
|
64
|
-
response = pagerduty.put(
|
63
|
+
response = pagerduty.get("some/relative/path", params)
|
64
|
+
response = pagerduty.post("some/relative/path", params)
|
65
|
+
response = pagerduty.delete("some/relative/path", params)
|
66
|
+
response = pagerduty.put("some/relative/path", params)
|
65
67
|
|
66
68
|
# use something like irb or pry to poke around the responses
|
67
69
|
# the contents will vary a bit between call, ie:
|
68
70
|
|
69
|
-
response = pagerduty.get(
|
71
|
+
response = pagerduty.get("incidents")
|
70
72
|
response.incidents # an array of incidents
|
71
73
|
|
72
|
-
response = pagerduty.get(
|
74
|
+
response = pagerduty.get("incidents/YYZ")
|
73
75
|
response # the hash/object that represents the array
|
74
76
|
```
|
75
77
|
|
@@ -102,14 +104,14 @@ In general, you can get/put/post/delete a path, with some attributes. Use the [R
|
|
102
104
|
If you are working in Rails, and using only a single PagerDuty account, you'll probably want an initializer:
|
103
105
|
|
104
106
|
```ruby
|
105
|
-
$pagerduty = PagerDuty::Connection.new(
|
107
|
+
$pagerduty = PagerDuty::Connection.new("your-token")
|
106
108
|
```
|
107
109
|
|
108
110
|
And if you are using [dotenv](https://github.com/bkeepers/dotenv), you can use environment variables, and stash them in .env:
|
109
111
|
|
110
112
|
```ruby
|
111
|
-
account = ENV[
|
112
|
-
token = ENV[
|
113
|
+
account = ENV["PAGERDUTY_ACCOUNT"] || raise("Missing ENV['PAGERDUTY_ACCOUNT'], add to .env")
|
114
|
+
token = ENV["PAGERDUTY_TOKEN"] || raise("Missing ENV['PAGERDUTY_TOKEN'], add to .env.#{Rails.env}")
|
113
115
|
$pagerduty = PagerDuty::Connection.new(account, token)
|
114
116
|
```
|
115
117
|
|
data/examples/find-users.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
Dotenv.load ".env.development",
|
3
|
+
require "dotenv"
|
4
|
+
Dotenv.load ".env.development", ".env"
|
5
5
|
|
6
|
-
token = ENV[
|
6
|
+
token = ENV["PAGERDUTY_TOKEN"] || raise("Missing ENV['PAGERDUTY_TOKEN'], add to .env.development")
|
7
7
|
|
8
|
-
require
|
9
|
-
|
8
|
+
require "pager_duty/connection"
|
9
|
+
pagerduty = PagerDuty::Connection.new(token)
|
10
10
|
|
11
11
|
# https://v2.developer.pagerduty.com/v2/page/api-reference#!/Users/get_users
|
12
|
-
response =
|
13
|
-
response[
|
14
|
-
puts "#{user[
|
12
|
+
response = pagerduty.get("users")
|
13
|
+
response["users"].each do |user|
|
14
|
+
puts "#{user["name"]}: #{user["email"]}"
|
15
15
|
end
|
@@ -1,46 +1,46 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
Dotenv.load ".env.development",
|
3
|
+
require "dotenv"
|
4
|
+
Dotenv.load ".env.development", ".env"
|
5
5
|
|
6
|
-
token = ENV[
|
6
|
+
token = ENV["PAGERDUTY_TOKEN"] || raise("Missing ENV['PAGERDUTY_TOKEN'], add to .env.development")
|
7
7
|
|
8
|
-
require
|
9
|
-
|
8
|
+
require "pager_duty/connection"
|
9
|
+
pagerduty = PagerDuty::Connection.new(token)
|
10
10
|
|
11
|
-
schedule_id = ENV[
|
11
|
+
schedule_id = ENV["PAGERDUTY_SCHEDULE_ID"] || raise("Missing ENV['PAGERDUTY_SCHEDULE_ID'], add to .env.development")
|
12
12
|
|
13
13
|
# pull down schedule entires for XXX schedule in the last day (ie who has been on call, and when
|
14
14
|
time_since = 1.day.ago
|
15
15
|
time_until = Time.now
|
16
16
|
|
17
17
|
# https://v2.developer.pagerduty.com/v2/page/api-reference#!/On-Calls/get_oncalls
|
18
|
-
response =
|
18
|
+
response = pagerduty.get("oncalls", query_params: {since: time_since, until: time_until, schedule_ids: [schedule_id]})
|
19
19
|
|
20
|
-
entries = response[
|
20
|
+
entries = response["oncalls"]
|
21
21
|
|
22
22
|
entries.each do |entry|
|
23
|
-
puts "#{entry[
|
23
|
+
puts "#{entry["start"]} - #{entry["end"]}: #{entry["user"]["summary"]}"
|
24
24
|
|
25
25
|
# find incidents during that shift
|
26
26
|
# https://v2.developer.pagerduty.com/v2/page/api-reference#!/Incidents/get_incidents
|
27
|
-
response =
|
27
|
+
response = pagerduty.get("incidents", query_params: {since: entry["start"], until: entry["end"], user_ids: [entry["user"]["id"]]})
|
28
28
|
|
29
|
-
response[
|
29
|
+
response["incidents"].each do |incident|
|
30
30
|
puts "\t#{incident.id}"
|
31
31
|
|
32
32
|
# find log entries (acknowledged, notifications, etc) for incident:
|
33
33
|
# https://v2.developer.pagerduty.com/v2/page/api-reference#!/Incidents/get_incidents_id_log_entries
|
34
|
-
response =
|
34
|
+
response = pagerduty.get("incidents/#{incident.id}/log_entries")
|
35
35
|
|
36
36
|
# select just the notes
|
37
|
-
notes = response[
|
38
|
-
log_entry[
|
37
|
+
notes = response["log_entries"].select do |log_entry|
|
38
|
+
log_entry["channel"] && log_entry["channel"]["type"] == "note"
|
39
39
|
end
|
40
40
|
|
41
41
|
# and print them out:
|
42
42
|
notes.each do |log_entry|
|
43
|
-
puts "\t\t#{log_entry[
|
43
|
+
puts "\t\t#{log_entry["channel"]["summary"]}"
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
@@ -1,11 +1,10 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
require "faraday"
|
2
|
+
require "hashie"
|
3
|
+
require "active_support"
|
4
|
+
require "active_support/core_ext"
|
5
|
+
require "active_support/time_with_zone"
|
6
6
|
|
7
7
|
module PagerDuty
|
8
|
-
|
9
8
|
class Connection
|
10
9
|
attr_accessor :connection
|
11
10
|
|
@@ -44,7 +43,6 @@ module PagerDuty
|
|
44
43
|
end
|
45
44
|
end
|
46
45
|
|
47
|
-
|
48
46
|
class RaiseFileNotFoundOn404 < Faraday::Middleware
|
49
47
|
def call(env)
|
50
48
|
response = @app.call env
|
@@ -59,11 +57,13 @@ module PagerDuty
|
|
59
57
|
class RaiseApiErrorOnNon200 < Faraday::Middleware
|
60
58
|
def call(env)
|
61
59
|
response = @app.call env
|
62
|
-
|
60
|
+
if [200, 201, 204].include?(response.status)
|
61
|
+
response
|
62
|
+
else
|
63
63
|
url = response.env[:url].to_s
|
64
64
|
message = "Got HTTP #{response.status}: #{response.reason_phrase}\nFrom #{url}"
|
65
65
|
|
66
|
-
if error = response.body
|
66
|
+
if (error = response.body)
|
67
67
|
begin
|
68
68
|
# TODO May Need to check error.errors too
|
69
69
|
message += "\n#{JSON.parse(error)}"
|
@@ -72,8 +72,6 @@ module PagerDuty
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
raise ApiError, message
|
75
|
-
else
|
76
|
-
response
|
77
75
|
end
|
78
76
|
end
|
79
77
|
end
|
@@ -92,7 +90,6 @@ module PagerDuty
|
|
92
90
|
class ConvertTimesParametersToISO8601 < Faraday::Middleware
|
93
91
|
TIME_KEYS = [:since, :until]
|
94
92
|
def call(env)
|
95
|
-
|
96
93
|
body = env[:body]
|
97
94
|
unless body.nil?
|
98
95
|
TIME_KEYS.each do |key|
|
@@ -107,7 +104,7 @@ module PagerDuty
|
|
107
104
|
end
|
108
105
|
|
109
106
|
class ParseTimeStrings < Faraday::Middleware
|
110
|
-
TIME_KEYS = %w
|
107
|
+
TIME_KEYS = %w[
|
111
108
|
at
|
112
109
|
created_at
|
113
110
|
created_on
|
@@ -118,9 +115,9 @@ module PagerDuty
|
|
118
115
|
start
|
119
116
|
started_at
|
120
117
|
start_time
|
121
|
-
|
118
|
+
]
|
122
119
|
|
123
|
-
OBJECT_KEYS = %w
|
120
|
+
OBJECT_KEYS = %w[
|
124
121
|
alert
|
125
122
|
entry
|
126
123
|
incident
|
@@ -129,13 +126,13 @@ module PagerDuty
|
|
129
126
|
note
|
130
127
|
override
|
131
128
|
service
|
132
|
-
|
129
|
+
]
|
133
130
|
|
134
|
-
NESTED_COLLECTION_KEYS = %w
|
131
|
+
NESTED_COLLECTION_KEYS = %w[
|
135
132
|
acknowledgers
|
136
133
|
assigned_to
|
137
134
|
pending_actions
|
138
|
-
|
135
|
+
]
|
139
136
|
|
140
137
|
def on_complete(env)
|
141
138
|
parse(env[:body])
|
@@ -173,7 +170,7 @@ module PagerDuty
|
|
173
170
|
end
|
174
171
|
|
175
172
|
def parse_object_times(object)
|
176
|
-
time = Time.zone
|
173
|
+
time = Time.zone || Time
|
177
174
|
|
178
175
|
TIME_KEYS.each do |key|
|
179
176
|
if object.has_key?(key) && object[key].present?
|
@@ -209,10 +206,10 @@ module PagerDuty
|
|
209
206
|
if faraday_v1?
|
210
207
|
conn.request :token_auth, token
|
211
208
|
else
|
212
|
-
conn.request :authorization,
|
209
|
+
conn.request :authorization, "Token", token
|
213
210
|
end
|
214
211
|
when :Bearer
|
215
|
-
conn.request :authorization,
|
212
|
+
conn.request :authorization, "Bearer", token
|
216
213
|
else raise ArgumentError, "invalid token_type: #{token_type.inspect}"
|
217
214
|
end
|
218
215
|
|
@@ -226,7 +223,7 @@ module PagerDuty
|
|
226
223
|
conn.use ParseTimeStrings
|
227
224
|
conn.use Mashify
|
228
225
|
conn.response :json
|
229
|
-
conn.response :logger, ::Logger.new(
|
226
|
+
conn.response :logger, ::Logger.new($stdout), bodies: true if debug
|
230
227
|
|
231
228
|
# Because Faraday::Middleware executes in reverse order of
|
232
229
|
# calls to conn.use, status code error handling goes at the
|
@@ -237,7 +234,7 @@ module PagerDuty
|
|
237
234
|
conn.use RaiseForbiddenOn403
|
238
235
|
conn.use RaiseUnauthorizedOn401
|
239
236
|
|
240
|
-
conn.adapter
|
237
|
+
conn.adapter Faraday.default_adapter
|
241
238
|
end
|
242
239
|
end
|
243
240
|
|
@@ -275,7 +272,7 @@ module PagerDuty
|
|
275
272
|
private
|
276
273
|
|
277
274
|
def faraday_v1?
|
278
|
-
faraday_version < Gem::Version.new("2")
|
275
|
+
faraday_version < Gem::Version.new("2")
|
279
276
|
end
|
280
277
|
|
281
278
|
def faraday_version
|
@@ -283,7 +280,7 @@ module PagerDuty
|
|
283
280
|
end
|
284
281
|
|
285
282
|
def run_request(method, path, body: {}, headers: {}, query_params: {})
|
286
|
-
path = path.gsub(/^\//,
|
283
|
+
path = path.gsub(/^\//, "") # strip leading slash, to make sure relative things happen on the connection
|
287
284
|
|
288
285
|
connection.params = query_params
|
289
286
|
response = connection.run_request(method, path, body, headers)
|
data/lib/pager_duty.rb
CHANGED
@@ -1,24 +1,22 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
3
|
+
require "pager_duty/connection/version"
|
5
4
|
|
6
5
|
Gem::Specification.new do |gem|
|
7
|
-
gem.name
|
8
|
-
gem.version
|
9
|
-
gem.authors
|
10
|
-
gem.email
|
11
|
-
gem.description
|
12
|
-
gem.summary
|
13
|
-
gem.homepage
|
6
|
+
gem.name = "pager_duty-connection"
|
7
|
+
gem.version = PagerDuty::Connection::VERSION
|
8
|
+
gem.authors = ["Josh Nichols"]
|
9
|
+
gem.email = ["josh@technicalpickles.com"]
|
10
|
+
gem.description = "Ruby API wrapper for the PagerDuty REST API"
|
11
|
+
gem.summary = "Written with the power of faraday, pager_duty-connection tries to be a simple and usable Ruby API wrapper for the PagerDuty REST API"
|
12
|
+
gem.homepage = "http://github.com/technicalpickles/pager_duty-connection"
|
14
13
|
|
15
|
-
gem.files
|
16
|
-
gem.executables
|
17
|
-
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.files = `git ls-files`.split($/)
|
15
|
+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
18
16
|
gem.require_paths = ["lib"]
|
19
17
|
|
20
18
|
gem.add_dependency "faraday", ">= 1.10", "< 3"
|
21
|
-
gem.add_dependency "activesupport", ">= 3.2", "<
|
19
|
+
gem.add_dependency "activesupport", ">= 3.2", "< 9.0"
|
22
20
|
gem.add_dependency "hashie", ">= 1.2"
|
23
21
|
|
24
22
|
gem.add_development_dependency "rake"
|
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: 3.
|
4
|
+
version: 3.1.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: 2025-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
version: '3.2'
|
40
40
|
- - "<"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '
|
42
|
+
version: '9.0'
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -49,7 +49,7 @@ dependencies:
|
|
49
49
|
version: '3.2'
|
50
50
|
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: '
|
52
|
+
version: '9.0'
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: hashie
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -85,6 +85,7 @@ executables: []
|
|
85
85
|
extensions: []
|
86
86
|
extra_rdoc_files: []
|
87
87
|
files:
|
88
|
+
- ".github/workflows/standardrb.yaml"
|
88
89
|
- ".gitignore"
|
89
90
|
- ".ruby-version"
|
90
91
|
- Gemfile
|
@@ -116,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
117
|
- !ruby/object:Gem::Version
|
117
118
|
version: '0'
|
118
119
|
requirements: []
|
119
|
-
rubygems_version: 3.4.
|
120
|
+
rubygems_version: 3.4.10
|
120
121
|
signing_key:
|
121
122
|
specification_version: 4
|
122
123
|
summary: Written with the power of faraday, pager_duty-connection tries to be a simple
|