Skip to content

Commit

Permalink
Misc updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomshaw committed Oct 17, 2023
1 parent 564c118 commit f1ee924
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 84 deletions.
4 changes: 1 addition & 3 deletions src/Api/GoogleCalendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ final class GoogleCalendar

public function __construct(GoogleClient $client)
{
if (! $client->getAccessToken()) {
$client->createAuthUrl();
}
$client->initialize();

$this->service = new Calendar($client->client);
}
Expand Down
4 changes: 1 addition & 3 deletions src/Api/GoogleMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ final class GoogleMail

public function __construct(GoogleClient $client)
{
if (! $client->getAccessToken()) {
$client->createAuthUrl();
}
$client->initialize();

$this->service = new Gmail($client->client);

Expand Down
14 changes: 1 addition & 13 deletions src/Contracts/GoogleClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,7 @@

interface GoogleClientInterface
{
public function setAuthConfig(string $authConfig): GoogleClient;

public function setApplicationName(string $applicationName): GoogleClient;

public function addScope(array $scopes): GoogleClient;

public function setAccessType(string $accessType = 'offline'): GoogleClient;

public function setPrompt(string $prompt = 'none'): GoogleClient;

public function setApprovalPrompt(string $approvalPrompt = 'offline'): GoogleClient;

public function setIncludeGrantedScopes(bool $includeGrantedScopes = true): GoogleClient;
public function initialize(): GoogleClient;

public function createAuthUrl(): void;

Expand Down
89 changes: 24 additions & 65 deletions src/GoogleClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,84 +28,43 @@ public function __construct(
throw new GoogleClientException('Unable to load client secrets.');
}

$this->client->setAuthConfig(config('google-api.auth_config'));
$client->setAuthConfig(config('google-api.auth_config'));

$this->client->addScope(config('google-api-scopes'));
$client->addScope(config('google-api-scopes'));

$this->client->setApplicationName(config('google-api.application_name'));
$client->setApplicationName(config('google-api.application_name'));

$this->client->setPrompt(config('google-api.prompt'));
$client->setPrompt(config('google-api.prompt'));

$this->client->setApprovalPrompt(config('google-api.approval_prompt'));
$client->setApprovalPrompt(config('google-api.approval_prompt'));

$this->client->setAccessType(config('google-api.access_type'));
$client->setAccessType(config('google-api.access_type'));

$this->client->setIncludeGrantedScopes(config('google-api.include_grant_scopes'));

$accessToken = $this->getAccessToken();

if ($accessToken) {
if ($accessToken instanceof Collection) {
$this->client->setAccessToken($accessToken->toArray());
} else {
$this->client->setAccessToken($accessToken->makeHidden(['id'])->toArray());
}

if ($this->client->isAccessTokenExpired()) {
$accessRefreshToken = $this->fetchAccessTokenWithRefreshToken($this->client->getRefreshToken());
if (is_array($accessRefreshToken)) {
$this->client->setAccessToken($accessRefreshToken);
$this->setAccessToken($accessRefreshToken);
}
}
}
}

public function setAuthConfig(string $authConfig): GoogleClient
{
$this->client->setAuthConfig($authConfig);

return $this;
}

public function setApplicationName(string $applicationName): GoogleClient
{
$this->client->setApplicationName($applicationName);

return $this;
}

public function addScope(array $scopes): GoogleClient
{
$this->client->addScope($scopes);

return $this;
}

public function setAccessType(string $accessType = 'offline'): GoogleClient
{
$this->client->setAccessType($accessType);

return $this;
$client->setIncludeGrantedScopes(config('google-api.include_grant_scopes'));
}

public function setPrompt(string $prompt = 'none'): GoogleClient
public function initialize(): GoogleClient
{
$this->client->setPrompt($prompt);
$accessToken = $this->getAccessToken();

return $this;
}
if (! $accessToken) {
throw new GoogleClientException('Invalid or missing token.');
}

public function setApprovalPrompt(string $approvalPrompt = 'offline'): GoogleClient
{
$this->client->setApprovalPrompt($approvalPrompt);
if ($accessToken instanceof Collection) {
$this->client->setAccessToken($accessToken->toArray());
} else {
$this->client->setAccessToken($accessToken->makeHidden(['id'])->toArray());
}

return $this;
}
if ($this->client->isAccessTokenExpired()) {
$accessRefreshToken = $this->fetchAccessTokenWithRefreshToken($this->client->getRefreshToken());

public function setIncludeGrantedScopes(bool $includeGrantedScopes = true): GoogleClient
{
$this->client->setPrompt($includeGrantedScopes);
if (is_array($accessRefreshToken)) {
$this->client->setAccessToken($accessRefreshToken);
$this->setAccessToken($accessRefreshToken);
}
}

return $this;
}
Expand Down

0 comments on commit f1ee924

Please sign in to comment.