googleカレンダーの情報取得

gcalapiを使うと簡単らしいので試してみた。

#!/usr/bin/ruby -Ku
require "rubygems"
require "googlecalendar/calendar"

GCAL_ACCOUNT = "someone"
GCAL_PASSWORD = "hogehoge"
GCAL_FEED = "http://www.google.com/calendar/feeds/someone@gmail.com/private/full"

server = GoogleCalendar::Service.new(GCAL_ACCOUNT, GCAL_PASSWORD)
calendar = GoogleCalendar::Calendar.new(server, GCAL_FEED)

now = Time.now
calendar.events(:'start-min' => now, :orderby => "starttime").each do |ev|
  puts "[#{ev.st} - #{ev.en}] #{ev.title}"
end

これだけでgoogleカレンダーのイベントがとれてしまう。

[mitsu@koma_colinux gcal]$ ./mygcal.rb
[Tue Jul 29 11:00:00 UTC 2008 - Tue Jul 29 12:00:00 UTC 2008] 提出書類作成

楽チンだなぁ。素晴らし。

ただ、ServiceBase#queryのパラメータconditionsで

    # * :max-results => max contents count. (default: 25)
    # * :start-index => 1-based index of the first result to be retrieved

のようにハッシュのキーにハイフンが入っているのがちょっと辛い。シンボルをクォーテーションで括りたくない派なので。