1 | <?php |
||
12 | class AbstractApi |
||
13 | { |
||
14 | /** |
||
15 | * @var ClientInterface HTTP-client from Guzzle |
||
16 | */ |
||
17 | protected $client; |
||
18 | |||
19 | /** |
||
20 | * @var LoggerInterface |
||
21 | */ |
||
22 | protected $logger; |
||
23 | |||
24 | /** |
||
25 | * @var string Authentication token for API |
||
26 | */ |
||
27 | protected $authToken; |
||
28 | |||
29 | /** |
||
30 | * @var string CSRF-token for API |
||
31 | */ |
||
32 | protected $csRfToken; |
||
33 | |||
34 | |||
35 | 12 | public function __construct(ClientInterface $httpClient, LoggerInterface $logger) |
|
40 | |||
41 | /** |
||
42 | * @param string $path Request path |
||
43 | * @param array $parameters Key => Value array of query parameters |
||
44 | * |
||
45 | * @return ResponseInterface |
||
46 | */ |
||
47 | public function sendGetRequest(string $path, array $parameters = []): ResponseInterface |
||
53 | |||
54 | /** |
||
55 | * @param string $path Request path |
||
56 | * @param array $parameters Key => Value array of request data |
||
57 | * |
||
58 | * @return ResponseInterface |
||
59 | */ |
||
60 | public function sendPostRequest(string $path, array $parameters = []): ResponseInterface |
||
66 | |||
67 | /** |
||
68 | * Make GET request and return data from response |
||
69 | * |
||
70 | * @param string $path Path template |
||
71 | * @param array $parameters Parameters array used to fill path template |
||
72 | * @param bool $decodeJsonResponse Decode JSON or return plaintext |
||
73 | * @param bool $decodeJsonToObjects Decode JSON objects to PHP objects instead of arrays |
||
74 | * |
||
75 | * @return mixed |
||
76 | */ |
||
77 | public function getGetRequestData($path, array $parameters = [], bool $decodeJsonResponse = false, bool $decodeJsonToObjects = false) |
||
83 | |||
84 | /** |
||
85 | * Make POST request and return data from response |
||
86 | * |
||
87 | * @param string $path Path template |
||
88 | * @param array $parameters Parameters array used to fill path template |
||
89 | * @param bool $decodeJson Decode JSON or return plaintext |
||
90 | * @param bool $decodeToObjects Decode JSON objects to PHP objects instead of arrays |
||
91 | * |
||
92 | * @return mixed |
||
93 | */ |
||
94 | public function getPostRequestData($path, array $parameters = [], bool $decodeJson = false, bool $decodeToObjects = false) |
||
100 | |||
101 | /** |
||
102 | * @param ResponseInterface $response |
||
103 | * @param bool $decodeJson |
||
104 | * @param bool $decodeToObjects |
||
105 | * |
||
106 | * @return string|array|object |
||
107 | */ |
||
108 | private function processResponse(ResponseInterface $response, bool $decodeJson = false, bool $decodeToObjects = false) |
||
120 | } |
||
121 |