Closed Darrrren closed 3 years ago
Just pass the timeout option in construct.
$fortie = new Fortie(..., ['timeout' => 20]);
Ahh thanks @jongotlin. Actually, I'm using Laravel and I'm instantiating the client in the controller using the exact example in the README.md:
protected $fortie;
public function __construct(Fortie $fortie)
{
$this->fortie = $fortie;
}
and then obviously I have access to the $fortie object everywhere. Any idea how I pass the timeout variable into that?
Thanks for your help!
I think perhaps we should add an optional "options" to the configuration in the service provider to enable this (and other) configs.
protected function registerFortie()
{
$this->app->singleton(Fortie::class, function ($app)
{
$access_token = Config::get('fortie.default.access_token', Config::get('fortie::default.access_token'));
$client_secret = Config::get('fortie.default.client_secret', Config::get('fortie::default.client_secret'));
$content_type = Config::get('fortie.default.content_type', Config::get('fortie::default.content_type'));
$accepts = Config::get('fortie.default.accepts', Config::get('fortie::default.accepts'));
$endpoint = Config::get('fortie.default.endpoint', Config::get('fortie::default.endpoint'));
$config = Config::get('fortie.default.config', Config::get('fortie::default.config')); // This would contain the timeout value, which then can easily be configured in the installation
$options = array_merge([
'base_uri' => $endpoint,
'headers' => [
'Access-Token' => $access_token,
'Client-Secret' => $client_secret,
'Content-Type' => $content_type,
'Accept' => $accepts
],
], $config)
return new Fortie($options);
});
}
Also probably moving stuff from the constructor of the Fortie client; that way we won't end up with this kind of problems in the future if we allow more generic parameters in the client.
The default 3 second client timeout is causing me a problem sometimes and Fortnox is occasionally timing out, I need to at least double this. Is there an easy way to change this which wont get over written when I next update fortie? https://github.com/wetcat-studios/fortie/blob/85fc4ec5baf289c0cc0c4407c7f9e3106152e6a2/src/Fortie.php#L103