Class | GoogleCalendar::Service |
In: |
lib/googlecalendar/service.rb
|
Parent: | Object |
This class interacts with google calendar service.
AUTH_SERVER | = | "www.google.com" | Server name to Authenticate | |
AUTH_PATH | = | "/accounts/ClientLogin" | Server Path to authenticate | |
CALENDAR_LIST_PATH | = | "http://www.google.com/calendar/feeds/" | URL to get calendar list |
# File lib/googlecalendar/service.rb, line 69 def initialize(email, pass) @email = email @pass = pass @session = nil @cookie = nil @auth = nil end
get the list of user’s calendars and returns http response object
# File lib/googlecalendar/service.rb, line 80 def calendar_list auth unless @auth uri = URI.parse(CALENDAR_LIST_PATH + @email) do_get(uri, "Authorization" => "GoogleLogin auth=#{@auth}") end
delete an event.
# File lib/googlecalendar/service.rb, line 115 def delete(feed) auth unless @auth uri = URI.parse(feed) do_post(uri, {"X-HTTP-Method-Override" => "DELETE", "Authorization" => "GoogleLogin auth=#{@auth}"}, "DELETE " + uri.path) end
insert an event
# File lib/googlecalendar/service.rb, line 127 def insert(feed, event) auth unless @auth uri = URI.parse(feed) do_post(uri, {"Authorization" => "GoogleLogin auth=#{@auth}", "Content-Type" => "application/atom+xml", "Content-Length" => event.length.to_s}, event) end
send query for events of a calendar and returns http response object. available condtions are
For detail, see code.google.com/apis/gdata/protocol.html#Queries
# File lib/googlecalendar/service.rb, line 103 def query(cal_url, conditions) auth unless @auth uri = URI.parse(cal_url) uri.query = conditions.map do |key, val| "#{key}=#{URI.escape(val.kind_of?(Time) ? val.getutc.iso8601 : val.to_s)}" end.join("&") do_get(uri, "Authorization" => "GoogleLogin auth=#{@auth}") end
update an event.
# File lib/googlecalendar/service.rb, line 139 def update(feed, event) auth unless @auth uri = URI.parse(feed) do_post(uri, {"X-HTTP-Method-Override" => "PUT", "Authorization" => "GoogleLogin auth=#{@auth}", "Content-Type" => "application/atom+xml", "Content-Length" => event.length.to_s}, event) end