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 48 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 59 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 92 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 104 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: :q => query string :max-results => max contents count. (default: 25) :start-index => 1-based index of the first result to be retrieved :orderby => the order of retrieved data. :published-min => Bounds on the entry publication date(oldest) :published-max => Bounds on the entry publication date(newest) :updated-min => Bounds on the entry update date(oldest) :updated-max => Bounds on the entry update date(newest) :author => Entry author
# File lib/googlecalendar/service.rb, line 80 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 116 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