Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ require 'vendor/autoload.php';
$client = new Xolphin\Client('<username>', '<password>');
```

When needed, you are able to provide a custom GuzzleHttp client when initializing the Xolphin client:

```php
$client = new Xolphin\Client(httpClient: new GuzzleHttp\Client([
...
]));
```

While this feature can be useful for applying your own middleware, make sure to also implement the authentication yourself.

### Rate Limiting

#### Current limit
Expand Down
12 changes: 7 additions & 5 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Xolphin;

use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\RequestException;
use Psr\Http\Message\StreamInterface;
Expand Down Expand Up @@ -52,8 +53,9 @@ class Client
* @param string|null $username
* @param string|null $password
* @param bool $test
* @param ClientInterface|null $httpClient
*/
function __construct(?string $username = null, ?string $password = null, bool $test = false)
function __construct(?string $username = null, ?string $password = null, bool $test = false, ClientInterface $httpClient = null)
{
$this->username = $username;
$this->password = $password;
Expand All @@ -76,7 +78,7 @@ function __construct(?string $username = null, ?string $password = null, bool $t
$options['verify'] = false;
}

$this->guzzle = new \GuzzleHttp\Client($options);
$this->guzzle = $httpClient ?? new \GuzzleHttp\Client($options);

$this->initializeEndpoints();
}
Expand Down Expand Up @@ -123,7 +125,7 @@ public function get(string $uri, array $data = [])
);

return json_decode(
$result->getBody()->getContents()
(string)$result->getBody()
);

} catch (RequestException $e) {
Expand Down Expand Up @@ -165,7 +167,7 @@ public function post(string $uri, array $data = [])
);

return json_decode(
$result->getBody()->getContents()
(string)$result->getBody()
);
} catch (RequestException $e) {
throw XolphinRequestException::createFromRequestException($e);
Expand All @@ -188,7 +190,7 @@ public function download(string $uri, array $data = []): StreamInterface
(int) $result->getHeader('X-RateLimit-Remaining')[0]
);

return $result->getBody();
return $result->getBody()->rewind();
} catch (RequestException $e) {
throw XolphinRequestException::createFromRequestException($e);
}
Expand Down