Create recurring events using the API

72 views
Skip to first unread message

flandolsi

unread,
Oct 30, 2009, 11:17:20 AM10/30/09
to Google Data APIs Objective-C Client Library Discussion
Hi All,

I know this might be a very easy thing, but I am just starting with
the library.

Can anyone help me on how to create a recurring event (specifying the
different parameters) in code. Posting a short code snippet will be of
great help.


The sample application does only create single occurring events.

Thanks,
Fakhri

David Phillip Oster

unread,
Oct 30, 2009, 4:24:02 PM10/30/09
to Google Data APIs Objective-C Client Library Discussion
The easy way is to create some sample recurring events on the calendar
in a web browser, then fetch them in GData with logging turned on and
inspecting the resulting GData. The recurrence information is
specified according to RFC 2445 http://www.ietf.org/rfc/rfc2445.txt
RFC 2446 covers inviting attendees, and processing their acceptances
and refusals.

Complexities occur when an event is recurring, but some instances get
moved (or deleted) (Particularly if you want to undo the motion or
deletion, (then redo, then undo again.))

Also Recurring events can cross time zones, including some instances
in standard time, some in daylight saving time. And the date where
those transitions occur can change at the whim of the legislature of
the country (or even city!) where the event is happening.

flandolsi

unread,
Oct 30, 2009, 8:48:36 PM10/30/09
to Google Data APIs Objective-C Client Library Discussion

Wow there seems to be a lot of work needed to implement recurring
events. Do you mean that we need to use xml to create them?

Can [event recurrence] be used to obtain details about the event? (I
am guessing that [event recurrence] yields a structure with the
different properties of the event, namely freq, start time, end
time ... but I am not sure how that can be done).

I really appreciate your help.

flandolsi

unread,
Nov 2, 2009, 9:06:55 AM11/2/09
to Google Data APIs Objective-C Client Library Discussion
Can anyone post a small code snippet on how to create a recurring
event in obj-C?

Thanks

David Phillip Oster

unread,
Nov 2, 2009, 2:39:01 PM11/2/09
to Google Data APIs Objective-C Client Library Discussion
No. you don't need XML, you just do a little string processing

Did you do as I asked, and look at the recurrence specications in
existing events?

The look like this, for example:

"RRULE:FREQ=DAILY;BYDAY=MO,WE,FR;UNTIL=20100804T180000Z;WKST=SU\r
\nDURATION:PT3600S\r\n"


Handling the full spec is difficult, but just creating the recurring
events you want is easy.

David Phillip Oster

unread,
Nov 2, 2009, 7:26:55 PM11/2/09
to Google Data APIs Objective-C Client Library Discussion
I'm working with Greg to post a parser/unparser for RFC2445 recurrence
rules, so check this space in a few days.

flandolsi

unread,
Nov 2, 2009, 10:09:45 PM11/2/09
to Google Data APIs Objective-C Client Library Discussion
Thanks a lot David. I will stay tuned.

Fakhri

David Phillip Oster

unread,
Nov 3, 2009, 1:40:42 AM11/3/09
to Google Data APIs Objective-C Client Library Discussion
As a favor to me, Greg has kindly allowed me to attach a simple class
for parsing and unparsing GDataRecurrence specifications. I've add it,
with unit test code, and a simple example to
http://code.google.com/p/gdata-objectivec-client/downloads/list The
interface is based on that used by the Macintosh Sync Services
Manager. He doesn't support it. I do.

In the official example CalendarHelloWorldMini, to create an event,
you say:
// begin common prefix.
// Construct the event we'll post.
GDataEntryCalendarEvent *event = [GDataEntryCalendarEvent
calendarEvent];
[event setTitleWithString:@"Hello World"];

NSTimeZone *currentTimeZone = [NSTimeZone defaultTimeZone];
NSDate *now = [NSDate dateWithTimeIntervalSinceNow:0];
GDataDateTime *nowDateTime = [GDataDateTime dateTimeWithDate:now

timeZone:currentTimeZone];

NSDate *oneHourFromNow = [NSDate dateWithTimeIntervalSinceNow:
60*60];
GDataDateTime *endDateTime = [GDataDateTime
dateTimeWithDate:oneHourFromNow

timeZone:currentTimeZone];

// end common prefix.

GDataWhen *when = [GDataWhen whenWithStartTime:nowDateTime
endTime:endDateTime];
[event addTime:when];


In CalendarHelloWorldRecurring, you say, after the common prefix:

NSDictionary *recurrenceDict = [NSDictionary
dictionaryWithObjectsAndKeys:
nowDateTime, kStartDateKey,
endDateTime, kEndDateKey,
@"daily", kRecurrenceFrequencyKey,
[NSNumber numberWithInt:6], kRecurrenceCountKey,
nil];
NSString *recurrenceString = [[RecurrenceRFC2445 recurrence]
recurrenceStringFromDictionary:recurrenceDict];
GDataRecurrence *recurrence = [GDataRecurrence
recurrenceWithString:recurrenceString];
[event setRecurrence:recurrence];

That is, you construct a dictionary of key value pairs that define the
recurrence. use [RecurrenceRFC2445 recurrence] to turn it into a
string (use it once, then discard it. then pass that string, instead
of a GDataWhen to define when the event occurs.

You can look at RecurrenceRFC2445 .h and its unit tests for some of
the things you can put in the dictionary.

The recurrence dictionary Api is inspired by
http://developer.apple.com/documentation/AppleApplications/Reference/SyncServicesSchemaRef/Articles/Calendars.html

I've only tested it on Mac OS, but since it only uses Foundation, it
should be fine on iPhone OS.
-- DavidPhillipOster

flandolsi

unread,
Nov 3, 2009, 8:25:31 AM11/3/09
to Google Data APIs Objective-C Client Library Discussion
Thanks a lot David and Greg. This makes things clearer to me.

Best,
~Fakhri

Ash Kin

unread,
Nov 3, 2009, 9:00:47 AM11/3/09
to gdata-objec...@googlegroups.com
Hi David,
 
You are really doing great work. Is it possible to provide this kind of sample for GDataXML. how to traverse a XML through the node and get the element using GDataXML?
 
Thanks&Regards,
Ash

David Phillip Oster

unread,
Nov 3, 2009, 10:09:35 AM11/3/09
to Google Data APIs Objective-C Client Library Discussion
I don't understand. You can ask a GDataEntryCalendarEvent event for
its GDataRecurence, but it just holds an NSString that follows the
RFC2445 standard. The code I posted parses that NSString into a
convenient NSDictionary, or given such a dictionary produces an
appropriate NSString. Once you get down to the string of the
recurrence, there isn't any XML.
Reply all
Reply to author
Forward
0 new messages