Skip to content
This repository has been archived by the owner on Oct 30, 2020. It is now read-only.

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattCast44 committed May 26, 2020
1 parent 9853947 commit d7a1b2a
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 14 deletions.
39 changes: 26 additions & 13 deletions src/Clients/GoogleClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,34 @@ class GoogleClient
*/
public function __construct()
{
return $this->setEnv()->setClient()->setScopes()->setSubject();
return $this->chain()
->setEnv()
->setClient()
->setScopes()
->setSubject();
}

/**
* Get the configured client
* A Single method to allow
* method chaining
*/
public function chain()
{
return $this;
}

/**
* Set the env variables
*
* @return \Google_Client
* @return self
*/
public function getClient()
public function setEnv()
{
return $this->client;
if (!getenv('GOOGLE_APPLICATION_CREDENTIALS')) {
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . config('gsuite.credentials_path'));
}

return $this;
}

/**
Expand All @@ -44,17 +61,13 @@ public function setClient()
}

/**
* Set the env variables
* Get the configured client
*
* @return self
* @return \Google_Client
*/
public function setEnv()
public function getClient()
{
if (!getenv('GOOGLE_APPLICATION_CREDENTIALS')) {
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . config('gsuite.credentials_path'));
}

return $this;
return $this->client;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/GSuiteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function boot()
// Publish config file...
$this->publishes([
__DIR__ . '/../config/gsuite.php' => config_path('gsuite.php'),
], 'gsuite');
], 'config');
}

public function register()
Expand Down
44 changes: 44 additions & 0 deletions src/Resources/Accounts/AccountsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,50 @@ public function makeAdmin(string $userKey)
return ($response->getStatusCode() == 204) ? true : false;
}

/**
* Undelete a G-Suite account
*
* @link https://developers.google.com/admin-sdk/directory/v1/reference/users/undelete
*
* @return bool
*/
public function undelete(string $userKey)
{
try {
$response = $this->client->undelete($userKey);
} catch (\Exception $e) {
throw $e;
}

if ($response->getStatusCode() == 204) {
if ($this->shouldCache()) {
$this->flushCache();
}

return true;
}

return false;
}

/**
* Update an account
*
* @link https://developers.google.com/admin-sdk/directory/v1/reference/users/update
*
* @return \Google_Service_Directory_User
*/
public function update(string $userKey, array $fields)
{
try {
$account = $this->client->update($userKey, new \Google_Service_Directory_User($fields));
} catch (\Exception $e) {
throw $e;
}

return $account;
}

/**
* Check the aviliablity of an email address
*
Expand Down

0 comments on commit d7a1b2a

Please sign in to comment.