Skip to content

Instantly share code, notes, and snippets.

@kechol
Created January 28, 2022 12:54
Show Gist options
  • Save kechol/e615e93f59ebc08b8e65b3387309213b to your computer and use it in GitHub Desktop.
Save kechol/e615e93f59ebc08b8e65b3387309213b to your computer and use it in GitHub Desktop.
# https://developers.google.com/calendar/api/quickstart/ruby
require "google/apis/calendar_v3"
require "googleauth"
require "googleauth/stores/file_token_store"
require "date"
require "fileutils"
OOB_URI = "urn:ietf:wg:oauth:2.0:oob".freeze
APPLICATION_NAME = "Google Calendar API Ruby Quickstart".freeze
CREDENTIALS_PATH = "credentials.json".freeze
TOKEN_PATH = "token.yaml".freeze
SCOPE = Google::Apis::CalendarV3::AUTH_CALENDAR_READONLY
def authorize
client_id = Google::Auth::ClientId.from_file CREDENTIALS_PATH
token_store = Google::Auth::Stores::FileTokenStore.new file: TOKEN_PATH
authorizer = Google::Auth::UserAuthorizer.new client_id, SCOPE, token_store
user_id = "default".freeze
credentials = authorizer.get_credentials user_id
if credentials.nil?
url = authorizer.get_authorization_url base_url: OOB_URI
puts url
code = gets
credentials = authorizer.get_and_store_credentials_from_code(
user_id: user_id, code: code, base_url: OOB_URI
)
end
credentials
end
service = Google::Apis::CalendarV3::CalendarService.new
service.client_options.application_name = APPLICATION_NAME
service.authorization = authorize
calendar_id = "primary".freeze
response = service.list_events(
calendar_id,
max_results: 20,
single_events: true,
order_by: "startTime",
time_min: "#{Date.today.to_s}T00:00:00+09:00",
time_max: "#{Date.today.to_s}T23:59:59+09:00"
)
response.items.map do |e|
link = e.conference_data&.entry_points&.find{|ep| ep.entry_point_type == "video" }&.uri
puts "#{e.start.date_time.to_s[11..15]} #{link} - #{e.summary}" if link
end
puts "--"
loop do
link = response.items.find {|e| e.start.date_time.to_s[0..15] == DateTime.now.rfc3339[0..15] }
&.conference_data&.entry_points&.find{|ep| ep.entry_point_type == "video" }&.uri
puts "#{DateTime.now.rfc3339[11..15]} #{link}"
system "open -a '/Applications/Google Chrome.app' #{link}" if link
sleep 60
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment