@@ -19,7 +19,9 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | function __construct($params=null) { |
| 21 | 21 | get_instance()->load->splint('francis94c/ci-gmail', '%curl'); |
| 22 | - if ($params != null) $this->init($params); |
|
| 22 | + if ($params != null) { |
|
| 23 | + $this->init($params); |
|
| 24 | + } |
|
| 23 | 25 | } |
| 24 | 26 | |
| 25 | 27 | /** |
@@ -59,7 +61,9 @@ discard block |
||
| 59 | 61 | public function getAuthorizeUrl(string $scope, string $redirectUri=null, string $responseType='code', string $accessType='offline', bool $prompt=false):string |
| 60 | 62 | { |
| 61 | 63 | $redirectUri = $redirectUri ?? $this->redirectUri; |
| 62 | - if ($scope == null) throw new Exception("GMail scope cannot be null"); |
|
| 64 | + if ($scope == null) { |
|
| 65 | + throw new Exception("GMail scope cannot be null"); |
|
| 66 | + } |
|
| 63 | 67 | $params = [ |
| 64 | 68 | 'client_id' => $this->clientId, |
| 65 | 69 | 'redirect_uri' => $redirectUri, |
@@ -67,7 +71,9 @@ discard block |
||
| 67 | 71 | 'response_type' => $responseType, |
| 68 | 72 | 'access_type' => $accessType |
| 69 | 73 | ]; |
| 70 | - if ($prompt) $params['prompt'] = 'consent'; |
|
| 74 | + if ($prompt) { |
|
| 75 | + $params['prompt'] = 'consent'; |
|
| 76 | + } |
|
| 71 | 77 | return self::AUTH_URL . build_url_query($params, false); |
| 72 | 78 | } |
| 73 | 79 | /** |
@@ -103,7 +109,9 @@ discard block |
||
| 103 | 109 | $response = curl_exec($ch); |
| 104 | 110 | $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
| 105 | 111 | curl_close($ch); |
| 106 | - if ($response !== false) return $this->process_response($code, $response); |
|
| 112 | + if ($response !== false) { |
|
| 113 | + return $this->process_response($code, $response); |
|
| 114 | + } |
|
| 107 | 115 | return null; |
| 108 | 116 | } |
| 109 | 117 | /** |
@@ -137,7 +145,9 @@ discard block |
||
| 137 | 145 | $response = curl_exec($ch); |
| 138 | 146 | $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
| 139 | 147 | curl_close($ch); |
| 140 | - if ($response !== false) return $this->process_response($code, $response); |
|
| 148 | + if ($response !== false) { |
|
| 149 | + return $this->process_response($code, $response); |
|
| 150 | + } |
|
| 141 | 151 | return null; |
| 142 | 152 | } |
| 143 | 153 | /** |
@@ -151,7 +161,9 @@ discard block |
||
| 151 | 161 | self::API . "$user/profile", |
| 152 | 162 | ["Authorization: Bearer $this->token"] |
| 153 | 163 | ); |
| 154 | - if ($response !== false) return $this->process_response($code, $response); |
|
| 164 | + if ($response !== false) { |
|
| 165 | + return $this->process_response($code, $response); |
|
| 166 | + } |
|
| 155 | 167 | return null; |
| 156 | 168 | } |
| 157 | 169 | /** |
@@ -185,7 +197,9 @@ discard block |
||
| 185 | 197 | ["Authorization: Bearer $this->token"], |
| 186 | 198 | $body |
| 187 | 199 | ); |
| 188 | - if ($response !== false) return $this->process_response($code, $response); |
|
| 200 | + if ($response !== false) { |
|
| 201 | + return $this->process_response($code, $response); |
|
| 202 | + } |
|
| 189 | 203 | return null; |
| 190 | 204 | } |
| 191 | 205 | /** |
@@ -200,7 +214,9 @@ discard block |
||
| 200 | 214 | self::API . "$userId/stop", |
| 201 | 215 | ["Authorization: Bearer $this->token"] |
| 202 | 216 | ); |
| 203 | - if ($response !== false) return $code == 204; |
|
| 217 | + if ($response !== false) { |
|
| 218 | + return $code == 204; |
|
| 219 | + } |
|
| 204 | 220 | return false; |
| 205 | 221 | } |
| 206 | 222 | /** |
@@ -238,11 +254,21 @@ discard block |
||
| 238 | 254 | { |
| 239 | 255 | $query = []; |
| 240 | 256 | |
| 241 | - if ($labelIds != null) $query['labelIds'] = $labelIds; |
|
| 242 | - if ($includeSpamTrash) $query['includeSpamTrash'] = $includeSpamTrash; |
|
| 243 | - if ($q != null) $query['q'] = $q; |
|
| 244 | - if ($pageToken != null) $query['pageToken'] = $pageToken; |
|
| 245 | - if ($maxEmails != null) $query['maxResults'] = $maxEmails; |
|
| 257 | + if ($labelIds != null) { |
|
| 258 | + $query['labelIds'] = $labelIds; |
|
| 259 | + } |
|
| 260 | + if ($includeSpamTrash) { |
|
| 261 | + $query['includeSpamTrash'] = $includeSpamTrash; |
|
| 262 | + } |
|
| 263 | + if ($q != null) { |
|
| 264 | + $query['q'] = $q; |
|
| 265 | + } |
|
| 266 | + if ($pageToken != null) { |
|
| 267 | + $query['pageToken'] = $pageToken; |
|
| 268 | + } |
|
| 269 | + if ($maxEmails != null) { |
|
| 270 | + $query['maxResults'] = $maxEmails; |
|
| 271 | + } |
|
| 246 | 272 | |
| 247 | 273 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( |
| 248 | 274 | self::API . "$userId/messages?" . http_build_query($query), |