Class: GoogleCalendar::Calendar
- Inherits:
-
Object
- Object
- GoogleCalendar::Calendar
- Defined in:
- lib/googlecalendar/calendar.rb
Overview
SUMMARY
This class represents User's Calendar.
How to get this class
-
get calendar list
srv = GoogleCalendar::Service.new(MAIL, PASS) cal_list = srv.calendars cal_list is a hash of user's calendars. key: a calendar's editable feed url. value: calendar object.
-
create an instance from calendar’s feed url
srv = GoogleCalendar::Service.new(MAIL, PASS) cal = Calendar.new(srv, FEED)
Constant Summary collapse
- DEFAULT_CALENDAR_FEED =
"http://www.google.com/calendar/feeds/default/private/full"
- ATTRIBUTES =
defines calendar’s readonly attributes
{ "updated" => ["updated"], "title" => ["title"], "subtitle" => ["subtitle"], "name" => ["author/name"], "email" => ["author/email"], "timezone" => ["gCal:timezone", "value"], "where" => ["gd:where", "valueString"]}.each do |key, val| module_eval( "def #{key}; self.source.root.elements[\"#{val[0]}\"]." + (val.length == 1 ? "text" : "attributes[\"#{val[1]}\"]") + "; end" ) end
Instance Attribute Summary collapse
-
#feed ⇒ Object
readonly
Returns the value of attribute feed.
Class Method Summary collapse
-
.calendars(srv) ⇒ Object
get user’s calendar list.
Instance Method Summary collapse
-
#create_event ⇒ Object
creates a new Event instance which belongs to this clandar instance.
-
#events(conditions = {}) ⇒ Object
send query to get events and returns an array of Event objects.
-
#initialize(srv, feed = DEFAULT_CALENDAR_FEED) ⇒ Calendar
constructor
srv: GoogleCalendar::Service object feed: Calendar’s editable feed url(default value: user’s default calendar).
-
#source ⇒ Object
REXML::Document object which represents calendar object.
Constructor Details
#initialize(srv, feed = DEFAULT_CALENDAR_FEED) ⇒ Calendar
srv: GoogleCalendar::Service object feed: Calendar’s editable feed url(default value: user’s default calendar)
38 39 40 41 42 |
# File 'lib/googlecalendar/calendar.rb', line 38 def initialize(srv, feed = DEFAULT_CALENDAR_FEED) @srv = srv @feed = feed @source = nil end |
Instance Attribute Details
#feed ⇒ Object (readonly)
Returns the value of attribute feed.
34 35 36 |
# File 'lib/googlecalendar/calendar.rb', line 34 def feed @feed end |
Class Method Details
.calendars(srv) ⇒ Object
get user’s calendar list.
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/googlecalendar/calendar.rb', line 95 def self.calendars(srv) ret = srv.calendar_list list = REXML::Document.new(ret.body) h = {} list.root.elements.each("entry/link") do |e| if e.attributes["rel"] == "alternate" feed = e.attributes["href"] h[feed] = Calendar.new(srv, feed) end end h end |
Instance Method Details
#create_event ⇒ Object
creates a new Event instance which belongs to this clandar instance.
73 74 75 76 77 78 |
# File 'lib/googlecalendar/calendar.rb', line 73 def create_event ev = Event.new ev.srv = @srv ev.feed = @feed ev end |
#events(conditions = {}) ⇒ Object
send query to get events and returns an array of Event objects. if any conditions are given, recent 25 entries are retrieved. For detail, see Service#query
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/googlecalendar/calendar.rb', line 57 def events(conditions = {}) ret = @srv.query(self.feed, conditions) raise InvalidCalendarURL unless ret.code == "200" REXML::Document.new(ret.body).root.elements.each("entry"){}.map do |elem| elem.attributes["xmlns:gCal"] = "http://schemas.google.com/gCal/2005" elem.attributes["xmlns:gd"] = "http://schemas.google.com/g/2005" elem.attributes["xmlns"] = "http://www.w3.org/2005/Atom" entry = Event.new entry.srv = @srv entry.load_xml("<?xml version='1.0' encoding='UTF-8'?>#{elem.to_s}") end end |
#source ⇒ Object
REXML::Document object which represents calendar object
47 48 49 50 |
# File 'lib/googlecalendar/calendar.rb', line 47 def source @source = get_data unless @source @source end |