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
- 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) ⇒ Calendar
constructor
srv: GoogleCalendar::Service object feed: Calendar’s editable feed url.
-
#source ⇒ Object
REXML::Document object which represents calendar object.
Constructor Details
#initialize(srv, feed) ⇒ Calendar
srv: GoogleCalendar::Service object feed: Calendar’s editable feed url
65 66 67 68 69 |
# File 'lib/googlecalendar/calendar.rb', line 65 def initialize(srv, feed) @srv = srv @feed = feed @source = nil end |
Instance Attribute Details
#feed ⇒ Object (readonly)
Returns the value of attribute feed.
61 62 63 |
# File 'lib/googlecalendar/calendar.rb', line 61 def feed @feed end |
Class Method Details
.calendars(srv) ⇒ Object
get user’s calendar list.
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/googlecalendar/calendar.rb', line 30 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.
100 101 102 103 104 105 |
# File 'lib/googlecalendar/calendar.rb', line 100 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
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/googlecalendar/calendar.rb', line 84 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
74 75 76 77 |
# File 'lib/googlecalendar/calendar.rb', line 74 def source @source = get_data unless @source @source end |