Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1275f51
Use updated Farady syntax
markedmondson Dec 21, 2022
714e324
Merge pull request #53 from markedmondson/faraday-deprecation
technicalpickles Aug 10, 2023
f8f51e2
update .ruby-version
technicalpickles Aug 10, 2023
7a12d16
bump to 2.2.0
technicalpickles Aug 10, 2023
ff7bc16
Merge pull request #54 from technicalpickles/version-2.2.0
technicalpickles Aug 10, 2023
51490a9
Add support for Unauthorized and Forbidden response codes, and handle…
Nov 24, 2023
5f13b0b
Set HTTP GET body to nil, resolves #56
ag-TJNII Jan 16, 2024
9ffb147
Merge pull request #55 from DougEdey/de/unauth
technicalpickles Jan 16, 2024
020df00
Bump to 2.3.0
technicalpickles Jan 16, 2024
8b2b3ab
Merge pull request #57 from ag-TJNII/TJNII-Get-Body
technicalpickles Jan 16, 2024
e9b3747
Merge pull request #58 from technicalpickles/version-2.3.0
technicalpickles Jan 16, 2024
b782304
filter custom page query param from outgoing PD requests
mattbnz Apr 19, 2024
ebc36fb
Adds faraday 2 support
jasondoc3 Apr 27, 2024
da44d33
Merge pull request #59 from mkmba-nz/filter-page-param
technicalpickles Apr 29, 2024
7c576e1
Merge pull request #60 from jasondoc3/support-faraday-2
technicalpickles Apr 29, 2024
981ba4a
Version bump to 3.0.0
technicalpickles Apr 29, 2024
9c7d47f
Merge pull request #61 from technicalpickles/version-3.0.0
technicalpickles Apr 29, 2024
1c01ddc
Use standardrb on everything
technicalpickles Apr 29, 2024
2d8a451
Add github action
technicalpickles Apr 29, 2024
727b667
fix version
technicalpickles Apr 29, 2024
59d2a33
Merge pull request #63 from technicalpickles/standardrb
technicalpickles Apr 29, 2024
27612f9
Merge remote-tracking branch 'upstream/main' into fh-main
aellispierce Jan 13, 2025
e133966
Allow activesupport 8.0.1
aellispierce Jan 13, 2025
f25955d
Allow up to 9.0
aellispierce Jan 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/standardrb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: StandardRB

on: [push]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: StandardRB Linter
uses: standardrb/standard-ruby-action@v0.0.5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.7.5
3.2.2
7 changes: 4 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
source 'https://rubygems.org'
source "https://rubygems.org"

# Specify your gem's dependencies in pager_duty-connection.gemspec
gemspec

# for tests & running examples
group :development do
gem 'dotenv'
gem 'pry'
gem "dotenv"
gem "pry"
gem "standardrb"
end
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ And this is what it doesn't do:

Add this line to your application's Gemfile:

gem 'pager_duty-connection'
```ruby
gem "pager_duty-connection"
```

And then execute:

Expand All @@ -54,22 +56,22 @@ pagerduty = PagerDuty::Connection.new(token)
pagerduty = PagerDuty::Connection.new(token, token_type: :Bearer)

# setup to use a custom domain
pagerduty = PagerDuty::Connection.new(token, token_type: :Bearer, url: 'https://custom.domain.com')
pagerduty = PagerDuty::Connection.new(token, token_type: :Bearer, url: "https://custom.domain.com")

# 4 main methods: `get`, `post`, `put`, and `delete`:

response = pagerduty.get('some/relative/path', params)
response = pagerduty.post('some/relative/path', params)
response = pagerduty.delete('some/relative/path', params)
response = pagerduty.put('some/relative/path', params)
response = pagerduty.get("some/relative/path", params)
response = pagerduty.post("some/relative/path", params)
response = pagerduty.delete("some/relative/path", params)
response = pagerduty.put("some/relative/path", params)

# use something like irb or pry to poke around the responses
# the contents will vary a bit between call, ie:

response = pagerduty.get('incidents')
response = pagerduty.get("incidents")
response.incidents # an array of incidents

response = pagerduty.get('incidents/YYZ')
response = pagerduty.get("incidents/YYZ")
response # the hash/object that represents the array
```

Expand Down Expand Up @@ -102,14 +104,14 @@ In general, you can get/put/post/delete a path, with some attributes. Use the [R
If you are working in Rails, and using only a single PagerDuty account, you'll probably want an initializer:

```ruby
$pagerduty = PagerDuty::Connection.new('your-token')
$pagerduty = PagerDuty::Connection.new("your-token")
```

And if you are using [dotenv](https://github.com/bkeepers/dotenv), you can use environment variables, and stash them in .env:

```ruby
account = ENV['PAGERDUTY_ACCOUNT'] || raise("Missing ENV['PAGERDUTY_ACCOUNT'], add to .env")
token = ENV['PAGERDUTY_TOKEN'] || raise("Missing ENV['PAGERDUTY_TOKEN'], add to .env.#{Rails.env}")
account = ENV["PAGERDUTY_ACCOUNT"] || raise("Missing ENV['PAGERDUTY_ACCOUNT'], add to .env")
token = ENV["PAGERDUTY_TOKEN"] || raise("Missing ENV['PAGERDUTY_TOKEN'], add to .env.#{Rails.env}")
$pagerduty = PagerDuty::Connection.new(account, token)
```

Expand Down
16 changes: 8 additions & 8 deletions examples/find-users.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/usr/bin/env ruby

require 'dotenv'
Dotenv.load ".env.development", '.env'
require "dotenv"
Dotenv.load ".env.development", ".env"

token = ENV['PAGERDUTY_TOKEN'] || raise("Missing ENV['PAGERDUTY_TOKEN'], add to .env.development")
token = ENV["PAGERDUTY_TOKEN"] || raise("Missing ENV['PAGERDUTY_TOKEN'], add to .env.development")

require 'pager_duty/connection'
$pagerduty = PagerDuty::Connection.new(token)
require "pager_duty/connection"
pagerduty = PagerDuty::Connection.new(token)

# https://v2.developer.pagerduty.com/v2/page/api-reference#!/Users/get_users
response = $pagerduty.get('users')
response['users'].each do |user|
puts "#{user['name']}: #{user['email']}"
response = pagerduty.get("users")
response["users"].each do |user|
puts "#{user["name"]}: #{user["email"]}"
end
30 changes: 15 additions & 15 deletions examples/shifts-with-incidents-and-log-entries.rb
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
#!/usr/bin/env ruby

require 'dotenv'
Dotenv.load ".env.development", '.env'
require "dotenv"
Dotenv.load ".env.development", ".env"

token = ENV['PAGERDUTY_TOKEN'] || raise("Missing ENV['PAGERDUTY_TOKEN'], add to .env.development")
token = ENV["PAGERDUTY_TOKEN"] || raise("Missing ENV['PAGERDUTY_TOKEN'], add to .env.development")

require 'pager_duty/connection'
$pagerduty = PagerDuty::Connection.new(token)
require "pager_duty/connection"
pagerduty = PagerDuty::Connection.new(token)

schedule_id = ENV['PAGERDUTY_SCHEDULE_ID'] || raise("Missing ENV['PAGERDUTY_SCHEDULE_ID'], add to .env.development")
schedule_id = ENV["PAGERDUTY_SCHEDULE_ID"] || raise("Missing ENV['PAGERDUTY_SCHEDULE_ID'], add to .env.development")

# pull down schedule entires for XXX schedule in the last day (ie who has been on call, and when
time_since = 1.day.ago
time_until = Time.now

# https://v2.developer.pagerduty.com/v2/page/api-reference#!/On-Calls/get_oncalls
response = $pagerduty.get("oncalls", query_params: { since: time_since, until: time_until, schedule_ids: [schedule_id] })
response = pagerduty.get("oncalls", query_params: {since: time_since, until: time_until, schedule_ids: [schedule_id]})

entries = response['oncalls']
entries = response["oncalls"]

entries.each do |entry|
puts "#{entry['start']} - #{entry['end']}: #{entry['user']['summary']}"
puts "#{entry["start"]} - #{entry["end"]}: #{entry["user"]["summary"]}"

# find incidents during that shift
# https://v2.developer.pagerduty.com/v2/page/api-reference#!/Incidents/get_incidents
response = $pagerduty.get('incidents', query_params: { since: entry['start'], until: entry['end'], user_ids: [entry['user']['id']] })
response = pagerduty.get("incidents", query_params: {since: entry["start"], until: entry["end"], user_ids: [entry["user"]["id"]]})

response['incidents'].each do |incident|
response["incidents"].each do |incident|
puts "\t#{incident.id}"

# find log entries (acknowledged, notifications, etc) for incident:
# https://v2.developer.pagerduty.com/v2/page/api-reference#!/Incidents/get_incidents_id_log_entries
response = $pagerduty.get("incidents/#{incident.id}/log_entries")
response = pagerduty.get("incidents/#{incident.id}/log_entries")

# select just the notes
notes = response['log_entries'].select do |log_entry|
log_entry['channel'] && log_entry['channel']['type'] == 'note'
notes = response["log_entries"].select do |log_entry|
log_entry["channel"] && log_entry["channel"]["type"] == "note"
end

# and print them out:
notes.each do |log_entry|
puts "\t\t#{log_entry['channel']['summary']}"
puts "\t\t#{log_entry["channel"]["summary"]}"
end
end
end
5 changes: 2 additions & 3 deletions lib/pager_duty.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require 'pager_duty/connection/version'
require "pager_duty/connection/version"

module PagerDuty
autoload :Connection, 'pager_duty/connection'
autoload :Connection, "pager_duty/connection"
end

Loading
Loading