From: Vincent Vanwaelscappel Date: Tue, 29 Oct 2024 13:37:45 +0000 (+0100) Subject: wip #7062 @0.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=1c85c844f895bcea6704ba5994bbd628e3fecfd7;p=fluidbook_toolboxapiclient.git wip #7062 @0.5 --- diff --git a/src/Client.php b/src/Client.php index fe4b19d..c95bb09 100644 --- a/src/Client.php +++ b/src/Client.php @@ -2,14 +2,15 @@ namespace Fluidbook\ToolboxApiClient; -use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Psr7\Utils; use Psr\Http\Message\ResponseInterface; -class Client extends \GuzzleHttp\Client +class Client { const BASE_URI = 'https://https://toolbox.fluidbook.com/api/'; protected $_apiToken; + /** @var \GuzzleHttp\Client */ + protected $_client; public function __construct($apiToken, $uri = null) { @@ -18,7 +19,23 @@ class Client extends \GuzzleHttp\Client if (null === $uri) { $uri = self::BASE_URI; } - parent::__construct(['base_uri' => $uri]); + $this->setClient(new \GuzzleHttp\Client(['base_uri' => $uri])); + } + + /** + * @return \GuzzleHttp\Client + */ + public function getClient(): \GuzzleHttp\Client + { + return $this->_client; + } + + /** + * @param \GuzzleHttp\Client $client + */ + public function setClient(\GuzzleHttp\Client $client): void + { + $this->_client = $client; } /** @@ -29,12 +46,12 @@ class Client extends \GuzzleHttp\Client return $this->_apiToken; } - public static function getResponseBody(ResponseInterface $response): string + public static function getResponseContents(ResponseInterface $response): string { return $response->getBody()->getContents(); } - public function createFluidbook(\SplFileInfo $file, $base, $title, $installServer, $installPath) + public function createFluidbook(\SplFileInfo $file, $base, $title, $installServer, $installPath): string { $data = ['base' => $base, 'title' => $title, 'export[server]' => $installServer, 'export[path]' => $installPath]; $multipart = []; @@ -43,7 +60,12 @@ class Client extends \GuzzleHttp\Client } $multipart[] = ['name' => 'file', 'contents' => Utils::tryFopen($file->getPathname(), 'r'), 'filename' => $file->getFilename()]; - return self::getResponseBody($this->post('/fluidbook-publication/create', ['multipart' => $multipart])); + return $this->_request('post', '/fluidbook-publication/create', ['multipart' => $multipart]); + } + + protected function _request($method, $uri, $options = []) + { + return self::getResponseContents($this->getClient()->request($method, $uri, $options)); }