/
ListProjectsRequest.php
73 lines (63 loc) · 1.64 KB
/
ListProjectsRequest.php
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
<?php // Copyright ⓒ 2018 Magneds IP B.V. - All Rights Reserved
namespace Magneds\Lokalise\Project\Request;
use DateTime;
use DateTimeZone;
use Magneds\Lokalise\Project\Entity\Project;
use Magneds\Lokalise\Project\Entity\ProjectID;
use Magneds\Lokalise\RequestInterface;
use Magneds\Lokalise\ResponseInfo;
use Psr\Http\Message\ResponseInterface;
class ListProjectsRequest implements RequestInterface
{
/**
* Return the method to make this request in.
*
* @return string
*/
public function getMethod()
{
return 'GET';
}
/**
* This URI is appended to the route URL given to the Client object.
*
* @return string
*/
public function getURI()
{
return 'project/list';
}
/**
* @return array
*/
public function getQueryArguments()
{
return [];
}
/**
* @return array
*/
public function getBody()
{
return [];
}
/**
* @param ResponseInterface $response
* @return ResponseInfo
*/
public function handleResponse(ResponseInterface $response): ResponseInfo
{
$responseData = json_decode($response->getBody()->getContents(), true);
$responseInfo = ResponseInfo::buildFromArray($responseData['response']);
if ($responseInfo->getCode() !== 200) {
return $responseInfo;
}
$projects = [];
foreach ($responseData['projects'] as $project) {
$projects[] = Project::buildFromArray($project);
}
// Add it to the response object.
$responseInfo->setActionData($projects);
return $responseInfo;
}
}