Ejemplo n.º 1
0
use Apache\Usergrid\Native\UsergridBootstrapper;
use Apache\Usergrid\Native\Facades\Usergrid;
/**
 * When working with the management api any calls that require a application to target will use the default app name set in the config but some times you may want to
 * make a api call to a different application which is possible when the url requires a application name it taken from the config but if you pass in a different application
 * name in the method arguments it will override the default application name just for that api call so If I wanted to add a user to two application I could make the same call
 * twice but pass in a application name only for the 2nd call.
 */
/** 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);
// Get organization activity
$activity_feed = Usergrid::management()->OrgFeedGet();
// get org details
$organization_details = Usergrid::management()->OrgGet();
//get organizations application
$organization_applications = Usergrid::management()->OrgAppsGet();
//create application
$app = ['name' => 'app name -- required'];
$new_application = Usergrid::management()->OrgAppsJsonPost($app);
// delete application
$deleted_application = Usergrid::management()->OrgAppDelete($app);
//get irg admin users
$organization_admin_users = Usergrid::management()->OrgUsersGet();
/** There are many more api calls just look at the management manifest file to get the method name's and arguments to pass .
 * The management manifest file is a copy of the swagger file for usergrid so you can also run the swagger UI tool on your usergrid install as well.
 */
Ejemplo n.º 2
0
 *  That's all you need to do to get a device for the user this only works when you have one user in your user collection
 *  if you call this with more then one user in your user collection it will return the device for the first user in the
 *  collection.
 *
 */
$user = Usergrid::users()->findById(['uuid' => '1234abcd']);
echo "device" . PHP_EOL;
var_dump($user->device);
var_dump('=================================================================');
echo "roles" . PHP_EOL;
var_dump($user->roles);
var_dump('=================================================================');
echo "groups" . PHP_EOL;
var_dump($user->groups);
var_dump('=================================================================');
echo "connections" . PHP_EOL;
var_dump($user->connections);
var_dump('=================================================================');
var_dump('=================================================================');
echo "GROUPS" . PHP_EOL;
var_dump('=================================================================');
$group = Usergrid::groups()->findById(['uuid' => '121212']);
echo "roles" . PHP_EOL;
var_dump($group->roles);
var_dump('=================================================================');
echo "groups" . PHP_EOL;
var_dump($group->users);
var_dump('=================================================================');
echo "connections" . PHP_EOL;
var_dump($group->connections);
var_dump('=================================================================');
Ejemplo n.º 3
0
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * or in the "license" file accompanying this file. This file is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */
include 'vendor/autoload.php';
include 'data.php';
use Apache\Usergrid\Native\Facades\Usergrid;
use Apache\Usergrid\Native\UsergridBootstrapper;
/** 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' => './src/Manifests', 'clientId' => '', 'clientSecret' => '', 'username' => null, 'password' => null, 'auth_type' => 'organization', 'grant_type' => 'client_credentials', 'enable_oauth2_plugin' => true]];
// You need to add a push cert to this folder and pass the path in the apple_notifier_data array
$bootstrapper = new UsergridBootstrapper($config);
Usergrid::instance($bootstrapper);
//create Apple Notifier
$apple_notifier_data = ['name' => 'apple_test', 'environment' => 'development', 'p12Certificate' => @'pushtest_dev.p12'];
$apple_notifier = Usergrid::notifiers()->createApple($apple_notifier_data);
// create Google Notifier
$google_notifier_data = ['name' => 'google_test', 'apiKey' => 'AIzaSyCIH_7WC0mOqBGMOXyQnFgrBpOePgHvQJM', 'provider' => 'google'];
$google_notifier = Usergrid::notifiers()->createGoogle($google_notifier_data);
Ejemplo n.º 4
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()));
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * or in the "license" file accompanying this file. This file is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */
include 'vendor/autoload.php';
include 'data.php';
use Apache\Usergrid\Native\UsergridBootstrapper;
use Apache\Usergrid\Native\Facades\Usergrid;
/** 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);
// to user
$to_user = Usergrid::notifications()->toUser();
//to users
$to_users = Usergrid::notifications()->toUsers();
//to group
$to_group = Usergrid::notifications()->toGroup();
// to groups
$to_groups = Usergrid::notifications()->toGroups();
// to device
$to_device = Usergrid::notifications()->toDevice();
// to devices
$to_devices = Usergrid::notifications()->toDevices();
Ejemplo n.º 6
0
$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);
Ejemplo n.º 7
0
<?php

/**
 * Copyright 2010-2014 baas-platform.com, Pty Ltd. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * or in the "license" file accompanying this file. This file is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */
include 'vendor/autoload.php';
include 'data.php';
use Apache\Usergrid\Native\UsergridBootstrapper;
use Apache\Usergrid\Native\Facades\Usergrid;
/** 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);
Ejemplo n.º 8
0
    //    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();
var_dump($users_nested->entities->fetch('metadata.collections.devices')->first());
// The response that is returned is a PHP collection that has a Zero indexed $item property.
// but as its a collection class it has some methods that can help you find what you need and one
// of my fav feature is changing the Zero indexed collection to be indexed by the entity uuid or name or any other property.
$users_by = Usergrid::users()->all();
$users_by_uuid = $users_by->entities->keyBy('uuid');
var_dump($users_by_uuid->get('add uuid of user'));
$users_by_name = $users_by->entities->keyBy('username');
var_dump($users_by_name->get('jasonk'));
$users_by_email = $users_by->entities->keyBy('email');
var_dump($users_by_email->get('*****@*****.**'));
// sort by key
$sorted_by_email = $users_by->sortBy('username');
var_dump($sorted_by_email);
// add user to group
//$user_to_group = Usergrid::groups()->addUser(['entity_name_or_uuid' => 'group_name_or_uuid', 'user_name_or_uuid' => 'user name or uuid']);
//$user_remove_group = Usergrid::groups()->removeUser(['entity_name_or_uuid' => 'group_name_or_uuid', 'user_name_or_uuid' => 'user name or uuid']);
Ejemplo n.º 9
0
 */
$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();
var_dump($users_nested->entities->fetch('metadata.collections.devices')->first());
// add user to group
//$user_to_group = Usergrid::groups()->addUser(['entity_name_or_uuid' => 'group_name_or_uuid', 'user_name_or_uuid' => 'user name or uuid']);
//$user_remove_group = Usergrid::groups()->removeUser(['entity_name_or_uuid' => 'group_name_or_uuid', 'user_name_or_uuid' => 'user name or uuid']);