usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [4/5] git commit: Added get_entity_id, connect, disconnect, get_connections, and get_connecting to Entity
Date Sat, 01 Feb 2014 20:20:40 GMT
Added get_entity_id, connect, disconnect, get_connections, and get_connecting to Entity


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

Branch: refs/pull/45/head
Commit: 0f7c144b08b00358829f96b08aa0afc043e01197
Parents: 11917f2
Author: ryan bridges <rbridges@apigee.com>
Authored: Sat Feb 1 14:52:24 2014 -0500
Committer: ryan bridges <rbridges@apigee.com>
Committed: Sat Feb 1 14:52:24 2014 -0500

----------------------------------------------------------------------
 sdks/php/lib/vendor/Apigee/Usergrid/Entity.php | 90 +++++++++++++++++++--
 1 file changed, 84 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0f7c144b/sdks/php/lib/vendor/Apigee/Usergrid/Entity.php
----------------------------------------------------------------------
diff --git a/sdks/php/lib/vendor/Apigee/Usergrid/Entity.php b/sdks/php/lib/vendor/Apigee/Usergrid/Entity.php
index 6dc970c..d69b1c7 100755
--- a/sdks/php/lib/vendor/Apigee/Usergrid/Entity.php
+++ b/sdks/php/lib/vendor/Apigee/Usergrid/Entity.php
@@ -200,19 +200,97 @@ class Entity {
   }
 
   public function connect($connection, $entity) {
-    // TODO
+    $connectee=Entity::get_entity_id($entity);
+    $connecteeType=$entity->get("type");
+    if(!$connectee){
+      return "Error in connect. No UUID specified for connectee";
+    }
+
+    $connector=Entity::get_entity_id($this);
+    $connectorType=$this->get("type");
+    if(!$connector){
+      return "Error in connect. No UUID specified for connector";
+    }
+
+    $endpoint = $connectorType.'/'.$connector.'/'.$connection.'/'.$connecteeType.'/'.$connectee;
+    $result=$this->client->post($endpoint, array(), array());
+    $error=$result->get_error();
+    if($error){
+      return $result->get_error_message();
+    }else{
+      return $result->get_data();
+    }
+  }
+
+  public function disconnect($connection, $entity) {
+    $connectee=Entity::get_entity_id($entity);
+    $connecteeType=$entity->get("type");
+    if(!$connectee){
+      return "Error in disconnect. No UUID specified for connectee";
+    }
+
+    $connector=Entity::get_entity_id($this);
+    $connectorType=$this->get("type");
+    if(!$connector){
+      return "Error in disconnect. No UUID specified for connector";
+    }
+
+    $endpoint = $connectorType.'/'.$connector.'/'.$connection.'/'.$connecteeType.'/'.$connectee;
+
+    $result=$this->client->delete($endpoint, array(), array());
+    $error=$result->get_error();
+    if($error){
+      return $result->get_error_message();
+    }else{
+      return $result->get_data();
+    }
   }
 
   public static function get_entity_id($entity) {
-    // TODO
+      $id = false;
+      if (Client::is_uuid($entity->get('uuid'))) {
+        $id = $entity->get('uuid');
+      } else {
+        if ($type == 'users') {
+          $id = $entity->get('username');
+        } else if ($entity->get('name')) {
+          $id = $entity->get('name');
+        }
+      }
+      return $id;
   }
 
   public function get_connections($connection) {
-    // TODO
+    $connectorType = $this->get('type');
+    $connector = Entity::get_entity_id($this);
+    if (!$connector) {
+      return;
+    }
+
+    $endpoint = $connectorType . '/' . $connector . '/' . $connection . '/';
+    $result=$this->client->get($endpoint, array());
+    $this->set($connection,array());
+
+    $length = count($result->entities);
+    for ($i = 0; i < $length; $i++) {
+      if ($result['entities'][i]['type'] == 'user') {
+        $this[$connection][$result['entities'][i]['username']] = $result['entities'][i];
+      } else {
+        $this[$connection][$result['entities'][i]['name']] = $result['entities'][i];
+      }
+    }
   }
 
-  public function disconnect($connection, $entity) {
-    // TODO
+  public function get_connecting($connection) {
+    $connectorType = $this->get('type');
+    $connector = Entity::get_entity_id($this);
+    if (!$connector) {
+      return;
+    }
+
+    $endpoint = $connectorType. '/' . $connector . '/connecting/' . $connection . '/';
+    $result=$this->client->get($endpoint, array());
+    return $result->get_data();
   }
 
-}
\ No newline at end of file
+}


Mime
View raw message