예제 #1
0
$custom_collection_query = $usergrid->application()->EntityGet(['collection' => 'shops', 'ql' => "select * where country='aus'"]);
//var_dump($custom_collection_query->get('entities'));
// Post custom collection as JSON data
$custom_entity = ['collection' => 'shops', 'name' => 'shop_name', 'adr' => ['street' => '1 main st', 'location' => 'sydney', 'post_code' => '2323'], 'type' => 'pet_shop'];
//$created_entity = $usergrid->application()->EntityJsonPost($custom_entity);
//var_dump($created_entity->entities);
// update custom Entity
$custom_entity_edit = ['collection' => 'shops', 'entity_name_or_uuid' => '918a044a-618a-11e4-8c11-253e9c3723a9', ['adr' => ['street' => '3 main st', 'location' => 'act', 'post_code' => '3323']]];
$edited_entity = $usergrid->application()->EntityPut($custom_entity_edit);
/** Usergrid Facades On */
//create a bootstrap instance and then call the static instance method on the Usergrid facade
$bootstrapper2 = new UsergridBootstrapper($config);
Usergrid::instance($bootstrapper2);
// find users with query
$fUser = Usergrid::users()->find(['ql' => 'select * where activated=true']);
$fUser_iterator = Usergrid::usersIterator();
foreach ($fUser_iterator as $iUser) {
    var_dump($iUser);
    var_dump("---------------------------------------------------------------------------------");
}
// create new user
$fNew_user = ['name' => 'jasonk', 'username' => 'JasonK2', 'email' => '*****@*****.**', 'password' => 'some_password'];
$fCreated_user = Usergrid::users()->create($fNew_user);
//var_dump($fCreated_user->entities);
//Update Users by name or uuid
$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);
예제 #2
0
/** 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);
// call user by page size 20
$users_paged = Usergrid::users()->all();
var_dump(get_class($users_paged->entities));
//// get user 50 page size
$users_paged_50 = Usergrid::users()->all(['limit' => 50]);
var_dump($users_paged_50->entities);
// get all users
$all_users = Usergrid::usersIterator();
foreach ($all_users as $user) {
    //    var_dump($user['uuid']); // as array
}
// find user by query
$find_user_by_query = Usergrid::users()->find(['ql' => "select * where email='*****@*****.**'"]);
var_dump($find_user_by_query->entities->fetch('uuid'));
$find_user_by_uuid = Usergrid::users()->findById(['uuid' => $find_user_by_query->entities->fetch('uuid')->first()]);
var_dump($find_user_by_uuid->entities);
// AS all results as PHP Collections and the entities property is always returned as a PHP Collection you can fetch nested records
$user_addr = Usergrid::users()->findById(['uuid' => 'Jason']);
echo $user_addr->entities->fetch('adr.addr1');
//or
echo $user_addr->entities->fetch('adr.city');
// get users device URL -- nested fetch on php collection
$users_nested = Usergrid::users()->all();