@@ -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 | |
@@ -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")) { |
@@ -67,7 +69,9 @@ discard block |
||
| 67 | 69 | string $responseType='code', string $accessType='offline', bool $prompt=false):string |
| 68 | 70 | { |
| 69 | 71 | $redirectUri = $redirectUri ?? $this->redirectUri; |
| 70 | - if ($scope == null) throw new Exception("GMail scope cannot be null"); |
|
| 72 | + if ($scope == null) { |
|
| 73 | + throw new Exception("GMail scope cannot be null"); |
|
| 74 | + } |
|
| 71 | 75 | $params = [ |
| 72 | 76 | 'client_id' => $this->clientId, |
| 73 | 77 | 'redirect_uri' => $redirectUri, |
@@ -75,7 +79,9 @@ discard block |
||
| 75 | 79 | 'response_type' => $responseType, |
| 76 | 80 | 'access_type' => $accessType |
| 77 | 81 | ]; |
| 78 | - if ($prompt) $params['prompt'] = 'consent'; |
|
| 82 | + if ($prompt) { |
|
| 83 | + $params['prompt'] = 'consent'; |
|
| 84 | + } |
|
| 79 | 85 | return self::AUTH_URL . build_url_query($params, false); |
| 80 | 86 | } |
| 81 | 87 | /** |
@@ -111,7 +117,9 @@ discard block |
||
| 111 | 117 | $response = curl_exec($ch); |
| 112 | 118 | $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
| 113 | 119 | curl_close($ch); |
| 114 | - if ($response !== false) return $this->process_response($code, $response); |
|
| 120 | + if ($response !== false) { |
|
| 121 | + return $this->process_response($code, $response); |
|
| 122 | + } |
|
| 115 | 123 | return null; |
| 116 | 124 | } |
| 117 | 125 | /** |
@@ -146,7 +154,9 @@ discard block |
||
| 146 | 154 | $response = curl_exec($ch); |
| 147 | 155 | $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
| 148 | 156 | curl_close($ch); |
| 149 | - if ($response !== false) return $this->process_response($code, $response); |
|
| 157 | + if ($response !== false) { |
|
| 158 | + return $this->process_response($code, $response); |
|
| 159 | + } |
|
| 150 | 160 | return null; |
| 151 | 161 | } |
| 152 | 162 | /** |
@@ -161,7 +171,9 @@ discard block |
||
| 161 | 171 | self::API . "$user/profile", |
| 162 | 172 | ["Authorization: Bearer $this->token"] |
| 163 | 173 | ); |
| 164 | - if ($response !== false) return $this->process_response($code, $response); |
|
| 174 | + if ($response !== false) { |
|
| 175 | + return $this->process_response($code, $response); |
|
| 176 | + } |
|
| 165 | 177 | return null; |
| 166 | 178 | } |
| 167 | 179 | |
@@ -198,7 +210,9 @@ discard block |
||
| 198 | 210 | ["Authorization: Bearer $this->token"], |
| 199 | 211 | $body |
| 200 | 212 | ); |
| 201 | - if ($response !== false) return $this->process_response($code, $response); |
|
| 213 | + if ($response !== false) { |
|
| 214 | + return $this->process_response($code, $response); |
|
| 215 | + } |
|
| 202 | 216 | return null; |
| 203 | 217 | } |
| 204 | 218 | |
@@ -214,7 +228,9 @@ discard block |
||
| 214 | 228 | self::API . "$userId/stop", |
| 215 | 229 | ["Authorization: Bearer $this->token"] |
| 216 | 230 | ); |
| 217 | - if ($response !== false) return $code == 204; |
|
| 231 | + if ($response !== false) { |
|
| 232 | + return $code == 204; |
|
| 233 | + } |
|
| 218 | 234 | return false; |
| 219 | 235 | } |
| 220 | 236 | |
@@ -253,11 +269,21 @@ discard block |
||
| 253 | 269 | { |
| 254 | 270 | $query = []; |
| 255 | 271 | |
| 256 | - if ($labelIds != null) $query['labelIds'] = $labelIds; |
|
| 257 | - if ($includeSpamTrash) $query['includeSpamTrash'] = $includeSpamTrash; |
|
| 258 | - if ($q != null) $query['q'] = $q; |
|
| 259 | - if ($pageToken != null) $query['pageToken'] = $pageToken; |
|
| 260 | - if ($maxMessages != null) $query['maxResults'] = $maxMessages; |
|
| 272 | + if ($labelIds != null) { |
|
| 273 | + $query['labelIds'] = $labelIds; |
|
| 274 | + } |
|
| 275 | + if ($includeSpamTrash) { |
|
| 276 | + $query['includeSpamTrash'] = $includeSpamTrash; |
|
| 277 | + } |
|
| 278 | + if ($q != null) { |
|
| 279 | + $query['q'] = $q; |
|
| 280 | + } |
|
| 281 | + if ($pageToken != null) { |
|
| 282 | + $query['pageToken'] = $pageToken; |
|
| 283 | + } |
|
| 284 | + if ($maxMessages != null) { |
|
| 285 | + $query['maxResults'] = $maxMessages; |
|
| 286 | + } |
|
| 261 | 287 | |
| 262 | 288 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( |
| 263 | 289 | self::API . "$userId/messages" . build_url_query($query), |
@@ -293,15 +319,21 @@ discard block |
||
| 293 | 319 | { |
| 294 | 320 | $query = []; |
| 295 | 321 | |
| 296 | - if ($format != 'full' && $format != null) $query['format'] = $format; |
|
| 297 | - if ($metadataHeaders != null) $query['metadataHeaders'] = $metadataHeaders; |
|
| 322 | + if ($format != 'full' && $format != null) { |
|
| 323 | + $query['format'] = $format; |
|
| 324 | + } |
|
| 325 | + if ($metadataHeaders != null) { |
|
| 326 | + $query['metadataHeaders'] = $metadataHeaders; |
|
| 327 | + } |
|
| 298 | 328 | |
| 299 | 329 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( |
| 300 | 330 | self::API . "$userId/messages/$messageId?" . http_build_query($query), |
| 301 | 331 | ["Authorization: Bearer $this->token"] |
| 302 | 332 | ); |
| 303 | 333 | |
| 304 | - if ($response !== false) return new Message($response); |
|
| 334 | + if ($response !== false) { |
|
| 335 | + return new Message($response); |
|
| 336 | + } |
|
| 305 | 337 | |
| 306 | 338 | return null; |
| 307 | 339 | } |