-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPersonAPIExample.php
More file actions
35 lines (29 loc) · 1.01 KB
/
Copy pathPersonAPIExample.php
File metadata and controls
35 lines (29 loc) · 1.01 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
<?php namespace sgoendoer\Sonic\examples;
use sgoendoer\Sonic\Sonic;
use sgoendoer\Sonic\API\PersonRequestBuilder;
use sgoendoer\Sonic\Model\PersonObject;
use sgoendoer\Sonic\Model\PersonObjectBuilder;
class PersonAPIExample
{
public static function performGETPersonRequest($targetedGID)
{
// create an instance of PersonRequestBuilder
$personRequest = new PersonRequestBuilder($targetedGID);
// perform the request
$response = $personRequest->createGETPerson()->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 PersonObjectBuilder::buildFromJSON($response->getPayload());
}
}
}
?>