-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to pass your own client instance to the service #20
Labels
Comments
Yeah I'm not familiar with how the oauth stuff works since I just use an api key. If you think it would be helpful, we could do that, but maybe just move checking if the client is passed, to the constructor like this? /**
* @param string|null $apiKey
* @param bool $oauth
* @param HttpClient $client
* @throws HubSpotException
*/
protected function __construct($apiKey = null, $oauth = false, HttpClient $client = null)
{
$this->oauth = $oauth;
$this->apiKey = $apiKey ?: getenv('HUBSPOT_API_KEY');
if (empty($this->apiKey)) {
throw new HubSpotException("You must provide a HubSpot api key.");
}
$this->client = $client ?: new Client;
}
/**
* @param string $access_token HubSpot oauth access token
* @param HttpClient $client An Http Client
* @return static
*/
public static function makeWithToken($access_token, HttpClient $client = null)
{
return new static($access_token, true, $client);
}
/**
* @param string $name
* @param null $arguments
* @return mixed
* @throws HubSpotException
*/
public function __call($name, $arguments = null)
{
$apiClass = $this->getApiClassName($name);
if (! (new \ReflectionClass($apiClass))->isInstantiable()) {
throw new HubSpotException("Target [$apiClass] is not instantiable.");
}
return new $apiClass($this->apiKey, $this->client, $this->oauth);
} |
Yeah that makes sense, it means there's only ever one client per HubSpotService too, which is a bit more efficient. |
👍 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would like the ability to add my own instance of Client to the service which get's passed to all created API classes.
I would like to set up a events on the client to handle refreshing the OAuth token without having to handle each response separately.
Ideally I would like to be able to do the folloing:
What are your thoughts? I'll happily create a pull request if you think this would be useful
The text was updated successfully, but these errors were encountered: