Exemplo n.º 1
0
include 'data.php';
use Apache\Usergrid\Native\UsergridBootstrapper;
use Apache\Usergrid\Native\Facades\Usergrid;
use Apache\Usergrid\Api\Filters\Date;
/** The PHP SDK returns all responses as Illuminate\Support\Collection subclasses so the word collection below is php collection class not usergrid collection */
/** Source your config from file I'm using array here just for ease of use.
 * When using Laravel Framework publish the package config file when using with
 * other modern PHP frameworks just use their default config system .
 */
$config = ['usergrid' => ['url' => 'https://api.usergrid.com', 'version' => '1.0.1', 'orgName' => '', 'appName' => '', 'manifestPath' => null, 'clientId' => '', 'clientSecret' => '', 'username' => '', 'password' => '', 'auth_type' => 'organization', 'grant_type' => 'client_credentials', 'enable_oauth2_plugin' => true]];
$bootstrapper = new UsergridBootstrapper($config);
Usergrid::instance($bootstrapper);
foreach ($books_data as $book) {
    Usergrid::application()->EntityJsonPost($book);
}
$books = Usergrid::application()->EntityGet(['collection' => 'books', 'limit' => 25]);
// get result count just call the Illuminate\Support\Collection  count method
var_dump($books->entities->count());
// As responses are model object you can treat them like a assoc arrays
var_dump($books->entities[0]['uuid']);
// if you like a more object orientated way then use the Collection Class methods
// get all uuid
var_dump($books->entities->fetch('uuid'));
//get first uuid
var_dump($books->entities->fetch('uuid')->first());
// get first item in collection -- this is the first item in my response php collection not the Usergrid Collection (table).
var_dump($books->entities->first());
// get last item in collection -- this is the last item in my response php collection not the Usergrid Collection (table).
var_dump($books->entities->last());
// convert created date to string
var_dump(Date::convert($books->entities->fetch('created')->first()));
Exemplo n.º 2
0
$fNew_email = ['email' => 'jason@example', 'entity_name_or_uuid' => 'benn'];
$fUpdated_user = Usergrid::users()->update($fNew_email);
//var_dump($fUpdated_user->entities);
// delete a user
$fDeleted_user = Usergrid::users()->delete(['entity_name_or_uuid' => 'benn']);
//var_dump($fDeleted_user->entities);
//get custom collection
$fCustom_collection = Usergrid::application()->EntityGet(['collection' => 'shops']);
//var_dump($custom_collection->get('entities'));
//get custom collection with query
$fCustom_collection_query = Usergrid::application()->EntityGet(['collection' => 'shops', 'ql' => "select * where country='aus'"]);
//var_dump($custom_collection_query->get('name'));
// Post custom collection as JSON data
$fCustom_entity = ['collection' => 'shops', 'name' => 'shop_name3', 'adr' => ['street' => '1 main st', 'location' => 'sydney', 'post_code' => '2323'], 'type' => 'pet_shop'];
$fCreated_entity = Usergrid::applictions()->EntityJsonPost($custom_entity);
//var_dump($fCreated_entity->entities);
// update entity
$fCustom_entity_edit = ['collection' => 'shops', 'entity_name_or_uuid' => 'shop_name2', ['adr' => ['street' => '3 main st', 'location' => 'act', 'post_code' => '3323']]];
$fEdited_entity = Usergrid::applications()->EntityPut($fCustom_entity_edit);
//var_dump($fEdited_entity->entities);
/** Relationships */
$related_data = ['collection' => 'required', 'entity_id' => 'required', 'relationship' => 'required', 'ql' => 'optional'];
$get_relationship = Usergrid::application()->GetRelationship($related_data);
$create_relationship_data = ['collection' => 'required', 'first_entity_id' => 'required', 'relationship' => 'required', 'second_entity_id' => 'required'];
$new_relationship = Usergrid::application()->CreateRelationship($create_relationship_data);
/** Groups  */
//add user to group
$fAdd_user_to_group_data = ['entity_name_or_uuid' => 'group_name', 'user_name_or_uuid' => 'username'];
$fAdded_user_to_group = Usergrid::groups()->addUser($fAdd_user_to_group_data);
//delete user from group
$fDeleted_user_from_group = Usergrid::groups()->deleteUser($fAdd_user_to_group_data);