-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLikeAPIExample.php
More file actions
90 lines (75 loc) · 2.71 KB
/
Copy pathLikeAPIExample.php
File metadata and controls
90 lines (75 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php namespace sgoendoer\Sonic\examples;
use sgoendoer\Sonic\Sonic;
use sgoendoer\Sonic\API\LikeRequestBuilder;
use sgoendoer\Sonic\Model\LikeObject;
use sgoendoer\Sonic\Model\LikeObjectBuilder;
class LikeAPIExample
{
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());
}
}
public static function performPOSTLikeRequest($targetedGID, $likedContentID)
{
// create an instance of PersonRequestBuilder
$likeRequest = new LikeRequestBuilder($targetedGID);
// create the LIKE object for the content to be liked
$likeObject = (new LikeObjectBuilder())
->objectID(UOID::createUOID())
->targetID($likedContentID)
->author(Sonic::getUserGlobalID())
->build();
// perform the request
$response = $likeRequest->createGETLike($likeObject)->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
{
// request was performed successfully
return true;
}
}
public static function performDELETELikeRequest($targetedGID, $likeObjectID)
{
// create an instance of PersonRequestBuilder
$likeRequest = new LikeRequestBuilder($targetedGID);
// perform the request
$response = $likeRequest->createDELETELike($targetedGID, $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
{
// request was performed successfully
return true;
}
}
}
?>