@@ -10,7 +10,9 @@ |
||
10 | 10 | * @return string [description] |
11 | 11 | */ |
12 | 12 | function build_url_query(array $params, bool $urlEncode=true):?string { |
13 | - if ($params == null) return null; |
|
13 | + if ($params == null) { |
|
14 | + return null; |
|
15 | + } |
|
14 | 16 | $queryString = '?'; |
15 | 17 | foreach($params as $key => $val) { |
16 | 18 | $queryString .= $key."=".($urlEncode ? rawurlencode($val) : $val)."&"; |
@@ -20,7 +20,9 @@ discard block |
||
20 | 20 | get_instance()->load->splint('francis94c/ci-gmail', '%curl'); |
21 | 21 | get_instance()->load->splint('francis94c/ci-gmail', '%base64'); |
22 | 22 | |
23 | - if ($params != null) $this->init($params); |
|
23 | + if ($params != null) { |
|
24 | + $this->init($params); |
|
25 | + } |
|
24 | 26 | |
25 | 27 | spl_autoload_register(function($name) { |
26 | 28 | $oldPath = set_include_path(APPPATH . 'splints/' . self::PACKAGE . '/libraries'); |
@@ -66,7 +68,9 @@ discard block |
||
66 | 68 | public function getAuthorizeUrl(string $scope, string $redirectUri=null, string $responseType='code', string $accessType='offline', bool $prompt=false):string |
67 | 69 | { |
68 | 70 | $redirectUri = $redirectUri ?? $this->redirectUri; |
69 | - if ($scope == null) throw new Exception("GMail scope cannot be null"); |
|
71 | + if ($scope == null) { |
|
72 | + throw new Exception("GMail scope cannot be null"); |
|
73 | + } |
|
70 | 74 | $params = [ |
71 | 75 | 'client_id' => $this->clientId, |
72 | 76 | 'redirect_uri' => $redirectUri, |
@@ -74,7 +78,9 @@ discard block |
||
74 | 78 | 'response_type' => $responseType, |
75 | 79 | 'access_type' => $accessType |
76 | 80 | ]; |
77 | - if ($prompt) $params['prompt'] = 'consent'; |
|
81 | + if ($prompt) { |
|
82 | + $params['prompt'] = 'consent'; |
|
83 | + } |
|
78 | 84 | return self::AUTH_URL . build_url_query($params, false); |
79 | 85 | } |
80 | 86 | /** |
@@ -110,7 +116,9 @@ discard block |
||
110 | 116 | $response = curl_exec($ch); |
111 | 117 | $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
112 | 118 | curl_close($ch); |
113 | - if ($response !== false) return $this->process_response($code, $response); |
|
119 | + if ($response !== false) { |
|
120 | + return $this->process_response($code, $response); |
|
121 | + } |
|
114 | 122 | return null; |
115 | 123 | } |
116 | 124 | /** |
@@ -144,7 +152,9 @@ discard block |
||
144 | 152 | $response = curl_exec($ch); |
145 | 153 | $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
146 | 154 | curl_close($ch); |
147 | - if ($response !== false) return $this->process_response($code, $response); |
|
155 | + if ($response !== false) { |
|
156 | + return $this->process_response($code, $response); |
|
157 | + } |
|
148 | 158 | return null; |
149 | 159 | } |
150 | 160 | /** |
@@ -158,7 +168,9 @@ discard block |
||
158 | 168 | self::API . "$user/profile", |
159 | 169 | ["Authorization: Bearer $this->token"] |
160 | 170 | ); |
161 | - if ($response !== false) return $this->process_response($code, $response); |
|
171 | + if ($response !== false) { |
|
172 | + return $this->process_response($code, $response); |
|
173 | + } |
|
162 | 174 | return null; |
163 | 175 | } |
164 | 176 | /** |
@@ -192,7 +204,9 @@ discard block |
||
192 | 204 | ["Authorization: Bearer $this->token"], |
193 | 205 | $body |
194 | 206 | ); |
195 | - if ($response !== false) return $this->process_response($code, $response); |
|
207 | + if ($response !== false) { |
|
208 | + return $this->process_response($code, $response); |
|
209 | + } |
|
196 | 210 | return null; |
197 | 211 | } |
198 | 212 | /** |
@@ -207,7 +221,9 @@ discard block |
||
207 | 221 | self::API . "$userId/stop", |
208 | 222 | ["Authorization: Bearer $this->token"] |
209 | 223 | ); |
210 | - if ($response !== false) return $code == 204; |
|
224 | + if ($response !== false) { |
|
225 | + return $code == 204; |
|
226 | + } |
|
211 | 227 | return false; |
212 | 228 | } |
213 | 229 | /** |
@@ -245,11 +261,21 @@ discard block |
||
245 | 261 | { |
246 | 262 | $query = []; |
247 | 263 | |
248 | - if ($labelIds != null) $query['labelIds'] = $labelIds; |
|
249 | - if ($includeSpamTrash) $query['includeSpamTrash'] = $includeSpamTrash; |
|
250 | - if ($q != null) $query['q'] = $q; |
|
251 | - if ($pageToken != null) $query['pageToken'] = $pageToken; |
|
252 | - if ($maxMessages != null) $query['maxResults'] = $maxMessages; |
|
264 | + if ($labelIds != null) { |
|
265 | + $query['labelIds'] = $labelIds; |
|
266 | + } |
|
267 | + if ($includeSpamTrash) { |
|
268 | + $query['includeSpamTrash'] = $includeSpamTrash; |
|
269 | + } |
|
270 | + if ($q != null) { |
|
271 | + $query['q'] = $q; |
|
272 | + } |
|
273 | + if ($pageToken != null) { |
|
274 | + $query['pageToken'] = $pageToken; |
|
275 | + } |
|
276 | + if ($maxMessages != null) { |
|
277 | + $query['maxResults'] = $maxMessages; |
|
278 | + } |
|
253 | 279 | |
254 | 280 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( |
255 | 281 | self::API . "$userId/messages?" . http_build_query($query), |
@@ -285,15 +311,21 @@ discard block |
||
285 | 311 | { |
286 | 312 | $query = []; |
287 | 313 | |
288 | - if ($format != 'full' && $format != null) $query['format'] = $format; |
|
289 | - if ($metadataHeaders != null) $query['metadataHeaders'] = $metadataHeaders; |
|
314 | + if ($format != 'full' && $format != null) { |
|
315 | + $query['format'] = $format; |
|
316 | + } |
|
317 | + if ($metadataHeaders != null) { |
|
318 | + $query['metadataHeaders'] = $metadataHeaders; |
|
319 | + } |
|
290 | 320 | |
291 | 321 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( |
292 | 322 | self::API . "$userId/messages/$messageId?" . http_build_query($query), |
293 | 323 | ["Authorization: Bearer $this->token"] |
294 | 324 | ); |
295 | 325 | |
296 | - if ($response !== false) return new Message($response); |
|
326 | + if ($response !== false) { |
|
327 | + return new Message($response); |
|
328 | + } |
|
297 | 329 | |
298 | 330 | return null; |
299 | 331 | } |
@@ -16,7 +16,9 @@ |
||
16 | 16 | } |
17 | 17 | |
18 | 18 | function __invoke(string $url, array $header=[], array $body=null):array { |
19 | - if ($body != null) $body = json_encode($body); |
|
19 | + if ($body != null) { |
|
20 | + $body = json_encode($body); |
|
21 | + } |
|
20 | 22 | |
21 | 23 | $ch = curl_init($url); |
22 | 24 |