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

Commit d7a1b2a

Browse files
committed
wip
1 parent 9853947 commit d7a1b2a

File tree

3 files changed

+71
-14
lines changed

3 files changed

+71
-14
lines changed

src/Clients/GoogleClient.php

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,34 @@ class GoogleClient
1616
*/
1717
public function __construct()
1818
{
19-
return $this->setEnv()->setClient()->setScopes()->setSubject();
19+
return $this->chain()
20+
->setEnv()
21+
->setClient()
22+
->setScopes()
23+
->setSubject();
2024
}
2125

2226
/**
23-
* Get the configured client
27+
* A Single method to allow
28+
* method chaining
29+
*/
30+
public function chain()
31+
{
32+
return $this;
33+
}
34+
35+
/**
36+
* Set the env variables
2437
*
25-
* @return \Google_Client
38+
* @return self
2639
*/
27-
public function getClient()
40+
public function setEnv()
2841
{
29-
return $this->client;
42+
if (!getenv('GOOGLE_APPLICATION_CREDENTIALS')) {
43+
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . config('gsuite.credentials_path'));
44+
}
45+
46+
return $this;
3047
}
3148

3249
/**
@@ -44,17 +61,13 @@ public function setClient()
4461
}
4562

4663
/**
47-
* Set the env variables
64+
* Get the configured client
4865
*
49-
* @return self
66+
* @return \Google_Client
5067
*/
51-
public function setEnv()
68+
public function getClient()
5269
{
53-
if (!getenv('GOOGLE_APPLICATION_CREDENTIALS')) {
54-
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . config('gsuite.credentials_path'));
55-
}
56-
57-
return $this;
70+
return $this->client;
5871
}
5972

6073
/**

src/GSuiteServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function boot()
2929
// Publish config file...
3030
$this->publishes([
3131
__DIR__ . '/../config/gsuite.php' => config_path('gsuite.php'),
32-
], 'gsuite');
32+
], 'config');
3333
}
3434

3535
public function register()

src/Resources/Accounts/AccountsRepository.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,50 @@ public function makeAdmin(string $userKey)
249249
return ($response->getStatusCode() == 204) ? true : false;
250250
}
251251

252+
/**
253+
* Undelete a G-Suite account
254+
*
255+
* @link https://developers.google.com/admin-sdk/directory/v1/reference/users/undelete
256+
*
257+
* @return bool
258+
*/
259+
public function undelete(string $userKey)
260+
{
261+
try {
262+
$response = $this->client->undelete($userKey);
263+
} catch (\Exception $e) {
264+
throw $e;
265+
}
266+
267+
if ($response->getStatusCode() == 204) {
268+
if ($this->shouldCache()) {
269+
$this->flushCache();
270+
}
271+
272+
return true;
273+
}
274+
275+
return false;
276+
}
277+
278+
/**
279+
* Update an account
280+
*
281+
* @link https://developers.google.com/admin-sdk/directory/v1/reference/users/update
282+
*
283+
* @return \Google_Service_Directory_User
284+
*/
285+
public function update(string $userKey, array $fields)
286+
{
287+
try {
288+
$account = $this->client->update($userKey, new \Google_Service_Directory_User($fields));
289+
} catch (\Exception $e) {
290+
throw $e;
291+
}
292+
293+
return $account;
294+
}
295+
252296
/**
253297
* Check the aviliablity of an email address
254298
*

0 commit comments

Comments
 (0)