-
Notifications
You must be signed in to change notification settings - Fork 1
/
GetColors.php
93 lines (79 loc) · 2.34 KB
/
GetColors.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php declare(strict_types=1);
namespace Zogot\Rebrickable\API\Client\Lego\Color\Request;
use Psr\Http\Message\RequestInterface;
use Zogot\Rebrickable\API\Client\RebrickableRequestInterface;
use function implode;
class GetColors implements RebrickableRequestInterface
{
/**
* @var int|null
*/
protected ?int $page;
/**
* @var int|null
*/
protected ?int $pageSize;
/**
* @var string|null
*/
protected ?string $orderingField;
/**
* GetColors constructor.
* @param int|null $page
* @param int|null $pageSize
* @param string|null $orderingField
*/
public function __construct(?int $page = null, ?int $pageSize = null, ?string $orderingField = null)
{
$this->page = $page;
$this->pageSize = $pageSize;
$this->orderingField = $orderingField;
}
/**
* Return the http method for this request.
*
* @return string
*/
public function getMethod(): string
{
return RebrickableRequestInterface::METHOD_GET;
}
/**
* Return the api endpoints path.
*
* @see https://rebrickable.com/api/v3/docs/
* @return string
*/
public function getPath(): string
{
$path = "/api/v3/lego/colors/";
$queryParameters = [];
if(!is_null($this->page)) {
$queryParameters[] = "page={$this->page}";
}
if(!is_null($this->pageSize)) {
$queryParameters[] = "page_size={$this->pageSize}";
}
if(!is_null($this->orderingField)) {
$queryParameters[] = "ordering={$this->orderingField}";
}
if(!empty($queryParameters)) {
return $path . "?" . implode(separator: "&", array: $queryParameters);
}
return $path;
}
/**
* Modify the outgoing request, mainly used for adding additional headers or
* body of the outgoing request.
*
* Return the Request in the end, in case the implementation of RequestInterface
* is immutable.
*
* @param RequestInterface $request
* @return RequestInterface
*/
public function beforeRequest(RequestInterface $request): RequestInterface
{
return $request->withAddedHeader("Accept", "application/json");
}
}