예제 #1
0
 /**
  * Constructor.
  *
  * @param  \Apache\Usergrid\Native\UsergridBootstrapper $bootstraper
  * @return \Apache\Usergrid\Native\Facades\Usergrid
  */
 public function __construct(UsergridBootstrapper $bootstraper = null)
 {
     if (!$bootstraper) {
         $bootstraper = new UsergridBootstrapper();
     }
     $this->usergrid = $bootstraper->createUsergrid();
 }
예제 #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';
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' => '', 'password' => '', 'auth_type' => 'application', 'grant_type' => 'password', 'enable_oauth2_plugin' => true]];
/** Usergrid Facades Off */
//call the bootstrap class that will create the api client then get the usergrid instance from the bootstrapper
$bootstrapper = new UsergridBootstrapper($config);
$usergrid = $bootstrapper->createUsergrid();
/** Note: I'm using Users for the first lot of example's but you could do the same for all default collections eg: groups, devices, roles, notification etc*/
// All responses are model objects that subclass the baseCollection class so all collection methods are available eg: first(), map(), fetch(), hasValue(), hasKey() etc.
//find users with query
$user = $usergrid->users()->find(['ql' => 'select * where activated=true']);
//var_dump($user->entities->first());
//request that throw exception in this case 404 not found
try {
    $user2 = $usergrid->users()->findById(['uuid' => 'uuid-number']);
    //    var_dump($user2->get('entities'));
} catch (Apache\Usergrid\Api\Exception\NotFoundException $e) {
    //    var_dump($e->getResponse());
}
/**
 * There a errors for all Usergrid response errors and http errors so you can create a catch all error class or plug it into your fav php frameworks error handling.
예제 #3
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';
use Apache\Usergrid\Native\UsergridBootstrapper;
$config = ['usergrid' => ['url' => 'https://api.usergrid.com', 'version' => '1.0.1', 'orgName' => null, 'appName' => null, 'manifestPath' => null, 'clientId' => null, 'clientSecret' => null, 'username' => null, 'password' => null, 'auth_type' => 'organization', 'grant_type' => 'client_credentials', 'enable_oauth2_plugin' => true]];
$boot = new UsergridBootstrapper($config);
$usergrid = $boot->createUsergrid();