12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- namespace App\Http;
- use Symfony\Component\HttpClient\HttpClient;
- use Symfony\Contracts\HttpClient\HttpClientInterface;
- use Symfony\Contracts\HttpClient\ResponseInterface;
- class WebflowApiClient implements WebflowApiClientInterface {
- private $client;
- private $url;
- private $options = [];
- public function __construct(string $token, string $api_url, string $version = '1.0.0') {
- $this->url = $api_url;
- $this->options = [
- 'auth_bearer' => $token,
- 'headers' => [
- 'accept-version' => $version,
- ],
- ];
- $this->client = HttpClient::createForBaseUri(
- sprintf('https://%s', $api_url),
- $this->options
- );
- }
- public function scopeFromBase(string $scope): string {
- return sprintf('https://%s/%s', $this->url, ltrim($scope, '/'));
- }
- public function get(string $scope): ResponseInterface {
- return $this->client->request('GET',
- $this->scopeFromBase($scope),
- );
- }
- public function getClient(): HttpClientInterface {
- return $this->client;
- }
- }
- ?>
|