class Gcal::Gcal
Constants
- AUDIENCE
- SCOPE
- TOKEN_CREDENTIAL_URI
Attributes
calendar_id[R]
client[R]
Public Class Methods
new(calendar_id, p12key_path, p12pass, mail_adress)
click to toggle source
# File lib/gcal.rb, line 14 def initialize(calendar_id, p12key_path, p12pass, mail_adress) @client = Google::APIClient.new(application_name: '') @calendar_id = calendar_id key = Google::APIClient::KeyUtils.load_from_pkcs12(p12key_path, p12pass) @client.authorization = Signet::OAuth2::Client.new( token_credential_uri: TOKEN_CREDENTIAL_URI, audience: AUDIENCE, scope: SCOPE, issuer: mail_adress, signing_key: key) @client.authorization.fetch_access_token! end
Public Instance Methods
all_day_events()
click to toggle source
# File lib/gcal.rb, line 49 def all_day_events under_time = Time.new(1000, 1, 1, 0) top_time = Time.new(3000, 1, 1, 0) params = event_get_params(under_time.iso8601, top_time.iso8601) send_params(params) end
discovered_cal_api()
click to toggle source
# File lib/gcal.rb, line 67 def discovered_cal_api @client.discovered_api('calendar', 'v3') end
event_get_params(start_time, end_time)
click to toggle source
# File lib/gcal.rb, line 71 def event_get_params(start_time, end_time) { 'calendarId' => @calendar_id, 'orderBy' => 'startTime', 'timeMax' => end_time, 'timeMin' => start_time, 'singleEvents' => 'True' } end
next_day_events()
click to toggle source
# File lib/gcal.rb, line 35 def next_day_events now = Time.now + (60*60*24) tomorrow = now + (60*60*24) params = event_get_params(now.iso8601, tomorrow.iso8601) send_params(params) end
one_month_events()
click to toggle source
# File lib/gcal.rb, line 42 def one_month_events now = DateTime.now one_month_after = now >> 1 params = event_get_params(now.iso8601, one_month_after.iso8601) send_params(params) end
send_params(params)
click to toggle source
# File lib/gcal.rb, line 56 def send_params(params) cal = discovered_cal_api result = @client.execute(api_method: cal.events.list, parameters: params) events = [] result.data.items.each do |item| events << item end events end
today_events()
click to toggle source
# File lib/gcal.rb, line 28 def today_events now = Time.now tomorrow = now + (60*60*24) params = event_get_params(now.iso8601, tomorrow.iso8601) send_params(params) end