Skip to content

Instantly share code, notes, and snippets.

@davereid
Created Jul 9, 2015
Embed
What would you like to do?
<?php
class Client extends GuzzleClient implements ClientInterface
{
/**
* {@inheritdoc}
*/
public function authenticatedRequest($method = 'GET', $url = null, UserInterface $user, $options = [])
{
$duration = isset($options['timeout']) ? $options['timeout'] : null;
$options['query']['token'] = $user->acquireToken($duration);
try {
$response = $this->send($this->createRequest($method, $url, $options));
return $response;
} catch (ApiException $exception) {
// If the token is invalid, we should delete it from storage so that a
// fresh token is fetched on the next request.
if ($exception->getCode() == 401) {
// Ensure the token will be deleted.
$user->invalidateToken();
}
throw $exception;
}
}
}
<?php
class Client extends GuzzleClient implements ClientInterface {
/**
* {@inheritdoc}
*/
public function authenticatedRequest($method = 'GET', $url = null, UserInterface $user, $options = []) {
$duration = isset($options['timeout']) ? $options['timeout'] : NULL;
$options['query']['token'] = $user->acquireToken($duration);
try {
$response = $this->send($this->createRequest($method, $url, $options));
return $response;
}
catch (ApiException $exception) {
// If the token is invalid, we should delete it from storage so that a
// fresh token is fetched on the next request.
if ($exception->getCode() == 401) {
// Ensure the token will be deleted.
$user->invalidateToken();
}
throw $exception;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment