diff --git a/src/Clients/GoogleClient.php b/src/Clients/GoogleClient.php index 9bc1dbd..d497563 100644 --- a/src/Clients/GoogleClient.php +++ b/src/Clients/GoogleClient.php @@ -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; } /** @@ -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; } /** diff --git a/src/GSuiteServiceProvider.php b/src/GSuiteServiceProvider.php index 152f1f3..47f2f1e 100644 --- a/src/GSuiteServiceProvider.php +++ b/src/GSuiteServiceProvider.php @@ -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() diff --git a/src/Resources/Accounts/AccountsRepository.php b/src/Resources/Accounts/AccountsRepository.php index 9aa9827..f11fc2f 100644 --- a/src/Resources/Accounts/AccountsRepository.php +++ b/src/Resources/Accounts/AccountsRepository.php @@ -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 *