@@ -9,10 +9,10 @@ |
||
9 | 9 | * @param boolean $urlEncode [description] |
10 | 10 | * @return string [description] |
11 | 11 | */ |
12 | - function build_url_query(array $params, bool $urlEncode=true):?string { |
|
12 | + function build_url_query(array $params, bool $urlEncode = true): ?string { |
|
13 | 13 | if ($params == null) return null; |
14 | 14 | $queryString = '?'; |
15 | - foreach($params as $key => $val) { |
|
15 | + foreach ($params as $key => $val) { |
|
16 | 16 | if (is_array($val)) { |
17 | 17 | foreach ($val as $value) { |
18 | 18 | $queryString .= $key."=".($urlEncode ? rawurlencode($value) : $value)."&"; |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | private $token; |
16 | 16 | private $userAgent = 'CodeIgniter GMail API'; |
17 | 17 | |
18 | - function __construct($params=null) |
|
18 | + function __construct($params = null) |
|
19 | 19 | { |
20 | 20 | get_instance()->load->splint('francis94c/ci-gmail', '%curl'); |
21 | 21 | get_instance()->load->splint('francis94c/ci-gmail', '%base64'); |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * [getClientId Get Client ID.] |
51 | 51 | * @return null|string Client ID. |
52 | 52 | */ |
53 | - public function getClientId():?string { |
|
53 | + public function getClientId(): ?string { |
|
54 | 54 | return $this->clientId; |
55 | 55 | } |
56 | 56 | /** |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | * @param bool $prompt Add the prompt=consent query to the URL. |
64 | 64 | * @return string Authorize URL |
65 | 65 | */ |
66 | - public function getAuthorizeUrl(string $scope, string $redirectUri=null, string $responseType='code', string $accessType='offline', bool $prompt=false):string |
|
66 | + public function getAuthorizeUrl(string $scope, string $redirectUri = null, string $responseType = 'code', string $accessType = 'offline', bool $prompt = false):string |
|
67 | 67 | { |
68 | 68 | $redirectUri = $redirectUri ?? $this->redirectUri; |
69 | 69 | if ($scope == null) throw new Exception("GMail scope cannot be null"); |
@@ -75,14 +75,14 @@ discard block |
||
75 | 75 | 'access_type' => $accessType |
76 | 76 | ]; |
77 | 77 | if ($prompt) $params['prompt'] = 'consent'; |
78 | - return self::AUTH_URL . build_url_query($params, false); |
|
78 | + return self::AUTH_URL.build_url_query($params, false); |
|
79 | 79 | } |
80 | 80 | /** |
81 | 81 | * [getToken description] |
82 | 82 | * @param string $code [description] |
83 | 83 | * @return [type] [description] |
84 | 84 | */ |
85 | - public function getToken(string $code, string $redirectUri=null):?array |
|
85 | + public function getToken(string $code, string $redirectUri = null): ?array |
|
86 | 86 | { |
87 | 87 | $redirectUri = $redirectUri ?? $this->redirectUri; |
88 | 88 | $ch = curl_init(self::TOKEN_URL); |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | ]); |
101 | 101 | $header = [ |
102 | 102 | 'Content-Type: application/x-www-form-urlencoded', |
103 | - 'Content-Length: ' . strlen($body) |
|
103 | + 'Content-Length: '.strlen($body) |
|
104 | 104 | ]; |
105 | 105 | curl_setopt($ch, CURLOPT_HTTPHEADER, $header); |
106 | 106 | curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent); |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | * @param string $refreshToken [description] |
119 | 119 | * @return [type] [description] |
120 | 120 | */ |
121 | - public function refreshAccessToken(string $refreshToken):?array { |
|
121 | + public function refreshAccessToken(string $refreshToken): ?array { |
|
122 | 122 | $ch = curl_init(self::TOKEN_URL); |
123 | 123 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
124 | 124 | curl_setopt($ch, CURLINFO_HEADER_OUT, true); |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | ]); |
134 | 134 | $header = [ |
135 | 135 | 'Content-Type: application/x-www-form-urlencoded', |
136 | - 'Content-Length: ' . strlen($body) |
|
136 | + 'Content-Length: '.strlen($body) |
|
137 | 137 | ]; |
138 | 138 | curl_setopt($ch, CURLOPT_HTTPHEADER, $header); |
139 | 139 | curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent); |
@@ -153,9 +153,9 @@ discard block |
||
153 | 153 | * @param string $user [description] |
154 | 154 | * @return [type] [description] |
155 | 155 | */ |
156 | - public function getProfile(string $user='me'):?array { |
|
156 | + public function getProfile(string $user = 'me'): ?array { |
|
157 | 157 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( |
158 | - self::API . "$user/profile", |
|
158 | + self::API."$user/profile", |
|
159 | 159 | ["Authorization: Bearer $this->token"] |
160 | 160 | ); |
161 | 161 | if ($response !== false) return $this->process_response($code, $response); |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | * @param string $labelFilterAction [description] |
175 | 175 | * @return [type] [description] |
176 | 176 | */ |
177 | - public function watch(string $topic, $labelIds=null, string $userId='me', string $labelFilterAction='include'):?array { |
|
177 | + public function watch(string $topic, $labelIds = null, string $userId = 'me', string $labelFilterAction = 'include'): ?array { |
|
178 | 178 | $body = [ |
179 | 179 | 'topicName' => $topic, |
180 | 180 | 'labelFilterAction' => $labelFilterAction |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | } |
190 | 190 | |
191 | 191 | list($code, $response) = (new GMailCURL(GMailCURL::POST))( |
192 | - self::API . "$userId/watch", |
|
192 | + self::API."$userId/watch", |
|
193 | 193 | ["Authorization: Bearer $this->token"], |
194 | 194 | $body |
195 | 195 | ); |
@@ -203,10 +203,10 @@ discard block |
||
203 | 203 | * @param string $userId ID or Email Address of the user. |
204 | 204 | * @return bool [description] |
205 | 205 | */ |
206 | - public function endWatch(string $userId='me'):bool |
|
206 | + public function endWatch(string $userId = 'me'):bool |
|
207 | 207 | { |
208 | 208 | list($code, $response) = (new GMailCURL(GMailCURL::POST))( |
209 | - self::API . "$userId/stop", |
|
209 | + self::API."$userId/stop", |
|
210 | 210 | ["Authorization: Bearer $this->token"] |
211 | 211 | ); |
212 | 212 | if ($response !== false) return $code == 204; |
@@ -219,10 +219,10 @@ discard block |
||
219 | 219 | * @param string $userID [description] |
220 | 220 | * @return null|array [description] |
221 | 221 | */ |
222 | - public function getLabels(string $userId='me'):?array |
|
222 | + public function getLabels(string $userId = 'me'): ?array |
|
223 | 223 | { |
224 | 224 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( |
225 | - self::API . "$userId/labels", |
|
225 | + self::API."$userId/labels", |
|
226 | 226 | ["Authorization: Bearer $this->token"] |
227 | 227 | ); |
228 | 228 | if ($response !== false) { |
@@ -242,9 +242,9 @@ discard block |
||
242 | 242 | * @param [type] $truncateAfter [description] |
243 | 243 | * @return [type] [description] |
244 | 244 | */ |
245 | - public function getMessages(string $userId='me', array $labelIds=null, |
|
246 | - string $q=null, int $maxMessages=null, string $pageToken=null, bool $includeSpamTrash=false, |
|
247 | - $truncateAfter=null):?object |
|
245 | + public function getMessages(string $userId = 'me', array $labelIds = null, |
|
246 | + string $q = null, int $maxMessages = null, string $pageToken = null, bool $includeSpamTrash = false, |
|
247 | + $truncateAfter = null): ?object |
|
248 | 248 | { |
249 | 249 | $query = []; |
250 | 250 | |
@@ -255,14 +255,14 @@ discard block |
||
255 | 255 | if ($maxMessages != null) $query['maxResults'] = $maxMessages; |
256 | 256 | |
257 | 257 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( |
258 | - self::API . "$userId/messages" . build_url_query($query), |
|
258 | + self::API."$userId/messages".build_url_query($query), |
|
259 | 259 | ["Authorization: Bearer $this->token"] |
260 | 260 | ); |
261 | 261 | |
262 | 262 | if ($response !== false) { |
263 | 263 | if ($truncateAfter != null && $code == 200) { |
264 | 264 | $response = json_decode($response); |
265 | - $response->messages = array_filter($response->messages, function ($e) use ($truncateAfter) { |
|
265 | + $response->messages = array_filter($response->messages, function($e) use ($truncateAfter) { |
|
266 | 266 | return strcmp($truncateAfter, $e->id) < 0; |
267 | 267 | }); |
268 | 268 | $response->{self::HTTP_CODE} = $code; |
@@ -283,8 +283,8 @@ discard block |
||
283 | 283 | * @param [type] $metadataHeaders [description] |
284 | 284 | * @return Message|null [description] |
285 | 285 | */ |
286 | - public function getMessage(string $userId='me', string $messageId, |
|
287 | - string $format='full', array $metadataHeaders=null):?Message |
|
286 | + public function getMessage(string $userId = 'me', string $messageId, |
|
287 | + string $format = 'full', array $metadataHeaders = null): ?Message |
|
288 | 288 | { |
289 | 289 | $query = []; |
290 | 290 | |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | if ($metadataHeaders != null) $query['metadataHeaders'] = $metadataHeaders; |
293 | 293 | |
294 | 294 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( |
295 | - self::API . "$userId/messages/$messageId?" . http_build_query($query), |
|
295 | + self::API."$userId/messages/$messageId?".http_build_query($query), |
|
296 | 296 | ["Authorization: Bearer $this->token"] |
297 | 297 | ); |
298 | 298 |