/** * Prepares the environment before running a test. */ protected function setUp() { parent::setUp(); $this->RestRequestItem = new RestRequestItem(); $url = '/people/@viewer/@self?fields=age,name,gender,profileUrl,thumbnailUrl,' . 'status,id&startIndex=0&count=40&orderBy=name&filterBy=all&networkDistance=1'; $request = array(); $request['url'] = $url; $request['method'] = 'GET'; $request['postData'] = array(); $request['postData']['data'] = 'DataTest'; $this->RestRequestItem->createRequestItemWithRequest($request, $this->getToken()); //(the getters of the parsedTemplate will be tested on other methods) $this->RestRequestItem->parseUrlWithTemplate("/people/{userId}/{groupId}/{personId}"); }
/** * /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()); }
/** * /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()); }