1 | <?php |
||
8 | abstract class Endpoint |
||
9 | { |
||
10 | /** |
||
11 | * The request parameters. |
||
12 | * |
||
13 | * @var array |
||
14 | */ |
||
15 | protected $params; |
||
16 | |||
17 | /** |
||
18 | * The HTTP client instance. |
||
19 | * |
||
20 | * @var \CryptoMarkets\Common\Client |
||
21 | */ |
||
22 | protected $httpClient; |
||
23 | |||
24 | /** |
||
25 | * Determine if the request need authorized. |
||
26 | * |
||
27 | * @var bool |
||
28 | */ |
||
29 | protected $authorize = false; |
||
30 | |||
31 | /** |
||
32 | * Create a new Endpoint instance. |
||
33 | * |
||
34 | * @param \CryptoMarkets\Common\Client $httpClient |
||
35 | * @return void |
||
|
|||
36 | */ |
||
37 | public function __construct(Client $httpClient) |
||
41 | |||
42 | /** |
||
43 | * Configure the request parameters. |
||
44 | * |
||
45 | * @param array $params |
||
46 | * @return $this |
||
47 | */ |
||
48 | public function configure(array $params = []) |
||
54 | |||
55 | /** |
||
56 | * Send a new request. |
||
57 | * |
||
58 | * @return array |
||
59 | */ |
||
60 | public function send() |
||
68 | |||
69 | /** |
||
70 | * Create a new request object. |
||
71 | * |
||
72 | * @return \GuzzleHttp\Psr7\Request |
||
73 | */ |
||
74 | public function createRequest() |
||
83 | |||
84 | /** |
||
85 | * Get the request method. |
||
86 | * |
||
87 | * @return string |
||
88 | */ |
||
89 | public function getMethod() |
||
93 | |||
94 | /** |
||
95 | * Get the request url. |
||
96 | * |
||
97 | * @return string |
||
98 | */ |
||
99 | abstract public function getUrl(); |
||
100 | |||
101 | /** |
||
102 | * Get the request headers for authorized or not. |
||
103 | * |
||
104 | * @return array |
||
105 | */ |
||
106 | public function getPreparedHeaders() |
||
110 | |||
111 | /** |
||
112 | * Get the request headers. |
||
113 | * |
||
114 | * @return array |
||
115 | */ |
||
116 | public function getHeaders() |
||
120 | |||
121 | /** |
||
122 | * Get the request data for authorized or not. |
||
123 | * |
||
124 | * @return string |
||
125 | */ |
||
126 | public function getPreparedData() |
||
136 | |||
137 | /** |
||
138 | * Get the request data. |
||
139 | * |
||
140 | * @return array |
||
141 | */ |
||
142 | public function getData() |
||
146 | |||
147 | /** |
||
148 | * Get the authentication request data. |
||
149 | * |
||
150 | * @return array |
||
151 | */ |
||
152 | protected function authenticationData() |
||
156 | |||
157 | /** |
||
158 | * Parse and normalize the raw response. |
||
159 | * |
||
160 | * @param \Psr\Http\Message\ResponseInterface $response |
||
161 | * @return array |
||
162 | */ |
||
163 | public function parseResponse(ResponseInterface $response) |
||
167 | |||
168 | /** |
||
169 | * Map the given array to create a response object. |
||
170 | * |
||
171 | * @param array $data |
||
172 | * @return array |
||
173 | */ |
||
174 | abstract public function mapResponse(array $data = []); |
||
175 | } |
||
176 |
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.