@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | private $token; |
18 | 18 | private $userAgent = 'CodeIgniter GMail API'; |
19 | 19 | |
20 | - function __construct($params=null) { |
|
20 | + function __construct($params = null) { |
|
21 | 21 | get_instance()->load->splint('francis94c/ci-gmail', '%curl'); |
22 | 22 | if ($params != null) $this->init($params); |
23 | 23 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * [getClientId Get Client ID.] |
44 | 44 | * @return null|string Client ID. |
45 | 45 | */ |
46 | - public function getClientId():?string { |
|
46 | + public function getClientId(): ?string { |
|
47 | 47 | return $this->clientId; |
48 | 48 | } |
49 | 49 | /** |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | * @param bool $prompt Add the prompt=consent query to the URL. |
57 | 57 | * @return string Authorize URL |
58 | 58 | */ |
59 | - public function getAuthorizeUrl(string $scope, string $redirectUri=null, string $responseType='code', string $accessType='offline', bool $prompt=false):string |
|
59 | + public function getAuthorizeUrl(string $scope, string $redirectUri = null, string $responseType = 'code', string $accessType = 'offline', bool $prompt = false):string |
|
60 | 60 | { |
61 | 61 | $redirectUri = $redirectUri ?? $this->redirectUri; |
62 | 62 | if ($scope == null) throw new Exception("GMail scope cannot be null"); |
@@ -68,14 +68,14 @@ discard block |
||
68 | 68 | 'access_type' => $accessType |
69 | 69 | ]; |
70 | 70 | if ($prompt) $params['prompt'] = 'consent'; |
71 | - return self::AUTH_URL . build_url_query($params, false); |
|
71 | + return self::AUTH_URL.build_url_query($params, false); |
|
72 | 72 | } |
73 | 73 | /** |
74 | 74 | * [getToken description] |
75 | 75 | * @param string $code [description] |
76 | 76 | * @return [type] [description] |
77 | 77 | */ |
78 | - public function getToken(string $code, string $redirectUri=null):?array |
|
78 | + public function getToken(string $code, string $redirectUri = null): ?array |
|
79 | 79 | { |
80 | 80 | $redirectUri = $redirectUri ?? $this->redirectUri; |
81 | 81 | $ch = curl_init(self::TOKEN_URL); |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | ]); |
94 | 94 | $header = [ |
95 | 95 | 'Content-Type: application/x-www-form-urlencoded', |
96 | - 'Content-Length: ' . strlen($body) |
|
96 | + 'Content-Length: '.strlen($body) |
|
97 | 97 | ]; |
98 | 98 | curl_setopt($ch, CURLOPT_HTTPHEADER, $header); |
99 | 99 | curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent); |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * @param string $refreshToken [description] |
112 | 112 | * @return [type] [description] |
113 | 113 | */ |
114 | - public function refreshAccessToken(string $refreshToken):?array { |
|
114 | + public function refreshAccessToken(string $refreshToken): ?array { |
|
115 | 115 | $ch = curl_init(self::TOKEN_URL); |
116 | 116 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
117 | 117 | curl_setopt($ch, CURLINFO_HEADER_OUT, true); |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | ]); |
127 | 127 | $header = [ |
128 | 128 | 'Content-Type: application/x-www-form-urlencoded', |
129 | - 'Content-Length: ' . strlen($body) |
|
129 | + 'Content-Length: '.strlen($body) |
|
130 | 130 | ]; |
131 | 131 | curl_setopt($ch, CURLOPT_HTTPHEADER, $header); |
132 | 132 | curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent); |
@@ -146,9 +146,9 @@ discard block |
||
146 | 146 | * @param string $user [description] |
147 | 147 | * @return [type] [description] |
148 | 148 | */ |
149 | - public function getProfile(string $user='me'):?array { |
|
149 | + public function getProfile(string $user = 'me'): ?array { |
|
150 | 150 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( |
151 | - self::API . "$user/profile", |
|
151 | + self::API."$user/profile", |
|
152 | 152 | ["Authorization: Bearer $this->token"] |
153 | 153 | ); |
154 | 154 | if ($response !== false) return $this->process_response($code, $response); |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | * @param string $labelFilterAction [description] |
167 | 167 | * @return [type] [description] |
168 | 168 | */ |
169 | - public function watch(string $topic, $labelIds=null, string $userId='me', string $labelFilterAction='include'):?array { |
|
169 | + public function watch(string $topic, $labelIds = null, string $userId = 'me', string $labelFilterAction = 'include'): ?array { |
|
170 | 170 | $body = [ |
171 | 171 | 'topicName' => $topic, |
172 | 172 | 'labelFilterAction' => $labelFilterAction |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | } |
182 | 182 | |
183 | 183 | list($code, $response) = (new GMailCURL(GMailCURL::POST))( |
184 | - self::API . "$userId/watch", |
|
184 | + self::API."$userId/watch", |
|
185 | 185 | ["Authorization: Bearer $this->token"], |
186 | 186 | $body |
187 | 187 | ); |
@@ -194,10 +194,10 @@ discard block |
||
194 | 194 | * @param string $userId ID or Email Address of the user. |
195 | 195 | * @return bool [description] |
196 | 196 | */ |
197 | - public function endWatch(string $userId='me'):bool |
|
197 | + public function endWatch(string $userId = 'me'):bool |
|
198 | 198 | { |
199 | 199 | list($code, $response) = (new GMailCURL(GMailCURL::POST))( |
200 | - self::API . "$userId/stop", |
|
200 | + self::API."$userId/stop", |
|
201 | 201 | ["Authorization: Bearer $this->token"] |
202 | 202 | ); |
203 | 203 | if ($response !== false) return $code == 204; |
@@ -19,7 +19,9 @@ discard block |
||
19 | 19 | |
20 | 20 | function __construct($params=null) { |
21 | 21 | get_instance()->load->splint('francis94c/ci-gmail', '%curl'); |
22 | - if ($params != null) $this->init($params); |
|
22 | + if ($params != null) { |
|
23 | + $this->init($params); |
|
24 | + } |
|
23 | 25 | } |
24 | 26 | |
25 | 27 | /** |
@@ -59,7 +61,9 @@ discard block |
||
59 | 61 | public function getAuthorizeUrl(string $scope, string $redirectUri=null, string $responseType='code', string $accessType='offline', bool $prompt=false):string |
60 | 62 | { |
61 | 63 | $redirectUri = $redirectUri ?? $this->redirectUri; |
62 | - if ($scope == null) throw new Exception("GMail scope cannot be null"); |
|
64 | + if ($scope == null) { |
|
65 | + throw new Exception("GMail scope cannot be null"); |
|
66 | + } |
|
63 | 67 | $params = [ |
64 | 68 | 'client_id' => $this->clientId, |
65 | 69 | 'redirect_uri' => $redirectUri, |
@@ -67,7 +71,9 @@ discard block |
||
67 | 71 | 'response_type' => $responseType, |
68 | 72 | 'access_type' => $accessType |
69 | 73 | ]; |
70 | - if ($prompt) $params['prompt'] = 'consent'; |
|
74 | + if ($prompt) { |
|
75 | + $params['prompt'] = 'consent'; |
|
76 | + } |
|
71 | 77 | return self::AUTH_URL . build_url_query($params, false); |
72 | 78 | } |
73 | 79 | /** |
@@ -103,7 +109,9 @@ discard block |
||
103 | 109 | $response = curl_exec($ch); |
104 | 110 | $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
105 | 111 | curl_close($ch); |
106 | - if ($response !== false) return $this->process_response($code, $response); |
|
112 | + if ($response !== false) { |
|
113 | + return $this->process_response($code, $response); |
|
114 | + } |
|
107 | 115 | return null; |
108 | 116 | } |
109 | 117 | /** |
@@ -137,7 +145,9 @@ discard block |
||
137 | 145 | $response = curl_exec($ch); |
138 | 146 | $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
139 | 147 | curl_close($ch); |
140 | - if ($response !== false) return $this->process_response($code, $response); |
|
148 | + if ($response !== false) { |
|
149 | + return $this->process_response($code, $response); |
|
150 | + } |
|
141 | 151 | return null; |
142 | 152 | } |
143 | 153 | /** |
@@ -151,7 +161,9 @@ discard block |
||
151 | 161 | self::API . "$user/profile", |
152 | 162 | ["Authorization: Bearer $this->token"] |
153 | 163 | ); |
154 | - if ($response !== false) return $this->process_response($code, $response); |
|
164 | + if ($response !== false) { |
|
165 | + return $this->process_response($code, $response); |
|
166 | + } |
|
155 | 167 | return null; |
156 | 168 | } |
157 | 169 | /** |
@@ -185,7 +197,9 @@ discard block |
||
185 | 197 | ["Authorization: Bearer $this->token"], |
186 | 198 | $body |
187 | 199 | ); |
188 | - if ($response !== false) return $this->process_response($code, $response); |
|
200 | + if ($response !== false) { |
|
201 | + return $this->process_response($code, $response); |
|
202 | + } |
|
189 | 203 | return null; |
190 | 204 | } |
191 | 205 | /** |
@@ -200,7 +214,9 @@ discard block |
||
200 | 214 | self::API . "$userId/stop", |
201 | 215 | ["Authorization: Bearer $this->token"] |
202 | 216 | ); |
203 | - if ($response !== false) return $code == 204; |
|
217 | + if ($response !== false) { |
|
218 | + return $code == 204; |
|
219 | + } |
|
204 | 220 | return false; |
205 | 221 | } |
206 | 222 | /** |