The newest versions of the Google Calendar API and Google Tasks API use JSON as their data format. In languages like PHP and Ruby, it’s simple to turn a JSON object into something that can be easily read and modified, like an associative array or hash.

While creating and modifying hashes is straightforward, sometimes you want a true object and the benefits that come with using one, such as type checking or introspection. To enable this, the PHP and Ruby client libraries can now provide objects as the results of API calls, in addition to supporting hash responses.

Ruby gets this for free with the latest version of the gem. For PHP, you have to enable support in the client instance:
$apiClient = new apiClient();
$apiClient->setUseObjects(true);
The following examples for PHP and Ruby retrieve an event via the Calendar API, and use data from the new resulting object:

PHP:
$event = $service->events->get("primary", "eventId");
echo $event->getSummary();
Ruby:
result = client.execute(
:api_method => service.events.get,
:parameters => {'calendarId' => 'primary',
'eventId' => 'eventId'})
print result.data.summary
If you have general questions about the client libraries, be sure to check out the client library forums (PHP and Ruby). For questions on specific Apps APIs come find us in the respective Apps API forum.

Dan Holevoet   profile

Dan joined the Google Developer Relations team in 2007. When not playing Starcraft, he works on Google Apps, with a focus on the Calendar and Contacts APIs. He's previously worked on iGoogle, OpenSocial, Gmail contextual gadgets, and the Google Apps Marketplace.