1 | <?php |
||
10 | class Request |
||
11 | { |
||
12 | /** |
||
13 | * Endpoint URL. |
||
14 | * |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $endpoint = ''; |
||
18 | |||
19 | /** |
||
20 | * Response model class to map request results to. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $response = Response::class; |
||
25 | |||
26 | /** |
||
27 | * Request method. |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $method = 'GET'; |
||
32 | |||
33 | /** |
||
34 | * Resource unique identifier. |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $key = null; |
||
39 | |||
40 | /** |
||
41 | * Query string parameters. |
||
42 | * |
||
43 | * @var array |
||
44 | */ |
||
45 | protected $queryStringParameters = []; |
||
46 | |||
47 | /** |
||
48 | * Builder a request to fetch a resource by unique identifier. |
||
49 | * |
||
50 | * @param string $key |
||
51 | * @return self |
||
52 | */ |
||
53 | public static function find($key): self |
||
60 | |||
61 | /** |
||
62 | * Return the HTTP method used for this request. |
||
63 | * |
||
64 | * @return string |
||
65 | */ |
||
66 | public function getMethod(): string |
||
70 | |||
71 | /** |
||
72 | * Get the response model class to map request result(s) to. |
||
73 | * |
||
74 | * @return string |
||
75 | */ |
||
76 | public function getResponseModel(): string |
||
80 | |||
81 | /** |
||
82 | * Add a parameter to the query string. |
||
83 | * |
||
84 | * @param string $key |
||
85 | * @param mixed $value |
||
86 | * @return self |
||
87 | */ |
||
88 | public function withParameter(string $key, $value): self |
||
94 | |||
95 | /** |
||
96 | * Encode the query string parameters. |
||
97 | * |
||
98 | * @param array $parameters |
||
99 | * @return string |
||
100 | */ |
||
101 | protected function encode(array $parameters): string |
||
110 | |||
111 | /** |
||
112 | * Build the query string. |
||
113 | * |
||
114 | * @return string |
||
115 | */ |
||
116 | protected function buildQueryString(): string |
||
120 | |||
121 | /** |
||
122 | * Build the request URL. |
||
123 | * |
||
124 | * @return string |
||
125 | */ |
||
126 | public function buildUrl(): string |
||
134 | } |
||
135 |