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:47 UTC

[42/45] incubator-usergrid git commit: fixed read me as it had some method calls that were changed . added a few more examples just to show that the results as PHP collections and that all collection type methods can be called in a fluent way e.g.: $user

fixed read me as it had some method calls that were changed .
added a few more examples just to show that the results as PHP collections and that all collection type methods can be called in a fluent way e.g.:
$users =  Usergrid::users()-all();
$user->entities->fetch('uuid')->first();


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

Branch: refs/heads/master
Commit: a9fbc73407933694c8b3527ed9d710f47419a149
Parents: 08ad23a
Author: Jason Kristian <ja...@apps4u.com.au>
Authored: Tue Nov 11 12:32:31 2014 +1000
Committer: Jason Kristian <ja...@apps4u.com.au>
Committed: Tue Nov 11 12:32:31 2014 +1000

----------------------------------------------------------------------
 .../Examples/collections/books.php               |  7 ++++++-
 .../Examples/collections/users.php               |  6 +++---
 sdks/php5/apache-usergrid/README.md              | 19 ++++++++++++-------
 3 files changed, 21 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a9fbc734/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
index 34ee501..e2d31ae 100644
--- a/sdks/php5/apache-usergrid/Examples/collections/books.php
+++ b/sdks/php5/apache-usergrid/Examples/collections/books.php
@@ -19,6 +19,7 @@ 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 */
 
@@ -83,13 +84,17 @@ var_dump($books->entities[0]['uuid']);
 // 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()));
 
 // Illuminate\Support\Collection class support all advanced collection methods
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a9fbc734/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
index eb99fdd..34a897d 100644
--- a/sdks/php5/apache-usergrid/Examples/collections/users.php
+++ b/sdks/php5/apache-usergrid/Examples/collections/users.php
@@ -81,15 +81,15 @@ foreach($all_users as $user) {
 $find_user_by_query = Usergrid::users()->find(['ql' => "select * where email='jason@apps4u.com.au'"]);
 var_dump($find_user_by_query->entities->fetch('uuid'));
 
-$find_user_by_uuid = Usergrid::users()->findById(['uuid' => $find_user_by_query->entities->fetch('uuid')[0]]);
+$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 propery is always returned as a PHP Collection you can fetch nested records
+// 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.street');
+echo $user_addr->entities->fetch('adr.city');
 
 // 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']);

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a9fbc734/sdks/php5/apache-usergrid/README.md
----------------------------------------------------------------------
diff --git a/sdks/php5/apache-usergrid/README.md b/sdks/php5/apache-usergrid/README.md
index cd22247..54d4e8f 100644
--- a/sdks/php5/apache-usergrid/README.md
+++ b/sdks/php5/apache-usergrid/README.md
@@ -78,22 +78,22 @@ then add your client_id and secret to the config file the set the service provid
 the aliases array ```'Usergrid' => 'Apache\Usergrid\Laravel\Facades\Usergrid``` to be able to access class via a Facade. Example for Laravel
 
 ```
-    $collection = Usergrid::application()->getEntity(['collection' => 'shops']);
+    $collection = Usergrid::application()->EntityGet(['collection' => 'shops']);
 ```
 
 ## how it works
 
  You have one main client called Usergrid so if I wanted to call the Management Api and I have Facades enabled then
- I would call like this ```Usergrid::Management->getApps();``` or ```Usergrid::Application->getEntity();```
+ I would call like this ```Usergrid::Management->OrgAppsGet();``` or ```Usergrid::Application->EntityGet();```
  
  There is one top level manifest file called Manifest.php and contain only top level Guzzle service descriptor properties and a empty operations array so 
- when calling ```php Usergrid::Management()->getEntity() ```  the Main Manifest file has the operation array filled in by the Management Manifest files operations array
+ when calling ```php Usergrid::Management()->OrgAppsGet() ```  the Main Manifest file has the operation array filled in by the Management Manifest files operations array
  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.
+ 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 entity then its a Collection with a count of 1.
  
  
  
@@ -134,10 +134,15 @@ All HTTP and Server error returned by the Usergrid API have error classes attach
  
 So there are two settings in the config that controls which type of token you get.
 the ```'auth_type' => 'application' ``` controls the level you get Organization or Application and the ``` 'grant_type' => 'client_credentials'``` controls
-which type of credentials you use which can be either client_id & client_secret or username & password.
+which type of credentials you use which can be either `client_credentials` or `password` using client_id & client_secret or username & password.
 
 ### Result Iteration
-Apache Usergrid has a default paging size of 10 records so if you ask for a collection that has more then 10 result (entities) then it will return a Cursor so you can pass it to the next request to get then next lot of 10 results so Ive made this easier. Using manifest version 1.0.1 and above you can now use a resource iterator that will return all entities for you in one request. So again let the SDK do the hard work for you. Resource Iterators as lazy loaded so they only make the api call if the data is needed for example when you first make the call no data is requested from the network but as soon as you dereference the data then the first page is requested and the 2nd page is not requested till you request the data for example if I used it in a foreach loop it will make a network request for the next page of data only after the loop has gone through the current page count and if you cancel the foreach loop then it wont request any more data the default page size is 20 for resou
 rce iterators.
+Apache Usergrid has a default paging size of 10 records so if you ask for a collection that has more then 10 result (entities) then it will return 
+a Cursor so you can pass it to the next request to get then next lot of 10 results so Ive made this easier. Using manifest version 1.0.1 and above you can now use a resource iterator  
+that will return all entities for you in one request. So again let the SDK do the hard work for you. Resource Iterators as lazy loaded so they only make the api call if the data is needed 
+for example when you first make the call no data is requested from the network but as soon as you dereference the data then the first page is requested and the 2nd page is not requested till
+you request the data for example if I used it in a foreach loop it will make a network request for the next page of data only after the loop has gone through the current page count and if you cancel the 
+foreach loop then it wont request any more data the default page size is 20 for resource iterators.
 
 The SDK will check each response to see if their is a cursor and if there is it will get the next set till all entities are returned.
 ```
@@ -187,4 +192,4 @@ of it as a helper as some times it good to have access to both world server side
 * Writing tests
 * Code review
 * Code
-* Manifest files
+* Manifest files
\ No newline at end of file