|
3 | 3 | use GuzzleHttp\Psr7\Request; |
4 | 4 | use GuzzleHttp\Psr7\Uri; |
5 | 5 | use GuzzleHttp\RequestOptions; |
| 6 | +use MyENA\CloudStackClientGenerator\Configuration\Environment; |
6 | 7 |
|
7 | 8 | /** |
8 | 9 | * Class Client |
9 | 10 | * @package MyENA\CloudStackClientGenerator |
10 | 11 | */ |
11 | 12 | class Client { |
12 | | - /** @var \MyENA\CloudStackClientGenerator\Configuration */ |
13 | | - protected $config; |
| 13 | + /** @var \MyENA\CloudStackClientGenerator\Configuration\Environment */ |
| 14 | + protected $env; |
14 | 15 |
|
15 | 16 | /** |
16 | 17 | * Client constructor. |
17 | | - * @param \MyENA\CloudStackClientGenerator\Configuration $c |
| 18 | + * @param \MyENA\CloudStackClientGenerator\Configuration\Environment $e |
18 | 19 | */ |
19 | | - public function __construct(Configuration $c) { |
20 | | - $this->config = $c; |
| 20 | + public function __construct(Environment $e) { |
| 21 | + $this->env = $e; |
21 | 22 | } |
22 | 23 |
|
23 | 24 | /** |
24 | 25 | * @param string $command |
25 | 26 | * @param array $parameters |
26 | 27 | * @param array $headers |
27 | 28 | * @return \stdClass |
| 29 | + * @throws \Exception |
| 30 | + * @throws \GuzzleHttp\Exception\GuzzleException |
28 | 31 | */ |
29 | 32 | public function do(string $command, array $parameters = [], array $headers = []): \stdClass { |
30 | 33 | static $defaultHeaders = |
31 | 34 | ['Accept' => ['application/json'], 'Content-Type' => ['application/x-www-form-urlencoded']]; |
32 | 35 |
|
33 | | - $params = ['apikey' => $this->config->getKey(), 'command' => $command, 'response' => 'json'] + $parameters; |
| 36 | + $params = ['apikey' => $this->env->getKey(), 'command' => $command, 'response' => 'json'] + $parameters; |
34 | 37 |
|
35 | 38 | ksort($params); |
36 | 39 |
|
37 | 40 | $query = http_build_query($params, '', '&', PHP_QUERY_RFC3986); |
38 | 41 |
|
39 | 42 | $uri = new Uri(sprintf( |
40 | 43 | '%s/%s?%s&signature=%s', |
41 | | - $this->config->getCompiledAddress(), |
42 | | - $this->config->getApiPath(), |
| 44 | + $this->env->getCompiledAddress(), |
| 45 | + $this->env->getApiPath(), |
43 | 46 | $query, |
44 | | - $this->config->buildSignature($query) |
| 47 | + $this->env->buildSignature($query) |
45 | 48 | )); |
46 | 49 |
|
47 | 50 | $r = new Request('GET', $uri, $headers + $defaultHeaders); |
48 | 51 |
|
49 | | - $resp = $this->config->HttpClient->send($r, [ |
| 52 | + $resp = $this->env->getHttpClient()->send($r, [ |
50 | 53 | RequestOptions::HTTP_ERRORS => false, |
51 | 54 | RequestOptions::DECODE_CONTENT => false, |
52 | 55 | ]); |
|
0 commit comments