1 | <?php |
||
12 | class ApiClient implements ApiClientContract |
||
13 | { |
||
14 | const AUTH_URL = 'https://auth.selcdn.ru'; |
||
15 | |||
16 | /** |
||
17 | * API Username. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $username; |
||
22 | |||
23 | /** |
||
24 | * API Password. |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $password; |
||
29 | |||
30 | /** |
||
31 | * Authorization token. |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $token; |
||
36 | |||
37 | /** |
||
38 | * Storage URL. |
||
39 | * |
||
40 | * @var string |
||
41 | */ |
||
42 | protected $storageUrl; |
||
43 | |||
44 | /** |
||
45 | * HTTP Client. |
||
46 | * |
||
47 | * @var \GuzzleHttp\ClientInterface |
||
48 | */ |
||
49 | protected $httpClient; |
||
50 | |||
51 | /** |
||
52 | * Creates new API Client instance. |
||
53 | * |
||
54 | * @param string $username |
||
55 | * @param string $password |
||
56 | */ |
||
57 | public function __construct($username, $password) |
||
62 | |||
63 | /** |
||
64 | * Replaces HTTP Client instance. |
||
65 | * |
||
66 | * @param \GuzzleHttp\ClientInterface $httpClient |
||
67 | * |
||
68 | * @return \ArgentCrusade\Selectel\CloudStorage\Contracts\Api\ApiClientContract |
||
69 | */ |
||
70 | public function setHttpClient(ClientInterface $httpClient) |
||
76 | |||
77 | /** |
||
78 | * HTTP Client. |
||
79 | * |
||
80 | * @return \GuzzleHttp\ClientInterface|null |
||
81 | */ |
||
82 | public function getHttpClient() |
||
95 | |||
96 | /** |
||
97 | * Authenticated user's token. |
||
98 | * |
||
99 | * @return string |
||
100 | */ |
||
101 | public function token() |
||
105 | |||
106 | /** |
||
107 | * Storage URL. |
||
108 | * |
||
109 | * @return string |
||
110 | */ |
||
111 | public function storageUrl() |
||
115 | |||
116 | /** |
||
117 | * Determines if user is authenticated. |
||
118 | * |
||
119 | * @return bool |
||
120 | */ |
||
121 | public function authenticated() |
||
125 | |||
126 | /** |
||
127 | * Performs authentication request. |
||
128 | * |
||
129 | * @throws \ArgentCrusade\Selectel\CloudStorage\Exceptions\AuthenticationFailedException |
||
130 | * @throws \RuntimeException |
||
131 | */ |
||
132 | public function authenticate() |
||
151 | |||
152 | /** |
||
153 | * Performs authentication request and returns its response. |
||
154 | * |
||
155 | * @throws \ArgentCrusade\Selectel\CloudStorage\Exceptions\AuthenticationFailedException |
||
156 | * |
||
157 | * @return \Psr\Http\Message\ResponseInterface |
||
158 | */ |
||
159 | public function authenticationResponse() |
||
176 | |||
177 | /** |
||
178 | * Performs new API request. $params array will be passed to HTTP Client as is. |
||
179 | * |
||
180 | * @param string $method |
||
181 | * @param string $url |
||
182 | * @param array $params = [] |
||
183 | * |
||
184 | * @return \Psr\Http\Message\ResponseInterface |
||
185 | */ |
||
186 | public function request($method, $url, array $params = []) |
||
206 | } |
||
207 |