File: //usr/local/mailchannels/clients/AWS/AwsApiImpl.php
<?php
namespace AWS;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\ConnectException;
use MailChannels\App;
class AwsApiImpl implements AwsApi
{
private $client;
private $logger;
public function __construct($baseUri, Client $client=null) {
if(!$client) {
$client = new Client([
'base_uri'=>$baseUri,
'verify' => APP::verifySSL()
]);
}
$this->client = $client;
$this->logger = \MailChannels\App::getLogger();
}
public function getLatestVersion() {
$response = $this->call("GET", "plugins/mailchannels-cpanel3-latest-version.txt");
return $response->getBody()->getContents();
}
public function getInstallScript()
{
$installer = $this->call("GET", "plugins/mailchannels-cpanel-v3-installer");
return $installer->getBody()->getContents();
}
private function call($method, $uri, $options=[]) {
try {
$this->logger->debug("[MailChannels AWS API] request - method: $method, URI: $uri; options: " . json_encode($options));
return $this->client->request($method, $uri, $options);
} catch (ClientException $e) {
$this->logger->debug("[MailChannels AWS API] exception - method: $method URI: $uri; options: " . json_encode($options));
$this->logger->debug($e);
throw $e;
} catch (ConnectException $e) {
throw new InboundApiConnectException("Couldn't connect to AWS", $e->getCode(), $e);
}
}
}