Permalink
Browse files

GCal Event

  • Loading branch information...
1 parent 943840a commit d361ac6159565776efcadb8dd5fcd072a2bd3bd2 @raybaxter committed Jan 5, 2009
View
@@ -37,10 +37,10 @@ class Container < Element
# The "atom:updated" Element
ELEMENTS = Atom::Element::ELEMENTS.merge({
- :alternate_link => {:type => :compound, :xpath => '//atom:feed/atom:link[@rel=\"alternate\"]', :attribute => "href"},
- :feed_link => {:type => :compound, :xpath => '//atom:feed/atom:link[@rel=\"http://schemas.google.com/g/2005#feed\"]', :attribute => "href"},
- :post_link => {:type => :compound, :xpath => '//atom:feed/atom:link[@rel=\"http://schemas.google.com/g/2005#post\"]', :attribute => "href"},
- :self_link => {:type => :compound, :xpath => '//atom:feed/atom:link[@rel=\"self\"]', :attribute => "href"},
+ :alternate_link => {:type => :compound, :xpath => '//atom:$CONTAINER$/atom:link[@rel=\"alternate\"]', :attribute => "href"},
+ :feed_link => {:type => :compound, :xpath => '//atom:$CONTAINER$/atom:link[@rel=\"http://schemas.google.com/g/2005#feed\"]', :attribute => "href"},
+ :post_link => {:type => :compound, :xpath => '//atom:$CONTAINER$/atom:link[@rel=\"http://schemas.google.com/g/2005#post\"]', :attribute => "href"},
+ :self_link => {:type => :compound, :xpath => '//atom:$CONTAINER$/atom:link[@rel=\"self\"]', :attribute => "href"},
})
attr_reader :document
View
@@ -1,36 +1,36 @@
module Atom
- # NAMESPACE = %q[ atom:http://www.w3.org/2005/Atom ]
NAMESPACES = %w[ atom:http://www.w3.org/2005/Atom ]
class Element < LibXML::XML::Node
include LibXML
- ELEMENT_DEFAULTS = {:type => :simple, :xpath => "//atom:feed/atom:$KEY$", :link? => false}
+ ELEMENT_DEFAULTS = { :type => :simple, :xpath => "//atom:$CONTAINER$/atom:$KEY$" }
ELEMENTS = {
- :atom_id => { :xpath => '//atom:feed/atom:id'},
- :title => {},
- :subtitle => {},
- :updated => {},
- :published => {:xpath => '//atom:feed/atom:published'},
+ :atom_id => { :xpath => '//atom:$CONTAINER$/atom:id' },
+ :title => { },
+ :subtitle => { },
+ :content => { },
+ :updated => { },
+ :published => { :xpath => '//atom:$CONTAINER$/atom:published' },
- :generator => {},
- :generator_uri => {:type => :compound, :xpath => '//atom:feed/atom:generator', :attribute => "uri"},
- :generator_version=> {:type => :compound, :xpath => '//atom:feed/atom:generator', :attribute => "version"},
+ :generator => { },
+ :generator_uri => { :type => :compound, :xpath => '//atom:feed/atom:generator', :attribute => "uri" },
+ :generator_version=> { :type => :compound, :xpath => '//atom:feed/atom:generator', :attribute => "version" },
- :author => {},
- :author_name => {:xpath => '//atom:feed/atom:author/atom:name'},
- :author_email => {:xpath => '//atom:feed/atom:author/atom:email'},
+ :author => { },
+ :author_name => { :xpath => '//atom:$CONTAINER$/atom:author/atom:name' },
+ :author_email => { :xpath => '//atom:$CONTAINER$/atom:author/atom:email' },
- :links => {:type => :compound, :xpath => "//atom:feed/atom:link"},
- :entries => {:type => :compound, :xpath => "//atom:feed/atom:entry"},
+ :links => { :type => :compound, :xpath => "//atom:$CONTAINER$/atom:link" },
+ :entries => { :type => :compound, :xpath => "//atom:$CONTAINER$/atom:entry" },
- :category => {},
- :category_term => {:type => :compound, :xpath => '//atom:feed/atom:category', :attribute => "term"},
- :category_scheme => {:type => :compound, :xpath => '//atom:feed/atom:category', :attribute => "scheme"},
- :category_label => {:type => :compound, :xpath => '//atom:feed/atom:category', :attribute => "label"},
+ :category => { },
+ :category_term => { :type => :compound, :xpath => '//atom:$CONTAINER$/atom:category', :attribute => "term" },
+ :category_scheme => { :type => :compound, :xpath => '//atom:$CONTAINER$/atom:category', :attribute => "scheme" },
+ :category_label => { :type => :compound, :xpath => '//atom:$CONTAINER$/atom:category', :attribute => "label" },
}
if false
@@ -84,6 +84,10 @@ def elements_for_accessors
ELEMENTS
end
+ def container_for_accessors
+ 'feed'
+ end
+
def define_element_accessors(elements)
elements.each do |name, overrides|
values = ELEMENT_DEFAULTS.merge(overrides)
@@ -100,7 +104,7 @@ def method_for_element(name,values)
end
def xpath_for_element(name,xpath)
- xpath.gsub(/\$KEY\$/,name.to_s)
+ xpath.gsub(/\$CONTAINER\$/,container_for_accessors).gsub(/\$KEY\$/,name.to_s)
end
def xpath_for_attribute(attribute)
View
@@ -1,2 +1,3 @@
require 'lib/gcal/calendar'
require 'lib/gcal/calendars'
+require 'lib/gcal/event'
View
@@ -0,0 +1,30 @@
+module GCal
+
+ class Event < Atom::Container
+ NAMESPACES = %w[ atom:http://www.w3.org/2005/Atom
+ opensearch:http://a9.com/-/spec/opensearchrss/1.0/
+ gcal:http://schemas.google.com/gCal/2005
+ gd:http://schemas.google.com/gd/2005
+ ]
+
+ ELEMENTS = {
+ :atom_id => { :xpath => '//atom:entry/atom:id'},
+ :edit_link => { :type => :compound, :xpath => '//atom:$CONTAINER$/atom:link[@rel=\"edit\"]', :attribute => "href"},
+ :comments => { :xpath => '//atom:entry/gd:comments'},
+ :comments_feedlink=> { :type => :compound, :xpath => '//atom:entry/gd:comments/gd:feedLink', :attribute => "href"},
+ :eventStatus => { :type => :compound, :xpath => '//atom:entry/gd:eventStatus', :attribute => "value"},
+ :visibility => { :type => :compound, :xpath => '//atom:entry/gd:visibility', :attribute => "value"},
+
+ }
+
+ def elements_for_accessors
+ super.merge(ELEMENTS)
+ end
+
+ def container_for_accessors
+ 'entry'
+ end
+
+ end
+
+end
@@ -0,0 +1,43 @@
+<?xml version='1.0' encoding='utf-8'?>
+<entry xmlns='http://www.w3.org/2005/Atom'
+xmlns:batch='http://schemas.google.com/gdata/batch'
+xmlns:gCal='http://schemas.google.com/gCal/2005'
+xmlns:gd='http://schemas.google.com/g/2005'
+gd:etag='"F0UNQAJHeSp7ImA6WhVX"'>
+ <id>
+ http://www.google.com/calendar/feeds/default/events/upd56n8tetsuor73bas6v923ek</id>
+ <published>2008-05-31T00:41:07.000Z</published>
+ <updated>2008-05-31T00:41:07.000Z</updated>
+ <app:edited xmlns:app='http://www.w3.org/2007/app'>
+ 2008-05-31T00:41:07.000Z</app:edited>
+ <category scheme='http://schemas.google.com/g/2005#kind'
+ term='http://schemas.google.com/g/2005#event' />
+ <title>Time Zone Test</title>
+ <content>Hi mom!</content>
+ <link rel='alternate' type='text/html'
+ href='http://www.google.com/calendar/event?eid=dXBkNTZuOHRldHN1b3I3M2JhczZ2OTIzZWsgY2FsZW5kYXIubWF2ZW5AbQ'
+ title='alternate' />
+ <link rel='self' type='application/atom+xml'
+ href='http://www.google.com/calendar/feeds/default/private/full/upd56n8tetsuor73bas6v923ek?v=2' />
+ <link rel='edit' type='application/atom+xml'
+ href='http://www.google.com/calendar/feeds/default/private/full/upd56n8tetsuor73bas6v923ek?v=2' />
+ <author>
+ <name>Calendar Maven</name>
+ <email>calendar.maven@gmail.com</email>
+ </author>
+ <gd:comments>
+ <gd:feedLink href='http://www.google.com/calendar/feeds/default/private/full/upd56n8tetsuor73bas6v923ek/comments?v=2' />
+ </gd:comments>
+ <gd:eventStatus value='http://schemas.google.com/g/2005#event.confirmed' />
+ <gd:visibility value='http://schemas.google.com/g/2005#event.default' />
+ <gd:transparency value='http://schemas.google.com/g/2005#event.opaque' />
+ <gCal:uid value='upd56n8tetsuor73bas6v923ek@google.com' />
+ <gCal:sequence value='0' />
+ <gd:when startTime='2008-05-30T10:00:00.000-07:00'
+ endTime='2008-05-30T10:01:00.000-07:00'>
+ <gd:reminder minutes='10' method='alert' />
+ </gd:when>
+ <gd:who rel='http://schemas.google.com/g/2005#event.organizer'
+ valueString='Calendar Maven' email='calendar.maven@gmail.com' />
+ <gd:where />
+</entry>
@@ -13,6 +13,7 @@ xmlns:gd='http://schemas.google.com/g/2005'>
label='Events'/>
<title type='text'>Calendar Maven</title>
<subtitle type='text'>Calendar Maven</subtitle>
+ <content>Hi mom!</content>
<link rel='alternate' type='text/html'
href='http://www.google.com/calendar/embed?src=calendar.maven@gmail.com' />
<link rel='http://schemas.google.com/g/2005#feed'
@@ -13,8 +13,13 @@
# .should == 'http://www.w3.org/2005/Atom'
end
+
it_should_behave_like "common Atom elements"
+ it "should have #content" do
+ Atom::Element.file('spec/fixtures/feeds/synthetic.xml').content.should == 'Hi mom!'
+ end
+
it "should catch method missing errors and raise reasonable errors for debugging" do
@message = nil
@error = begin
View
@@ -0,0 +1,126 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+describe GCal::Event do
+ it "should read an event" do
+ GCal::Event.file('spec/fixtures/feeds/event.xml').should_not be_nil
+ end
+
+ describe "Atom properties" do
+ before(:all) do
+ @event = GCal::Event.file('spec/fixtures/feeds/event.xml')
+ end
+
+ it "should have #atom_id" do
+ @event.atom_id.should == 'http://www.google.com/calendar/feeds/default/events/upd56n8tetsuor73bas6v923ek'
+ end
+
+ it "should have #title" do
+ @event.title.should == 'Time Zone Test'
+ end
+
+ it "should have #content" do
+ @event.content.should == 'Hi mom!'
+ end
+
+ it "should have #published" do
+ @event.published.should == '2008-05-31T00:41:07.000Z'
+ end
+
+ it "should have #updated" do
+ @event.updated.should == '2008-05-31T00:41:07.000Z'
+ end
+
+ it "should have #category_scheme" do
+ @event.category_scheme.should == 'http://schemas.google.com/g/2005#kind'
+ end
+
+ it "should have #category_term" do
+ @event.category_term.should == 'http://schemas.google.com/g/2005#event'
+ end
+
+ it "should have #links" do
+ @event.links.size.should == 3
+ end
+
+ describe "author" do
+ it "should have author" do
+ @event.author.should_not be_nil
+ @event.author.should == %(Calendar Maven\n calendar.maven@gmail.com)
+ end
+
+ it "should have author_name" do
+ @event.author_name.should == "Calendar Maven"
+ end
+
+ it "should have author_email" do
+ @event.author_email.should == "calendar.maven@gmail.com"
+ end
+ end
+
+ end
+
+ # <app:edited xmlns:app='http://www.w3.org/2007/app'>
+ # 2008-05-31T00:41:07.000Z</app:edited>
+
+ describe "links" do
+ before(:all) do
+ @event = GCal::Event.file('spec/fixtures/feeds/event.xml')
+ end
+
+ it "should have an #alternate_link" do
+ @event.alternate_link.should == 'http://www.google.com/calendar/event?eid=dXBkNTZuOHRldHN1b3I3M2JhczZ2OTIzZWsgY2FsZW5kYXIubWF2ZW5AbQ'
+ end
+
+ it "should have a #self_link" do
+ @event.self_link.should == 'http://www.google.com/calendar/feeds/default/private/full/upd56n8tetsuor73bas6v923ek?v=2'
+ end
+
+ it "should have an #edit_link" do
+ @event.edit_link.should == 'http://www.google.com/calendar/feeds/default/private/full/upd56n8tetsuor73bas6v923ek?v=2'
+ end
+
+ end
+
+ describe "gd namespace properties" do
+ before(:all) do
+ @event = GCal::Event.file('spec/fixtures/feeds/event.xml')
+ end
+
+ it "should have #comments" do
+ @event.comments.should == ''
+ end
+
+ it "should have #comments_feedlink" do
+ @event.comments_feedlink.should == 'http://www.google.com/calendar/feeds/default/private/full/upd56n8tetsuor73bas6v923ek/comments?v=2'
+ end
+
+ it "should have #eventStatus" do
+ @event.eventStatus.should == 'http://schemas.google.com/g/2005#event.confirmed'
+ end
+
+ it "should have #visibility" do
+ @event.visibility.should == 'http://schemas.google.com/g/2005#event.default'
+ end
+
+ xit "should have #transparency" do
+ @event.transparency.should == 'http://schemas.google.com/g/2005#event.opaque'
+ end
+
+
+ # <gd:transparency value='http://schemas.google.com/g/2005#event.opaque' />
+ # <gd:when startTime='2008-05-30T10:00:00.000-07:00'
+ # endTime='2008-05-30T10:01:00.000-07:00'>
+ # <gd:reminder minutes='10' method='alert' />
+ # </gd:when>
+ # <gd:who rel='http://schemas.google.com/g/2005#event.organizer'
+ # valueString='Calendar Maven' email='calendar.maven@gmail.com' />
+ # <gd:where />
+
+
+ end
+
+ # <gCal:uid value='upd56n8tetsuor73bas6v923ek@google.com' />
+ # <gCal:sequence value='0' />
+
+
+end

0 comments on commit d361ac6

Please sign in to comment.