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)
{
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;
}
/**
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 = [];
}
$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));
}