/**
  * /people/{userId}/{groupId}/{optionalPersonId}
  *
  * examples:
  * /people/john.doe/@all
  * /people/john.doe/@friends
  * /people/john.doe/@self
  */
 public function handleGet(RestRequestItem $requestItem)
 {
     $requestItem->parseUrlWithTemplate(self::$PEOPLE_PATH);
     $parameters = $requestItem->getParameters();
     $optionalPersonId = in_array('personId', $parameters) ? $parameters['personId'] : null;
     $fields = $requestItem->getFieldsWithDefaultValue(self::$DEFAULT_PERSON_FIELDS);
     if ($optionalPersonId || is_object($requestItem->getGroup()) && $requestItem->getGroup()->getType() == 'self') {
         //FIXME same logic as the java code here, but doesn't seem to do much with the optionalPersonId which seems odd
         return $this->service->getPerson($requestItem->getUser(), $requestItem->getGroup(), $fields, $requestItem->getToken());
     }
     return $this->service->getPeople($requestItem->getUser(), $requestItem->getGroup(), $requestItem->getOrderBy(), $requestItem->getFilterBy(), $requestItem->getStartIndex(), $requestItem->getCount(), $fields, $requestItem->getNetworkDistance(), $requestItem->getToken());
 }
 /**
  * /people/{userId}/{groupId}/{appId}
  * - fields={field1, field2}
  *
  * examples:
  * /appdata/john.doe/@friends/app?fields=count
  * /appdata/john.doe/@self/app
  *
  * The post data should be a regular json object. All of the fields vars will
  * be pulled from the values and set on the person object. If there are no
  * fields vars then all of the data will be overridden.
  */
 public function handlePost(RestRequestItem $requestItem)
 {
     $requestItem->parseUrlWithTemplate(self::$APP_DATA_PATH);
     // if no ?fields=foo,bar was specified, we try to guess them from the post data
     $postFields = array();
     if ($requestItem->getPostData() != null) {
         $data = $requestItem->getPostData();
         foreach ($data as $key => $val) {
             $postFields[] = $key;
         }
     }
     return $this->service->updatePersonData($requestItem->getUser(), $requestItem->getGroup(), $requestItem->getFieldsWithDefaultValue($postFields), $requestItem->getPostData(), $requestItem->getAppId(), $requestItem->getToken());
 }
 public function handleMethod(RestRequestItem $requestItem)
 {
     $token = $requestItem->getToken();
     $method = $requestItem->getMethod();
     if ($token->isAnonymous() && $method != 'GET') {
         // Anonymous requests are only allowed to GET data (not create/edit/delete)
         $response = new ResponseItem(BAD_REQUEST, "[{$method}] not allowed for anonymous users", null);
     } elseif ($method == 'GET') {
         $response = $this->handleGet($requestItem);
     } elseif ($method == 'POST') {
         $response = $this->handlePost($requestItem);
     } elseif ($method == 'DELETE') {
         $response = $this->handleDelete($requestItem);
     } elseif ($method == 'PUT') {
         $response = $this->handlePut($requestItem);
     } else {
         $response = new ResponseItem(BAD_REQUEST, "Unserviced Http method type", null);
     }
     return $response;
 }
 /**
  * Tests RestRequestItem->getToken()
  */
 public function testGetToken()
 {
     $this->assertEquals($this->getToken(), $this->RestRequestItem->getToken());
 }
 /**
  * /activities/{userId}/@self
  *
  * examples:
  * /activities/@viewer/@self/@app
  * /activities/john.doe/@self
  * - postBody is an activity object
  */
 public function handlePost(RestRequestItem $requestItem)
 {
     $requestItem->parseUrlWithTemplate(self::$ACTIVITY_ID_PATH);
     return $this->service->createActivity($requestItem->getUser(), $requestItem->getPostData(), $requestItem->getToken());
 }
 /**
  * /messages/{groupId}/outbox/{msgId}
  *
  * @param RestRequestItem $requestItem
  * @return responseItem
  */
 public function handlePut(RestRequestItem $requestItem)
 {
     $requestItem->parseUrlWithTemplate(self::$MESSAGES_PATH);
     return $this->service->createMessage($requestItem->getUser(), $requestItem->getPostData(), $requestItem->getToken());
 }