You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by ro...@apache.org on 2014/11/12 02:15:34 UTC

[29/45] incubator-usergrid git commit: Started on better examples and added to read me that the responses returned from Api calls are PHP Collections so they have all collection methods get(), hasKey(), hasValue(), fetch(), map(), merge(), splice(), etc.

Started on better examples and added to read me that the responses returned from Api calls are PHP Collections so they have all collection methods get(), hasKey(), hasValue(), fetch(), map(), merge(), splice(), etc. so not to mistake Usergrid collection (db table) with response collection which are all subclasses of the BaseCollection class.


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/ba63705d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/ba63705d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/ba63705d

Branch: refs/heads/master
Commit: ba63705d36311547ca9d655b1f6a7d979379cb4a
Parents: 9f25f36
Author: Jason Kristian <ja...@apps4u.com.au>
Authored: Sun Nov 2 18:07:05 2014 +1000
Committer: Jason Kristian <ja...@apps4u.com.au>
Committed: Sun Nov 2 18:07:05 2014 +1000

----------------------------------------------------------------------
 .../Examples/collections/books.php              | 124 ++++++++++
 .../Examples/collections/data.php               |  38 +++
 .../Examples/collections/users.php              |  65 +++++
 sdks/php5/apache-usergrid/Examples/examples.php | 244 +++++++++++++++++++
 sdks/php5/apache-usergrid/README.md             |   6 +-
 sdks/php5/apache-usergrid/examples.php          | 244 -------------------
 .../src/Api/Models/GuzzleCommandTrait.php       |   2 +-
 7 files changed, 477 insertions(+), 246 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ba63705d/sdks/php5/apache-usergrid/Examples/collections/books.php
----------------------------------------------------------------------
diff --git a/sdks/php5/apache-usergrid/Examples/collections/books.php b/sdks/php5/apache-usergrid/Examples/collections/books.php
new file mode 100644
index 0000000..83bc884
--- /dev/null
+++ b/sdks/php5/apache-usergrid/Examples/collections/books.php
@@ -0,0 +1,124 @@
+<?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;
+
+/** 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', // set manifest version
+        'orgName' => '',
+        'appName' => '',
+        'manifestPath' => null, //leave as default or change to your own custom folder
+        'clientId' => '',
+        'clientSecret' => '',
+        'username' => '',
+        'password' => '',
+        /**
+         * The Auth Type setting is the Oauth 2 end point you want to get the OAuth 2
+         * Token from.  You have two options here one is 'application' the other is 'organization'
+         *
+         *  organization will get the the token from http://example.com/management using  client_credentials or password grant type
+         *  application will get the token from http://example.com/managment/org_name/app_name using client_credentials or password grant type
+         */
+        'auth_type' => 'organization',
+        /** The Grant Type to use
+         *
+         * This has to be set to one of the 2 grant types that Apache Usergrid
+         * supports which at the moment is client_credentials or password but at
+         * 2 level organization or application
+         */
+        'grant_type' => 'client_credentials',
+        /**
+         * if you want to manage your own auth flow by calling the token api and setting the token your self just set this to false
+         * */
+        '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->count());
+
+
+// As responses are model object you can treat them like a assoc arrays
+var_dump($books[0]['uuid']);
+
+// if you like a more object orientated way then use the Collection Class methods
+
+// get all uuid
+var_dump($books->fetch('uuid'));
+
+// get first item in collection -- this is the first item in my response php collection not the Usergrid Collection (table).
+var_dump($books->first());
+
+// get last item in collection -- this is the last item in my response php collection not the Usergrid Collection (table).
+var_dump($books->last());
+
+
+
+// Illuminate\Support\Collection class support all advanced collection methods
+
+// pop last item off collection
+$book = $books->pop();
+
+// Converting methods
+$json_ = $books->toJson();
+
+//Convert the object into something JSON serializable.
+$books->jsonSerialize();
+
+// Get an iterator for the items in collection
+$iterator = $books->getIterator();
+
+
+
+/// Here are some more Methods that you can call on your responses .. To get the most out of this SDK please look at the Illuminate\Support\Collection class
+/// which is the supper class of Apache/Usergrid/Api/Models/BaseCollection class
+/**
+    $books->unique();
+    $books->transform();
+    $books->take();
+    $books->splice();
+    $books->sum($callback );
+    $books->values();
+    $books->sortByDesc($callback);
+    $books->sortBy();
+    $books->shuffle();
+    $books->chunk();
+ */
+

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ba63705d/sdks/php5/apache-usergrid/Examples/collections/data.php
----------------------------------------------------------------------
diff --git a/sdks/php5/apache-usergrid/Examples/collections/data.php b/sdks/php5/apache-usergrid/Examples/collections/data.php
new file mode 100644
index 0000000..a926dbe
--- /dev/null
+++ b/sdks/php5/apache-usergrid/Examples/collections/data.php
@@ -0,0 +1,38 @@
+<?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.
+ */
+
+$books_data = [
+['collection' => 'books', 'title' => 'book one', 'name' => 'book_one', 'author' => 'author 1'],
+['collection' => 'books', 'title' => 'book two', 'name' => 'book_two', 'author' => 'author 2'],
+['collection' => 'books', 'title' => 'book three', 'name' => 'book_three', 'author' => 'author 3'],
+['collection' => 'books', 'title' => 'book four', 'name' => 'book_four', 'author' => 'author 4'],
+['collection' => 'books', 'title' => 'book five', 'name' => 'book_five', 'author' => 'author 5'],
+['collection' => 'books', 'title' => 'book six', 'name' => 'book_six', 'author' => 'author 6'],
+['collection' => 'books', 'title' => 'book seven', 'name' => 'book_seven', 'author' => 'author 7'],
+['collection' => 'books', 'title' => 'book eight', 'name' => 'book_eight', 'author' => 'author 8'],
+['collection' => 'books', 'title' => 'book nine', 'name' => 'book_nine', 'author' => 'author 9'],
+['collection' => 'books', 'title' => 'book ten', 'name' => 'book_ten', 'author' => 'author 10'],
+['collection' => 'books', 'title' => 'book eleven', 'name' => 'book_eleven', 'author' => 'author 11'],
+['collection' => 'books', 'title' => 'book twelve', 'name' => 'book_twelve', 'author' => 'author 12'],
+['collection' => 'books', 'title' => 'book thirteen', 'name' => 'book_thirteen', 'author' => 'author 13'],
+['collection' => 'books', 'title' => 'book fourteen', 'name' => 'book_fourteen', 'author' => 'author 14'],
+['collection' => 'books', 'title' => 'book fifteen', 'name' => 'book_fifteen', 'author' => 'author 15'],
+['collection' => 'books', 'title' => 'book sixteen', 'name' => 'book_sixteen', 'author' => 'author 16'],
+['collection' => 'books', 'title' => 'book seventeen', 'name' => 'book_seventeen', 'author' => 'author 17'],
+['collection' => 'books', 'title' => 'book eighteen', 'name' => 'book_eighteen', 'author' => 'author 18'],
+['collection' => 'books', 'title' => 'book nineteen', 'name' => 'book_nineteen', 'author' => 'author 19'],
+['collection' => 'books', 'title' => 'book twenty', 'name' => 'book_twenty', 'author' => 'author 20'],
+];

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ba63705d/sdks/php5/apache-usergrid/Examples/collections/users.php
----------------------------------------------------------------------
diff --git a/sdks/php5/apache-usergrid/Examples/collections/users.php b/sdks/php5/apache-usergrid/Examples/collections/users.php
new file mode 100644
index 0000000..a789631
--- /dev/null
+++ b/sdks/php5/apache-usergrid/Examples/collections/users.php
@@ -0,0 +1,65 @@
+<?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;
+
+/** 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', // set manifest version
+        'orgName' => '',
+        'appName' => '',
+        'manifestPath' => null, //leave as default or change to your own custom folder
+        'clientId' => '',
+        'clientSecret' => '',
+        'username' => '',
+        'password' => '',
+        /**
+         * The Auth Type setting is the Oauth 2 end point you want to get the OAuth 2
+         * Token from.  You have two options here one is 'application' the other is 'organization'
+         *
+         *  organization will get the the token from http://example.com/management using  client_credentials or password grant type
+         *  application will get the token from http://example.com/managment/org_name/app_name using client_credentials or password grant type
+         */
+        'auth_type' => 'organization',
+        /** The Grant Type to use
+         *
+         * This has to be set to one of the 2 grant types that Apache Usergrid
+         * supports which at the moment is client_credentials or password but at
+         * 2 level organization or application
+         */
+        'grant_type' => 'client_credentials',
+        /**
+         * if you want to manage your own auth flow by calling the token api and setting the token your self just set this to false
+         * */
+        'enable_oauth2_plugin' => true
+    ]
+];
+
+$bootstrapper = new UsergridBootstrapper($config);
+Usergrid::instance($bootstrapper);
+
+

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ba63705d/sdks/php5/apache-usergrid/Examples/examples.php
----------------------------------------------------------------------
diff --git a/sdks/php5/apache-usergrid/Examples/examples.php b/sdks/php5/apache-usergrid/Examples/examples.php
new file mode 100644
index 0000000..f139808
--- /dev/null
+++ b/sdks/php5/apache-usergrid/Examples/examples.php
@@ -0,0 +1,244 @@
+<?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;
+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', // set manifest version
+        'orgName' => '',
+        'appName' => '',
+        'manifestPath' => './src/Manifests', //leave as default or change to your own custom folder
+        'clientId' => '',
+        'clientSecret' => '',
+        'username' => '',
+        'password' => '',
+        /**
+         * The Auth Type setting is the Oauth 2 end point you want to get the OAuth 2
+         * Token from.  You have two options here one is 'application' the other is 'organization'
+         *
+         *  organization will get the the token from http://example.com/management using  client_credentials or password grant type
+         *  application will get the token from http://example.com/managment/org_name/app_name using client_credentials or password grant type
+         */
+        'auth_type' => 'application',
+        /** The Grant Type to use
+         *
+         * This has to be set to one of the 2 grant types that Apache Usergrid
+         * supports which at the moment is client_credentials or password but at
+         * 2 level organization or application
+         */
+        'grant_type' => 'password',
+        /**
+         * if you want to manage your own auth flow by calling the token api and setting the token your self just set this to false
+         * */
+        '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*/
+
+//find users with query
+$user = $usergrid->users()->find(['ql' => 'select * where activated=true']);
+
+//var_dump($user->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.
+ * Apache\Usergrid\Api\Exception\BadRequestException = http 400
+ * Apache\Usergrid\Api\Exception\UnauthorizedException = http 401
+ * Apache\Usergrid\Api\Exception\RequestFailedException = http 402
+ * Apache\Usergrid\Api\Exception\NotFoundException = http 404
+ * Apache\Usergrid\Api\Exception\ServerErrorException = http 500
+ * Apache\Usergrid\Api\Exception\ServerErrorException = http 502
+ * Apache\Usergrid\Api\Exception\ServerErrorException = http 503
+ * Apache\Usergrid\Api\Exception\ServerErrorException = http 504
+ */
+
+// collection Iterators no need to keep calling request with a cursor to get all entities in a collection
+// UserIterator(), DeviceIterator() GroupsIterator() , RolesIterator() etc.
+$user_iterator = $usergrid->usersIterator();
+
+foreach ($user_iterator as $iUser) {
+    var_dump($iUser);
+    var_dump("---------------------------------------------------------------------------------");
+}
+
+// create new user
+$new_user = ['name' => 'jasonk', 'username' => 'JasonK', 'email' => 'jason@example.com', 'password' => 'some_password'];
+//$created_user = $usergrid->users()->create($new_user);
+//var_dump($created_user);
+
+//Update Users by name or uuid
+$new_email = ['email' => 'jason@example', 'entity_name_or_uuid' => 'benn'];
+$updated_user = $usergrid->users()->update($new_email);
+//var_dump($updated_user);
+
+// delete a user
+//$deleted_user = $usergrid->users()->delete(['entity_name_or_uuid' => 'benn']);
+//var_dump($deleted_user);
+
+//get custom collection
+$custom_collection = $usergrid->application()->EntityGet(['collection' => 'shops']);
+//var_dump($custom_collection->get('entities'));
+
+//get custom collection with query
+$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);
+
+// 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' => 'jaso2n@example.com',
+    'password' => 'some_password'
+];
+$fCreated_user = Usergrid::users()->create($fNew_user);
+//var_dump($fCreated_user);
+
+//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);
+
+// delete a user
+$fDeleted_user = Usergrid::users()->delete(['entity_name_or_uuid' => 'benn']);
+//var_dump($fDeleted_user);
+
+//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('entities'));
+
+// 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);
+
+// 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);
+
+
+
+/** 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);
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ba63705d/sdks/php5/apache-usergrid/README.md
----------------------------------------------------------------------
diff --git a/sdks/php5/apache-usergrid/README.md b/sdks/php5/apache-usergrid/README.md
index f4787d4..61e8869 100644
--- a/sdks/php5/apache-usergrid/README.md
+++ b/sdks/php5/apache-usergrid/README.md
@@ -92,7 +92,10 @@ the aliases array ```'Usergrid' => 'Apache\Usergrid\Laravel\Facades\Usergrid```
  and they are cached by the Usergrid web service client. Calls on the Usergrid client are like magic method in the sense that ```php Usergrid::Management()-> method``` call is not
  backed by a Management class or method its the Manifest that it being selected . Also by using Facades all method are like static method and fit in with newer PHP frameworks just like using the
  AWS PHP SDK when calling enableFacades() on the AWS factory method.
- 
+  
+ All responses are subclasses of Illuminate\Support\Collection class so all collection methods are available to call on your response model eg: first(), get(), map(), fetch(), hasKey(), hasValue(), etc.
+ this is not to mistake this with a Usergrid collection which is like your DB table they too are collection object but if you get a response of a single entiry then its a Collection with a count of 1.
+  
 ### Error Handling ### 
 All HTTP and Server error returned by the Usergrid API have error classes attached to the services descriptors so to handle error's that you want too, Just catch the correct exception eg. resource not found.
 
@@ -144,6 +147,7 @@ foreach($allDevices as $device) {
 // this will have all devices. 
 }
 ```
+
 ### HTTP headers and UserAgents ###
  When working with http clients & server system you may want to sett additional HTTP Headers. Ive have made this easy as well on the Usergrid class you 
  can set any http headers or access token or user agent when calling the set method it will append new headers or replace headers already set so if you 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ba63705d/sdks/php5/apache-usergrid/examples.php
----------------------------------------------------------------------
diff --git a/sdks/php5/apache-usergrid/examples.php b/sdks/php5/apache-usergrid/examples.php
deleted file mode 100644
index f139808..0000000
--- a/sdks/php5/apache-usergrid/examples.php
+++ /dev/null
@@ -1,244 +0,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;
-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', // set manifest version
-        'orgName' => '',
-        'appName' => '',
-        'manifestPath' => './src/Manifests', //leave as default or change to your own custom folder
-        'clientId' => '',
-        'clientSecret' => '',
-        'username' => '',
-        'password' => '',
-        /**
-         * The Auth Type setting is the Oauth 2 end point you want to get the OAuth 2
-         * Token from.  You have two options here one is 'application' the other is 'organization'
-         *
-         *  organization will get the the token from http://example.com/management using  client_credentials or password grant type
-         *  application will get the token from http://example.com/managment/org_name/app_name using client_credentials or password grant type
-         */
-        'auth_type' => 'application',
-        /** The Grant Type to use
-         *
-         * This has to be set to one of the 2 grant types that Apache Usergrid
-         * supports which at the moment is client_credentials or password but at
-         * 2 level organization or application
-         */
-        'grant_type' => 'password',
-        /**
-         * if you want to manage your own auth flow by calling the token api and setting the token your self just set this to false
-         * */
-        '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*/
-
-//find users with query
-$user = $usergrid->users()->find(['ql' => 'select * where activated=true']);
-
-//var_dump($user->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.
- * Apache\Usergrid\Api\Exception\BadRequestException = http 400
- * Apache\Usergrid\Api\Exception\UnauthorizedException = http 401
- * Apache\Usergrid\Api\Exception\RequestFailedException = http 402
- * Apache\Usergrid\Api\Exception\NotFoundException = http 404
- * Apache\Usergrid\Api\Exception\ServerErrorException = http 500
- * Apache\Usergrid\Api\Exception\ServerErrorException = http 502
- * Apache\Usergrid\Api\Exception\ServerErrorException = http 503
- * Apache\Usergrid\Api\Exception\ServerErrorException = http 504
- */
-
-// collection Iterators no need to keep calling request with a cursor to get all entities in a collection
-// UserIterator(), DeviceIterator() GroupsIterator() , RolesIterator() etc.
-$user_iterator = $usergrid->usersIterator();
-
-foreach ($user_iterator as $iUser) {
-    var_dump($iUser);
-    var_dump("---------------------------------------------------------------------------------");
-}
-
-// create new user
-$new_user = ['name' => 'jasonk', 'username' => 'JasonK', 'email' => 'jason@example.com', 'password' => 'some_password'];
-//$created_user = $usergrid->users()->create($new_user);
-//var_dump($created_user);
-
-//Update Users by name or uuid
-$new_email = ['email' => 'jason@example', 'entity_name_or_uuid' => 'benn'];
-$updated_user = $usergrid->users()->update($new_email);
-//var_dump($updated_user);
-
-// delete a user
-//$deleted_user = $usergrid->users()->delete(['entity_name_or_uuid' => 'benn']);
-//var_dump($deleted_user);
-
-//get custom collection
-$custom_collection = $usergrid->application()->EntityGet(['collection' => 'shops']);
-//var_dump($custom_collection->get('entities'));
-
-//get custom collection with query
-$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);
-
-// 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' => 'jaso2n@example.com',
-    'password' => 'some_password'
-];
-$fCreated_user = Usergrid::users()->create($fNew_user);
-//var_dump($fCreated_user);
-
-//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);
-
-// delete a user
-$fDeleted_user = Usergrid::users()->delete(['entity_name_or_uuid' => 'benn']);
-//var_dump($fDeleted_user);
-
-//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('entities'));
-
-// 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);
-
-// 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);
-
-
-
-/** 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);
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ba63705d/sdks/php5/apache-usergrid/src/Api/Models/GuzzleCommandTrait.php
----------------------------------------------------------------------
diff --git a/sdks/php5/apache-usergrid/src/Api/Models/GuzzleCommandTrait.php b/sdks/php5/apache-usergrid/src/Api/Models/GuzzleCommandTrait.php
index f8bd6fa..5a6c57a 100644
--- a/sdks/php5/apache-usergrid/src/Api/Models/GuzzleCommandTrait.php
+++ b/sdks/php5/apache-usergrid/src/Api/Models/GuzzleCommandTrait.php
@@ -39,7 +39,7 @@ trait GuzzleCommandTrait
     public static function fromCommand(OperationCommand $command)
     {
         // Initialize the collection
-        $collection = new self($command->getResponse()->json());
+        $collection = new self($command->getResponse()->json()['entities']);
 
         // Set the Usergrid API client on the collection
         $collection->setApiClient($command->getClient()->getApiClient());