@@ -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 | } |