1 | <?php |
||
7 | abstract class Endpoint |
||
8 | { |
||
9 | /** |
||
10 | * The request parameters. |
||
11 | * |
||
12 | * @var array |
||
13 | */ |
||
14 | protected $params; |
||
15 | |||
16 | /** |
||
17 | * The HTTP client instance. |
||
18 | * |
||
19 | * @var \CryptoMarkets\Common\Client |
||
20 | */ |
||
21 | protected $httpClient; |
||
22 | |||
23 | /** |
||
24 | * Determine if the request need authorized. |
||
25 | * |
||
26 | * @var bool |
||
27 | */ |
||
28 | protected $authorize = false; |
||
29 | |||
30 | /** |
||
31 | * Create a new Endpoint instance. |
||
32 | * |
||
33 | * @param \CryptoMarkets\Common\Client $httpClient |
||
34 | * @return void |
||
|
|||
35 | */ |
||
36 | public function __construct(Client $httpClient) |
||
40 | |||
41 | /** |
||
42 | * Create a new resource instance. |
||
43 | * |
||
44 | * @param \CryptoMarkets\Common\Client $httpClient |
||
45 | * @param array $params |
||
46 | * @return static |
||
47 | */ |
||
48 | public static function make(Client $httpClient, array $params = []) |
||
56 | |||
57 | /** |
||
58 | * Configure the request parameters. |
||
59 | * |
||
60 | * @param array $params |
||
61 | * @return $this |
||
62 | */ |
||
63 | public function configure(array $params = []) |
||
69 | |||
70 | /** |
||
71 | * Send a new request. |
||
72 | * |
||
73 | * @return array |
||
74 | */ |
||
75 | public function send() |
||
83 | |||
84 | /** |
||
85 | * Create a new request object. |
||
86 | * |
||
87 | * @return \GuzzleHttp\Psr7\Request |
||
88 | */ |
||
89 | public function createRequest() |
||
98 | |||
99 | /** |
||
100 | * Get the request method. |
||
101 | * |
||
102 | * @return string |
||
103 | */ |
||
104 | public function getMethod() |
||
108 | |||
109 | /** |
||
110 | * Get the request url. |
||
111 | * |
||
112 | * @return string |
||
113 | */ |
||
114 | abstract public function getUrl(); |
||
115 | |||
116 | /** |
||
117 | * Get the request headers for authorized or not. |
||
118 | * |
||
119 | * @return array |
||
120 | */ |
||
121 | public function getPreparedHeaders() |
||
125 | |||
126 | /** |
||
127 | * Get the request headers. |
||
128 | * |
||
129 | * @return array |
||
130 | */ |
||
131 | public function getHeaders() |
||
135 | |||
136 | /** |
||
137 | * Get the request data for authorized or not. |
||
138 | * |
||
139 | * @return string |
||
140 | */ |
||
141 | public function getPreparedData() |
||
151 | |||
152 | /** |
||
153 | * Get the request data. |
||
154 | * |
||
155 | * @return array |
||
156 | */ |
||
157 | public function getData() |
||
161 | |||
162 | /** |
||
163 | * Get the authentication request data. |
||
164 | * |
||
165 | * @return array |
||
166 | */ |
||
167 | protected function authenticationData() |
||
171 | |||
172 | /** |
||
173 | * Parse and normalize the raw response. |
||
174 | * |
||
175 | * @param \Psr\Http\Message\ResponseInterface $response |
||
176 | * @return array |
||
177 | */ |
||
178 | public function parseResponse(ResponseInterface $response) |
||
182 | |||
183 | /** |
||
184 | * Map the given array to create a response object. |
||
185 | * |
||
186 | * @param array $data |
||
187 | * @return array |
||
188 | */ |
||
189 | abstract public function mapResponse(array $data = []); |
||
190 | } |
||
191 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.