class Ruboty::Gcal::Calendar

Public Class Methods

new() click to toggle source
# File lib/ruboty/gcal/client.rb, line 9
def initialize
  @calendar ||= Google::Calendar.new({
    username: ENV["GCAL_USERNAME"],
    password: ENV["GCAL_PASSWORD"],
    app_name: ENV["GCAL_APP_NAME"]
  })
end

Public Instance Methods

find(message) click to toggle source
# File lib/ruboty/gcal/client.rb, line 28
def find(message)
  #Support Japanese
  q = Addressable::URI.parse(message[:query]).normalize.to_s
  message.reply(@calendar.find_events(q) || "Event Not Found")
end
recent() click to toggle source
# File lib/ruboty/gcal/client.rb, line 23
def recent
  events = @calendar.find_future_events({max_results: 5})
  events.map { |e| e.to_s }.join("\n") || "Event Not Found"
end
schedule(message) click to toggle source
# File lib/ruboty/gcal/client.rb, line 34
def schedule(message)
  event = @calendar.create_event { |e|
    e.title = message[:title]
    e.start_time = Time.parse(message[:start_time])
    e.end_time = Time.parse(message[:end_time])
  }
  message.reply("Scheduled #{event}")
rescue ArgumentError
  message.reply("Could not schedule the event")
end
today() click to toggle source
# File lib/ruboty/gcal/client.rb, line 17
def today
  today = Time.now.utc
  tomorrow = today + 86400
  @calendar.find_events_in_range(today, tomorrow) || "Event Not Found"
end
unschedule(message) click to toggle source
# File lib/ruboty/gcal/client.rb, line 45
def unschedule(message)
  if event = @calendar.find_event_by_id(message[:event_id])
    @calendar.delete_event(event)
    message.reply("Deleted #{event.title}")
  else
    message.reply("Event Not Found")
  end
end