@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | private $token; |
18 | 18 | private $userAgent = 'CodeIgniter GMail API'; |
19 | 19 | |
20 | - function __construct($params=null) { |
|
20 | + function __construct($params = null) { |
|
21 | 21 | get_instance()->load->splint('francis94c/ci-gmail', '%curl'); |
22 | 22 | if ($params != null) $this->init($params); |
23 | 23 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * [getClientId Get Client ID.] |
44 | 44 | * @return null|string Client ID. |
45 | 45 | */ |
46 | - public function getClientId():?string { |
|
46 | + public function getClientId(): ?string { |
|
47 | 47 | return $this->clientId; |
48 | 48 | } |
49 | 49 | /** |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | * @param bool $prompt Add the prompt=consent query to the URL. |
57 | 57 | * @return string Authorize URL |
58 | 58 | */ |
59 | - public function getAuthorizeUrl(string $scope, string $redirectUri=null, string $responseType='code', string $accessType='offline', bool $prompt=false):string |
|
59 | + public function getAuthorizeUrl(string $scope, string $redirectUri = null, string $responseType = 'code', string $accessType = 'offline', bool $prompt = false):string |
|
60 | 60 | { |
61 | 61 | $redirectUri = $redirectUri ?? $this->redirectUri; |
62 | 62 | if ($scope == null) throw new Exception("GMail scope cannot be null"); |
@@ -68,14 +68,14 @@ discard block |
||
68 | 68 | 'access_type' => $accessType |
69 | 69 | ]; |
70 | 70 | if ($prompt) $params['prompt'] = 'consent'; |
71 | - return self::AUTH_URL . build_url_query($params, false); |
|
71 | + return self::AUTH_URL.build_url_query($params, false); |
|
72 | 72 | } |
73 | 73 | /** |
74 | 74 | * [getToken description] |
75 | 75 | * @param string $code [description] |
76 | 76 | * @return [type] [description] |
77 | 77 | */ |
78 | - public function getToken(string $code, string $redirectUri=null):?array |
|
78 | + public function getToken(string $code, string $redirectUri = null): ?array |
|
79 | 79 | { |
80 | 80 | $redirectUri = $redirectUri ?? $this->redirectUri; |
81 | 81 | $ch = curl_init(self::TOKEN_URL); |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | ]); |
94 | 94 | $header = [ |
95 | 95 | 'Content-Type: application/x-www-form-urlencoded', |
96 | - 'Content-Length: ' . strlen($body) |
|
96 | + 'Content-Length: '.strlen($body) |
|
97 | 97 | ]; |
98 | 98 | curl_setopt($ch, CURLOPT_HTTPHEADER, $header); |
99 | 99 | curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent); |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * @param string $refreshToken [description] |
112 | 112 | * @return [type] [description] |
113 | 113 | */ |
114 | - public function refreshAccessToken(string $refreshToken):?array { |
|
114 | + public function refreshAccessToken(string $refreshToken): ?array { |
|
115 | 115 | $ch = curl_init(self::TOKEN_URL); |
116 | 116 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
117 | 117 | curl_setopt($ch, CURLINFO_HEADER_OUT, true); |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | ]); |
127 | 127 | $header = [ |
128 | 128 | 'Content-Type: application/x-www-form-urlencoded', |
129 | - 'Content-Length: ' . strlen($body) |
|
129 | + 'Content-Length: '.strlen($body) |
|
130 | 130 | ]; |
131 | 131 | curl_setopt($ch, CURLOPT_HTTPHEADER, $header); |
132 | 132 | curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent); |
@@ -146,9 +146,9 @@ discard block |
||
146 | 146 | * @param string $user [description] |
147 | 147 | * @return [type] [description] |
148 | 148 | */ |
149 | - public function getProfile(string $user='me'):?array { |
|
149 | + public function getProfile(string $user = 'me'): ?array { |
|
150 | 150 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( |
151 | - self::API . "$user/profile", |
|
151 | + self::API."$user/profile", |
|
152 | 152 | ["Authorization: Bearer $this->token"] |
153 | 153 | ); |
154 | 154 | if ($response !== false) return $this->process_response($code, $response); |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | * @param string $labelFilterAction [description] |
167 | 167 | * @return [type] [description] |
168 | 168 | */ |
169 | - public function watch(string $topic, $labelIds=null, string $userId='me', string $labelFilterAction='include'):?array { |
|
169 | + public function watch(string $topic, $labelIds = null, string $userId = 'me', string $labelFilterAction = 'include'): ?array { |
|
170 | 170 | $body = [ |
171 | 171 | 'topicName' => $topic, |
172 | 172 | 'labelFilterAction' => $labelFilterAction |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | } |
182 | 182 | |
183 | 183 | list($code, $response) = (new GMailCURL(GMailCURL::POST))( |
184 | - self::API . "$userId/watch", |
|
184 | + self::API."$userId/watch", |
|
185 | 185 | ["Authorization: Bearer $this->token"], |
186 | 186 | $body |
187 | 187 | ); |
@@ -194,10 +194,10 @@ discard block |
||
194 | 194 | * @param string $userId ID or Email Address of the user. |
195 | 195 | * @return bool [description] |
196 | 196 | */ |
197 | - public function endWatch(string $userId='me'):bool |
|
197 | + public function endWatch(string $userId = 'me'):bool |
|
198 | 198 | { |
199 | 199 | list($code, $response) = (new GMailCURL(GMailCURL::POST))( |
200 | - self::API . "$userId/stop", |
|
200 | + self::API."$userId/stop", |
|
201 | 201 | ["Authorization: Bearer $this->token"] |
202 | 202 | ); |
203 | 203 | if ($response !== false) return $code == 204; |
@@ -209,10 +209,10 @@ discard block |
||
209 | 209 | * @param string $userID [description] |
210 | 210 | * @return null|array [description] |
211 | 211 | */ |
212 | - public function getLabels(string $userId='me'):?array |
|
212 | + public function getLabels(string $userId = 'me'): ?array |
|
213 | 213 | { |
214 | 214 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( |
215 | - self::API . "$userId/labels", |
|
215 | + self::API."$userId/labels", |
|
216 | 216 | ["Authorization: Bearer $this->token"] |
217 | 217 | ); |
218 | 218 | if ($response !== false) { |
@@ -232,9 +232,9 @@ discard block |
||
232 | 232 | * @param [type] $truncateAfter [description] |
233 | 233 | * @return [type] [description] |
234 | 234 | */ |
235 | - public function getEmails(string $userId='me', array $labelIds=null, |
|
236 | - string $q=null, int $maxEmails=null, string $pageToken=null, bool $includeSpamTrash=false, |
|
237 | - $truncateAfter=null):?object |
|
235 | + public function getEmails(string $userId = 'me', array $labelIds = null, |
|
236 | + string $q = null, int $maxEmails = null, string $pageToken = null, bool $includeSpamTrash = false, |
|
237 | + $truncateAfter = null): ?object |
|
238 | 238 | { |
239 | 239 | $query = []; |
240 | 240 | |
@@ -245,14 +245,14 @@ discard block |
||
245 | 245 | if ($maxEmails != null) $query['maxResults'] = $maxEmails; |
246 | 246 | |
247 | 247 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( |
248 | - self::API . "$userId/messages?" . http_build_query($query), |
|
248 | + self::API."$userId/messages?".http_build_query($query), |
|
249 | 249 | ["Authorization: Bearer $this->token"] |
250 | 250 | ); |
251 | 251 | |
252 | 252 | if ($response !== false) { |
253 | 253 | if ($truncateAfter != null && $code == 200) { |
254 | 254 | $response = json_decode($response); |
255 | - $response->messages = array_filter($response->messages, function ($e) use ($truncateAfter) { |
|
255 | + $response->messages = array_filter($response->messages, function($e) use ($truncateAfter) { |
|
256 | 256 | return strcmp($truncateAfter, $e->id) <= 0; |
257 | 257 | }); |
258 | 258 | $response->{self::HTTP_CODE} = $code; |
@@ -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), |