7.2.07

Zend and Google calendar

So I've been spending a few days since launch reviewing the operational, product and marketing metrics for share2me. We have a 10 minute morning call @ 10 minutes before 10am every day where I update the team on basic metrics such as # of registrations and hot sources of traffic. So I started to think what a good idea it would be to put that data in a calendar that the team could subscribe to... so I don't have to consume any of the precious few 10-b4-10 minutes. After a quick search I found a fabulous (if not a tad on the undocumented) library provided by the Zend team.

Here's the basic code to post to a calendar.


<?php
require_once 'Zend/Gdata.php';
require_once 'Zend/Http/Client.php';
require_once 'Zend/Gdata/ClientLogin.php';
require_once 'Zend/Gdata/Calendar.php';

$email = 'YOU@gmail.com';
$passwd = 'PASSWD';
$feedUrl = 'http://www.google.com/calendar/feeds/BLAH';

$client = Zend_Gdata_ClientLogin::getHttpClient($email, $passwd, 'cl');
$cal = new Zend_Gdata_Calendar($client);

$timestamp = time();
$start=date('Y-m-d', $timestamp);
$end=date('Y-m-d', ($timestamp + (60 * 60 * 24)));

$xmlString = <<<XML
<entry xmlns='http://www.w3.org/2005/Atom'
xmlns:gd='http://schemas.google.com/g/2005'>
<category scheme='http://schemas.google.com/g/2005#kind'
term='http://schemas.google.com/g/2005#event'></category>
<title type='text'>Title for my event</title>
<content type='text'>This is where all the content goes.</content>
<author>
<name>Jay Ridgeway</name>
<email>YOU@gmail.com</email>
</author>
<gd:transparency value='http://schemas.google.com/g/2005#event.transparent'/>
<gd:when startTime='$start' endTime='$end'/>
</entry>
XML;

$xml = new SimpleXMLElement($xmlString);
$cal->post($xml->asXML(), $feedUrl);
?>