This repository was archived by the owner on May 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a751d92
commit 7d529e7
Showing
7 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module Pagerduty | ||
module CLT | ||
module Formatters | ||
module Schedules | ||
class Table | ||
|
||
def initialize(schedules) | ||
@schedules = schedules | ||
end | ||
|
||
def render | ||
return nil if schedules.empty? | ||
puts TerminalTable.new(headings: columns, rows: rows, max_width: 140).render | ||
end | ||
|
||
private | ||
|
||
attr_reader :schedules | ||
|
||
def columns | ||
{ | ||
name: { label: 'Name', max_width: 35 }, | ||
people: { label: 'People', max_width: -1 } | ||
} | ||
end | ||
|
||
def rows | ||
schedules.map do |schedule| | ||
{ | ||
name: schedule.name, | ||
people: schedule.users.map(&:name).join(', ') | ||
} | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
module Pagerduty | ||
module CLT | ||
class Schedule | ||
|
||
include PathHelper # FIXME | ||
extend PathHelper # FIXME | ||
|
||
def initialize(raw) | ||
@raw = raw | ||
end | ||
|
||
def id | ||
@id ||= raw.id | ||
end | ||
|
||
def name | ||
@name ||= raw.name | ||
end | ||
|
||
def users | ||
@users ||= begin | ||
path = schedule_users_path(id) | ||
options = { since: Time.now.strftime('%Y-%m-%d'), until: (Time.now + 7 * 86_400).strftime('%Y-%m-%d') } | ||
$connection.get(path, options).users.map { |raw_user| User.new(raw_user) } | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :raw | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module Pagerduty | ||
module CLT | ||
class Schedules | ||
|
||
include Base | ||
include PathHelper # FIXME | ||
|
||
def all | ||
where | ||
end | ||
|
||
def where(query: nil) | ||
get(query) | ||
end | ||
|
||
private | ||
|
||
def get(query) | ||
schedules = [] | ||
options = {} | ||
options[:query] = query if query | ||
|
||
jobs = [] | ||
response = $connection.get(schedules_path) | ||
response.schedules.each_with_index do |raw_schedule_summary, i| | ||
jobs << Thread.new do | ||
raw_schedule_detailed = $connection.get(schedule_path(raw_schedule_summary.id), options) | ||
schedules[i] = Schedule.new(raw_schedule_detailed.schedule) | ||
end | ||
end | ||
|
||
jobs.each(&:join) | ||
schedules | ||
end | ||
|
||
end | ||
end | ||
end |