Пример #1
0
 /**
  * /messages/{groupId}/outbox/{msgId}
  * /messages/{groupId}/outbox
  *
  * @param RequestItem $requestItem
  * @return responseItem
  */
 public function handlePost(RequestItem $requestItem)
 {
     $requestItem->applyUrlTemplate(self::$MESSAGES_PATH);
     $userIds = $requestItem->getUsers();
     $message = $requestItem->getParameter('message');
     $optionalMessageId = $requestItem->getParameter('msgId');
     return $this->service->createMessage($userIds[0], $requestItem->getAppId(), $message, $optionalMessageId, $requestItem->getToken());
 }
Пример #2
0
 /**
  * /appdata/{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(RequestItem $requestItem)
 {
     $this->checkService();
     $requestItem->applyUrlTemplate(self::$APP_DATA_PATH);
     $userIds = $requestItem->getUsers();
     if (count($userIds) < 1) {
         throw new InvalidArgumentException("No userId specified");
     } elseif (count($userIds) > 1) {
         throw new InvalidArgumentException("Multiple userIds not supported");
     }
     $values = $requestItem->getParameter("data");
     // this used to be $requestItem->getFields() instead of using the fields, but that makes no sense to me
     // better to detect the fields depending on input right?
     $fields = array();
     foreach (array_keys($values) as $key) {
         $fields[] = $key;
         if (!$this->isValidKey($key)) {
             throw new SocialSpiException("One or more of the app data keys are invalid: " . $key, ResponseError::$BAD_REQUEST);
         }
     }
     $this->service->updatePersonData($userIds[0], $requestItem->getGroup(), $requestItem->getAppId(), $fields, $values, $requestItem->getToken());
 }
 /**
  * /activities/{userId}/@self
  *
  * examples:
  * /activities/@viewer/@self/@app
  * /activities/john.doe/@self
  * - postBody is an activity object
  *
  * @param RequestItem $requestItem
  * @return ResponseItem
  */
 public function handlePost(RequestItem $requestItem)
 {
     $this->checkService();
     $requestItem->applyUrlTemplate(self::$ACTIVITY_ID_PATH);
     $userIds = $requestItem->getUsers();
     $activityIds = $requestItem->getListParameter("activityId");
     if (empty($userIds)) {
         throw new InvalidArgumentException("No userId specified");
     } elseif (count($userIds) > 1) {
         throw new InvalidArgumentException("Multiple userIds not supported");
     }
     // TODO This seems reasonable to allow on PUT but we don't have an update verb.
     if (!empty($activityIds)) {
         throw new InvalidArgumentException("Cannot specify activityId in create");
     }
     /*
      * Note, on just about all types of social networks you would only allow activities to be created when the owner == viewer, and the userId == viewer as well, in code this would mean:
      *  if ($token->getOwnerId() != $token->getViewerId() || $token->getViewerId() != $userId->getUserId($token)) {
      *    throw new SocialSpiException("Create activity permission denied.", ResponseError::$UNAUTHORIZED);
      *  }
      */
     return $this->service->createActivity($userIds[0], $requestItem->getGroup(), $requestItem->getAppId(), $requestItem->getFields(), $requestItem->getParameter("activity"), $requestItem->getToken());
 }
Пример #4
0
 /**
  * /activities/{userId}/@self
  *
  * examples:
  * /activities/@viewer/@self/@app
  * /activities/john.doe/@self
  * - postBody is an activity object
  */
 public function handlePost(RequestItem $requestItem)
 {
     $requestItem->applyUrlTemplate(self::$ACTIVITY_ID_PATH);
     $userIds = $requestItem->getUsers();
     $activityIds = $requestItem->getListParameter("activityId");
     if (empty($userIds)) {
         throw new InvalidArgumentException("No userId specified");
     } elseif (count($userIds) > 1) {
         throw new InvalidArgumentException("Multiple userIds not supported");
     }
     // TODO This seems reasonable to allow on PUT but we don't have an update verb.
     if (!empty($activityIds)) {
         throw new InvalidArgumentException("Cannot specify activityId in create");
     }
     return $this->service->createActivity($userIds[0], $requestItem->getGroup(), $requestItem->getAppId(), $requestItem->getFields(), $requestItem->getParameter("activity"), $requestItem->getToken());
 }