1 | <?php |
||
2 | |||
3 | namespace Dacastro4\LaravelGmail; |
||
4 | |||
5 | use Dacastro4\LaravelGmail\Exceptions\AuthException; |
||
6 | use Dacastro4\LaravelGmail\Services\Message; |
||
7 | use Illuminate\Support\Facades\Redirect; |
||
8 | |||
9 | class LaravelGmailClass extends GmailConnection |
||
10 | { |
||
11 | public function __construct($config, $userId = null) |
||
12 | { |
||
13 | if (class_basename($config) === 'Application') { |
||
14 | $config = $config['config']; |
||
15 | } |
||
16 | |||
17 | parent::__construct($config, $userId); |
||
18 | } |
||
19 | |||
20 | /** |
||
21 | * @return Message |
||
22 | * @throws AuthException |
||
23 | */ |
||
24 | public function message() |
||
25 | { |
||
26 | if (!$this->getToken()) { |
||
27 | throw new AuthException('No credentials found.'); |
||
28 | } |
||
29 | |||
30 | return new Message($this); |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * Returns the Gmail user email |
||
35 | * |
||
36 | * @return \Google_Service_Gmail_Profile |
||
37 | */ |
||
38 | public function user() |
||
39 | { |
||
40 | return $this->config('email'); |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * Updates / sets the current userId for the service |
||
45 | * |
||
46 | * @return \Google_Service_Gmail_Profile |
||
47 | */ |
||
48 | public function setUserId($userId) |
||
49 | { |
||
50 | $this->userId = $userId; |
||
51 | return $this; |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
52 | } |
||
53 | |||
54 | public function redirect() |
||
55 | { |
||
56 | return Redirect::to($this->getAuthUrl()); |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * Gets the URL to authorize the user |
||
61 | * |
||
62 | * @return string |
||
63 | */ |
||
64 | public function getAuthUrl() |
||
65 | { |
||
66 | return $this->createAuthUrl(); |
||
67 | } |
||
68 | |||
69 | public function logout() |
||
70 | { |
||
71 | $this->revokeToken(); |
||
72 | $this->deleteAccessToken(); |
||
73 | } |
||
74 | |||
75 | } |
||
76 |