Skip to content

Instantly share code, notes, and snippets.

@rajibmitra
Forked from mdobson/gist:8116084
Created December 24, 2013 17:50
Show Gist options
  • Save rajibmitra/8116189 to your computer and use it in GitHub Desktop.
Save rajibmitra/8116189 to your computer and use it in GitHub Desktop.
<?php
date_default_timezone_set('America/Detroit');
//include autoloader to make sure all files are included
include '../autoloader.inc.php';
usergrid_autoload('Apigee\\Usergrid\\Client');
//initialize the SDK
$client = new Apigee\Usergrid\Client('crainsdetroit','cdbapp');
//Need to login before doing anything for the sake of permissions
$client->login("USERNAME","PASSWORD");
//reading data
$books = $client->get_collection('books');
//do something with the data
while ($books->has_next_entity()) {
$book = $books->get_next_entity();
$title = $book->get('title');
echo "Next Book's title is: " . $title . "<br>";
}
//writing data
$data = array('title' => 'the old man and the sea', 'type' => 'books');
$book = $books->add_entity($data);
if ($book == FALSE) {
echo 'write failed';
echo var_dump($book);
} else {
echo 'write succeeded';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment