@@ -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 | if (is_array($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 | if (file_exists(APPPATH.'splints/'.self::PACKAGE."/libraries/$name.php")) { |
@@ -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 | |
@@ -193,7 +205,9 @@ discard block |
||
| 193 | 205 | ["Authorization: Bearer $this->token"], |
| 194 | 206 | $body |
| 195 | 207 | ); |
| 196 | - if ($response !== false) return $this->process_response($code, $response); |
|
| 208 | + if ($response !== false) { |
|
| 209 | + return $this->process_response($code, $response); |
|
| 210 | + } |
|
| 197 | 211 | return null; |
| 198 | 212 | } |
| 199 | 213 | |
@@ -209,7 +223,9 @@ discard block |
||
| 209 | 223 | self::API . "$userId/stop", |
| 210 | 224 | ["Authorization: Bearer $this->token"] |
| 211 | 225 | ); |
| 212 | - if ($response !== false) return $code == 204; |
|
| 226 | + if ($response !== false) { |
|
| 227 | + return $code == 204; |
|
| 228 | + } |
|
| 213 | 229 | return false; |
| 214 | 230 | } |
| 215 | 231 | |
@@ -248,11 +264,21 @@ discard block |
||
| 248 | 264 | { |
| 249 | 265 | $query = []; |
| 250 | 266 | |
| 251 | - if ($labelIds != null) $query['labelIds'] = $labelIds; |
|
| 252 | - if ($includeSpamTrash) $query['includeSpamTrash'] = $includeSpamTrash; |
|
| 253 | - if ($q != null) $query['q'] = $q; |
|
| 254 | - if ($pageToken != null) $query['pageToken'] = $pageToken; |
|
| 255 | - if ($maxMessages != null) $query['maxResults'] = $maxMessages; |
|
| 267 | + if ($labelIds != null) { |
|
| 268 | + $query['labelIds'] = $labelIds; |
|
| 269 | + } |
|
| 270 | + if ($includeSpamTrash) { |
|
| 271 | + $query['includeSpamTrash'] = $includeSpamTrash; |
|
| 272 | + } |
|
| 273 | + if ($q != null) { |
|
| 274 | + $query['q'] = $q; |
|
| 275 | + } |
|
| 276 | + if ($pageToken != null) { |
|
| 277 | + $query['pageToken'] = $pageToken; |
|
| 278 | + } |
|
| 279 | + if ($maxMessages != null) { |
|
| 280 | + $query['maxResults'] = $maxMessages; |
|
| 281 | + } |
|
| 256 | 282 | |
| 257 | 283 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( |
| 258 | 284 | self::API . "$userId/messages" . build_url_query($query), |
@@ -288,15 +314,21 @@ discard block |
||
| 288 | 314 | { |
| 289 | 315 | $query = []; |
| 290 | 316 | |
| 291 | - if ($format != 'full' && $format != null) $query['format'] = $format; |
|
| 292 | - if ($metadataHeaders != null) $query['metadataHeaders'] = $metadataHeaders; |
|
| 317 | + if ($format != 'full' && $format != null) { |
|
| 318 | + $query['format'] = $format; |
|
| 319 | + } |
|
| 320 | + if ($metadataHeaders != null) { |
|
| 321 | + $query['metadataHeaders'] = $metadataHeaders; |
|
| 322 | + } |
|
| 293 | 323 | |
| 294 | 324 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( |
| 295 | 325 | self::API . "$userId/messages/$messageId?" . http_build_query($query), |
| 296 | 326 | ["Authorization: Bearer $this->token"] |
| 297 | 327 | ); |
| 298 | 328 | |
| 299 | - if ($response !== false) return new Message($response); |
|
| 329 | + if ($response !== false) { |
|
| 330 | + return new Message($response); |
|
| 331 | + } |
|
| 300 | 332 | |
| 301 | 333 | return null; |
| 302 | 334 | } |