public static function performGETLikeRequest($targetedGID, $likeID) { // create an instance of PersonRequestBuilder $likeRequest = new LikeRequestBuilder($targetedGID); // perform the request $response = $likeRequest->createGETLike($likeObjectID)->dispatch(); // to access contents of the response, use // $response->getPayload(); <-- the actual object data // $response->getResponseBody(); <-- the complete response body if ($response->getResponseStatusCode() != 200) { // in case the request returned something else thatn a 200 throw new \Exception('Request failed with status code ' . $response->getResponseStatusCode()); } else { // return the Person object from the responses payload return LikeObjectBuilder::buildFromJSON($response->getPayload()); } }
$personObject = PersonObjectBuilder::buildFromJSON(file_get_contents(__DIR__ . '/data/AlicePerson.json')); // check access permissions for the content object if (!Sonic::getAccessControlManager()->hasContentAccessPriviledges($request->getHeaderSourceGID(), $personObject->getObjectID())) { throw new AccessControlException(); } $response = new ResponseBuilder(200); $response->init()->setBody($personObject->getJSON()); $response->dispatch(); } else { throw new MethodNotAllowedException(); } break; case 'like': if ($request->getMethod() == 'POST') { // building LIKE object from request body data $likeObject = LikeObjectBuilder::buildFromJSON($request->getBody()); // here, we would store the received object in the database $response = new ResponseBuilder(200); $response->init('like object received: [' . $likeObject->getObjectID() . ']'); $response->dispatch(); } else { throw new MethodNotAllowedException(); } break; default: $response = new ResponseBuilder(404); $response->init('Resource ' . $resource . ' not found'); $response->dispatch(); break; } } catch (AccessControlException $e) {
public function testLike() { $like = (new LikeObjectBuilder())->objectID(UOID::createUOID())->targetID(UOID::createUOID())->author(Sonic::getContextGlobalID())->build(); $this->assertTrue($like->validate()); $this->assertEquals($like, LikeObjectBuilder::buildFromJSON($like->getJSONString())); }