@@ -41,7 +41,7 @@ |
||
41 | 41 | * @date 2019-11-22 |
42 | 42 | * @return string [description] |
43 | 43 | */ |
44 | - public function body():?string |
|
44 | + public function body(): ?string |
|
45 | 45 | { |
46 | 46 | if (isset($this->message->payload->body->data)) { |
47 | 47 | return base64url_decode($this->message->payload->body->data); |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | private $token; |
19 | 19 | private $userAgent = 'CodeIgniter GMail API'; |
20 | 20 | |
21 | - function __construct($params=null) { |
|
21 | + function __construct($params = null) { |
|
22 | 22 | get_instance()->load->splint('francis94c/ci-gmail', '%curl'); |
23 | 23 | get_instance()->load->splint('francis94c/ci-gmail', '%base64'); |
24 | 24 | if ($params != null) $this->init($params); |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | * [getClientId Get Client ID.] |
46 | 46 | * @return null|string Client ID. |
47 | 47 | */ |
48 | - public function getClientId():?string { |
|
48 | + public function getClientId(): ?string { |
|
49 | 49 | return $this->clientId; |
50 | 50 | } |
51 | 51 | /** |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | * @param bool $prompt Add the prompt=consent query to the URL. |
59 | 59 | * @return string Authorize URL |
60 | 60 | */ |
61 | - public function getAuthorizeUrl(string $scope, string $redirectUri=null, string $responseType='code', string $accessType='offline', bool $prompt=false):string |
|
61 | + public function getAuthorizeUrl(string $scope, string $redirectUri = null, string $responseType = 'code', string $accessType = 'offline', bool $prompt = false):string |
|
62 | 62 | { |
63 | 63 | $redirectUri = $redirectUri ?? $this->redirectUri; |
64 | 64 | if ($scope == null) throw new Exception("GMail scope cannot be null"); |
@@ -70,14 +70,14 @@ discard block |
||
70 | 70 | 'access_type' => $accessType |
71 | 71 | ]; |
72 | 72 | if ($prompt) $params['prompt'] = 'consent'; |
73 | - return self::AUTH_URL . build_url_query($params, false); |
|
73 | + return self::AUTH_URL.build_url_query($params, false); |
|
74 | 74 | } |
75 | 75 | /** |
76 | 76 | * [getToken description] |
77 | 77 | * @param string $code [description] |
78 | 78 | * @return [type] [description] |
79 | 79 | */ |
80 | - public function getToken(string $code, string $redirectUri=null):?array |
|
80 | + public function getToken(string $code, string $redirectUri = null): ?array |
|
81 | 81 | { |
82 | 82 | $redirectUri = $redirectUri ?? $this->redirectUri; |
83 | 83 | $ch = curl_init(self::TOKEN_URL); |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | ]); |
96 | 96 | $header = [ |
97 | 97 | 'Content-Type: application/x-www-form-urlencoded', |
98 | - 'Content-Length: ' . strlen($body) |
|
98 | + 'Content-Length: '.strlen($body) |
|
99 | 99 | ]; |
100 | 100 | curl_setopt($ch, CURLOPT_HTTPHEADER, $header); |
101 | 101 | curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent); |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | * @param string $refreshToken [description] |
114 | 114 | * @return [type] [description] |
115 | 115 | */ |
116 | - public function refreshAccessToken(string $refreshToken):?array { |
|
116 | + public function refreshAccessToken(string $refreshToken): ?array { |
|
117 | 117 | $ch = curl_init(self::TOKEN_URL); |
118 | 118 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
119 | 119 | curl_setopt($ch, CURLINFO_HEADER_OUT, true); |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | ]); |
129 | 129 | $header = [ |
130 | 130 | 'Content-Type: application/x-www-form-urlencoded', |
131 | - 'Content-Length: ' . strlen($body) |
|
131 | + 'Content-Length: '.strlen($body) |
|
132 | 132 | ]; |
133 | 133 | curl_setopt($ch, CURLOPT_HTTPHEADER, $header); |
134 | 134 | curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent); |
@@ -148,9 +148,9 @@ discard block |
||
148 | 148 | * @param string $user [description] |
149 | 149 | * @return [type] [description] |
150 | 150 | */ |
151 | - public function getProfile(string $user='me'):?array { |
|
151 | + public function getProfile(string $user = 'me'): ?array { |
|
152 | 152 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( |
153 | - self::API . "$user/profile", |
|
153 | + self::API."$user/profile", |
|
154 | 154 | ["Authorization: Bearer $this->token"] |
155 | 155 | ); |
156 | 156 | if ($response !== false) return $this->process_response($code, $response); |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | * @param string $labelFilterAction [description] |
169 | 169 | * @return [type] [description] |
170 | 170 | */ |
171 | - public function watch(string $topic, $labelIds=null, string $userId='me', string $labelFilterAction='include'):?array { |
|
171 | + public function watch(string $topic, $labelIds = null, string $userId = 'me', string $labelFilterAction = 'include'): ?array { |
|
172 | 172 | $body = [ |
173 | 173 | 'topicName' => $topic, |
174 | 174 | 'labelFilterAction' => $labelFilterAction |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | } |
184 | 184 | |
185 | 185 | list($code, $response) = (new GMailCURL(GMailCURL::POST))( |
186 | - self::API . "$userId/watch", |
|
186 | + self::API."$userId/watch", |
|
187 | 187 | ["Authorization: Bearer $this->token"], |
188 | 188 | $body |
189 | 189 | ); |
@@ -196,10 +196,10 @@ discard block |
||
196 | 196 | * @param string $userId ID or Email Address of the user. |
197 | 197 | * @return bool [description] |
198 | 198 | */ |
199 | - public function endWatch(string $userId='me'):bool |
|
199 | + public function endWatch(string $userId = 'me'):bool |
|
200 | 200 | { |
201 | 201 | list($code, $response) = (new GMailCURL(GMailCURL::POST))( |
202 | - self::API . "$userId/stop", |
|
202 | + self::API."$userId/stop", |
|
203 | 203 | ["Authorization: Bearer $this->token"] |
204 | 204 | ); |
205 | 205 | if ($response !== false) return $code == 204; |
@@ -211,10 +211,10 @@ discard block |
||
211 | 211 | * @param string $userID [description] |
212 | 212 | * @return null|array [description] |
213 | 213 | */ |
214 | - public function getLabels(string $userId='me'):?array |
|
214 | + public function getLabels(string $userId = 'me'): ?array |
|
215 | 215 | { |
216 | 216 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( |
217 | - self::API . "$userId/labels", |
|
217 | + self::API."$userId/labels", |
|
218 | 218 | ["Authorization: Bearer $this->token"] |
219 | 219 | ); |
220 | 220 | if ($response !== false) { |
@@ -234,9 +234,9 @@ discard block |
||
234 | 234 | * @param [type] $truncateAfter [description] |
235 | 235 | * @return [type] [description] |
236 | 236 | */ |
237 | - public function getMessages(string $userId='me', array $labelIds=null, |
|
238 | - string $q=null, int $maxMessages=null, string $pageToken=null, bool $includeSpamTrash=false, |
|
239 | - $truncateAfter=null):?object |
|
237 | + public function getMessages(string $userId = 'me', array $labelIds = null, |
|
238 | + string $q = null, int $maxMessages = null, string $pageToken = null, bool $includeSpamTrash = false, |
|
239 | + $truncateAfter = null): ?object |
|
240 | 240 | { |
241 | 241 | $query = []; |
242 | 242 | |
@@ -247,14 +247,14 @@ discard block |
||
247 | 247 | if ($maxMessages != null) $query['maxResults'] = $maxMessages; |
248 | 248 | |
249 | 249 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( |
250 | - self::API . "$userId/messages?" . http_build_query($query), |
|
250 | + self::API."$userId/messages?".http_build_query($query), |
|
251 | 251 | ["Authorization: Bearer $this->token"] |
252 | 252 | ); |
253 | 253 | |
254 | 254 | if ($response !== false) { |
255 | 255 | if ($truncateAfter != null && $code == 200) { |
256 | 256 | $response = json_decode($response); |
257 | - $response->messages = array_filter($response->messages, function ($e) use ($truncateAfter) { |
|
257 | + $response->messages = array_filter($response->messages, function($e) use ($truncateAfter) { |
|
258 | 258 | return strcmp($truncateAfter, $e->id) <= 0; |
259 | 259 | }); |
260 | 260 | $response->{self::HTTP_CODE} = $code; |
@@ -275,8 +275,8 @@ discard block |
||
275 | 275 | * @param [type] $metadataHeaders [description] |
276 | 276 | * @return Message|null [description] |
277 | 277 | */ |
278 | - public function getMessage(string $userId='me', string $messageId, |
|
279 | - string $format='full', array $metadataHeaders=null):?Message |
|
278 | + public function getMessage(string $userId = 'me', string $messageId, |
|
279 | + string $format = 'full', array $metadataHeaders = null): ?Message |
|
280 | 280 | { |
281 | 281 | $query = []; |
282 | 282 | |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | if ($metadataHeaders != null) $query['metadataHeaders'] = $metadataHeaders; |
285 | 285 | |
286 | 286 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( |
287 | - self::API . "$userId/messages/$messageId?" . http_build_query($query), |
|
287 | + self::API."$userId/messages/$messageId?".http_build_query($query), |
|
288 | 288 | ["Authorization: Bearer $this->token"] |
289 | 289 | ); |
290 | 290 |
@@ -21,7 +21,9 @@ discard block |
||
21 | 21 | function __construct($params=null) { |
22 | 22 | get_instance()->load->splint('francis94c/ci-gmail', '%curl'); |
23 | 23 | get_instance()->load->splint('francis94c/ci-gmail', '%base64'); |
24 | - if ($params != null) $this->init($params); |
|
24 | + if ($params != null) { |
|
25 | + $this->init($params); |
|
26 | + } |
|
25 | 27 | } |
26 | 28 | |
27 | 29 | /** |
@@ -61,7 +63,9 @@ discard block |
||
61 | 63 | public function getAuthorizeUrl(string $scope, string $redirectUri=null, string $responseType='code', string $accessType='offline', bool $prompt=false):string |
62 | 64 | { |
63 | 65 | $redirectUri = $redirectUri ?? $this->redirectUri; |
64 | - if ($scope == null) throw new Exception("GMail scope cannot be null"); |
|
66 | + if ($scope == null) { |
|
67 | + throw new Exception("GMail scope cannot be null"); |
|
68 | + } |
|
65 | 69 | $params = [ |
66 | 70 | 'client_id' => $this->clientId, |
67 | 71 | 'redirect_uri' => $redirectUri, |
@@ -69,7 +73,9 @@ discard block |
||
69 | 73 | 'response_type' => $responseType, |
70 | 74 | 'access_type' => $accessType |
71 | 75 | ]; |
72 | - if ($prompt) $params['prompt'] = 'consent'; |
|
76 | + if ($prompt) { |
|
77 | + $params['prompt'] = 'consent'; |
|
78 | + } |
|
73 | 79 | return self::AUTH_URL . build_url_query($params, false); |
74 | 80 | } |
75 | 81 | /** |
@@ -105,7 +111,9 @@ discard block |
||
105 | 111 | $response = curl_exec($ch); |
106 | 112 | $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
107 | 113 | curl_close($ch); |
108 | - if ($response !== false) return $this->process_response($code, $response); |
|
114 | + if ($response !== false) { |
|
115 | + return $this->process_response($code, $response); |
|
116 | + } |
|
109 | 117 | return null; |
110 | 118 | } |
111 | 119 | /** |
@@ -139,7 +147,9 @@ discard block |
||
139 | 147 | $response = curl_exec($ch); |
140 | 148 | $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
141 | 149 | curl_close($ch); |
142 | - if ($response !== false) return $this->process_response($code, $response); |
|
150 | + if ($response !== false) { |
|
151 | + return $this->process_response($code, $response); |
|
152 | + } |
|
143 | 153 | return null; |
144 | 154 | } |
145 | 155 | /** |
@@ -153,7 +163,9 @@ discard block |
||
153 | 163 | self::API . "$user/profile", |
154 | 164 | ["Authorization: Bearer $this->token"] |
155 | 165 | ); |
156 | - if ($response !== false) return $this->process_response($code, $response); |
|
166 | + if ($response !== false) { |
|
167 | + return $this->process_response($code, $response); |
|
168 | + } |
|
157 | 169 | return null; |
158 | 170 | } |
159 | 171 | /** |
@@ -187,7 +199,9 @@ discard block |
||
187 | 199 | ["Authorization: Bearer $this->token"], |
188 | 200 | $body |
189 | 201 | ); |
190 | - if ($response !== false) return $this->process_response($code, $response); |
|
202 | + if ($response !== false) { |
|
203 | + return $this->process_response($code, $response); |
|
204 | + } |
|
191 | 205 | return null; |
192 | 206 | } |
193 | 207 | /** |
@@ -202,7 +216,9 @@ discard block |
||
202 | 216 | self::API . "$userId/stop", |
203 | 217 | ["Authorization: Bearer $this->token"] |
204 | 218 | ); |
205 | - if ($response !== false) return $code == 204; |
|
219 | + if ($response !== false) { |
|
220 | + return $code == 204; |
|
221 | + } |
|
206 | 222 | return false; |
207 | 223 | } |
208 | 224 | /** |
@@ -240,11 +256,21 @@ discard block |
||
240 | 256 | { |
241 | 257 | $query = []; |
242 | 258 | |
243 | - if ($labelIds != null) $query['labelIds'] = $labelIds; |
|
244 | - if ($includeSpamTrash) $query['includeSpamTrash'] = $includeSpamTrash; |
|
245 | - if ($q != null) $query['q'] = $q; |
|
246 | - if ($pageToken != null) $query['pageToken'] = $pageToken; |
|
247 | - if ($maxMessages != null) $query['maxResults'] = $maxMessages; |
|
259 | + if ($labelIds != null) { |
|
260 | + $query['labelIds'] = $labelIds; |
|
261 | + } |
|
262 | + if ($includeSpamTrash) { |
|
263 | + $query['includeSpamTrash'] = $includeSpamTrash; |
|
264 | + } |
|
265 | + if ($q != null) { |
|
266 | + $query['q'] = $q; |
|
267 | + } |
|
268 | + if ($pageToken != null) { |
|
269 | + $query['pageToken'] = $pageToken; |
|
270 | + } |
|
271 | + if ($maxMessages != null) { |
|
272 | + $query['maxResults'] = $maxMessages; |
|
273 | + } |
|
248 | 274 | |
249 | 275 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( |
250 | 276 | self::API . "$userId/messages?" . http_build_query($query), |
@@ -280,15 +306,21 @@ discard block |
||
280 | 306 | { |
281 | 307 | $query = []; |
282 | 308 | |
283 | - if ($format != 'full' && $format != null) $query['format'] = $format; |
|
284 | - if ($metadataHeaders != null) $query['metadataHeaders'] = $metadataHeaders; |
|
309 | + if ($format != 'full' && $format != null) { |
|
310 | + $query['format'] = $format; |
|
311 | + } |
|
312 | + if ($metadataHeaders != null) { |
|
313 | + $query['metadataHeaders'] = $metadataHeaders; |
|
314 | + } |
|
285 | 315 | |
286 | 316 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( |
287 | 317 | self::API . "$userId/messages/$messageId?" . http_build_query($query), |
288 | 318 | ["Authorization: Bearer $this->token"] |
289 | 319 | ); |
290 | 320 | |
291 | - if ($response !== false) return new Message($response); |
|
321 | + if ($response !== false) { |
|
322 | + return new Message($response); |
|
323 | + } |
|
292 | 324 | |
293 | 325 | return null; |
294 | 326 | } |
@@ -11,7 +11,7 @@ |
||
11 | 11 | * |
12 | 12 | * @return string|bool Decoded String. |
13 | 13 | */ |
14 | - function base64url_decode(string $data, bool $strict=false) { |
|
14 | + function base64url_decode(string $data, bool $strict = false) { |
|
15 | 15 | $b64 = strtr($data, '-_', '+/'); |
16 | 16 | return base64_decode($b64, $strict); |
17 | 17 | } |