This repository was archived by the owner on Mar 7, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.rb
More file actions
68 lines (57 loc) · 1.79 KB
/
app.rb
File metadata and controls
68 lines (57 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
require 'rubygems'
require 'google/api_client'
require 'active_support/all'
require 'sinatra/base'
class ApiClient
attr_accessor :client
cattr_accessor :instance
def initialize
@client = Google::APIClient.new
key = Google::APIClient::KeyUtils.load_from_pkcs12(Base64.decode64(ENV["departure_lounge_client_key"]), 'notasecret')
@client.authorization = Signet::OAuth2::Client.new(
:token_credential_uri => 'https://accounts.google.com/o/oauth2/token',
:audience => 'https://accounts.google.com/o/oauth2/token',
:scope => 'https://www.googleapis.com/auth/calendar.readonly',
:issuer => ENV["departure_lounge_issuer"],
:signing_key => key
)
@client.authorization.fetch_access_token!
end
def events
@client.execute(:api_method => service.events.list, :parameters => {
'calendarId' => ENV["departure_lounge_calendar_id"],
'timeMin' => DateTime.now.to_s,
'timeMax' => 24.hours.from_now.to_datetime.to_s,
'orderBy' => 'startTime',
'singleEvents' => true
}).data.items
end
def service
@client.discovered_api('calendar', 'v3')
end
end
class DepartureLounge < Sinatra::Base
configure do
ApiClient.instance = ApiClient.new
set :protection, :except => :frame_options
end
use Rack::Auth::Basic, "Please login to the release dashboard" do |username, password|
username == ENV['departure_lounge_user'] and password == ENV['departure_lounge_password']
end
get '/events.json' do
events = ApiClient.instance.events.map do |event|
{
"app" => event["summary"],
"start" => event["start"]["dateTime"],
"end" => event["end"]["dateTime"]
}
end
events.to_json
end
get '/' do
erb :dashboard
end
def pretty_time(string)
string.strftime("%H:%M")
end
end