@@ -10,12 +10,12 @@ discard block |
||
10 | 10 | private $method; |
11 | 11 | private $userAgent; |
12 | 12 | |
13 | - function __construct(string $method, string $userAgent='CodeIgniter GMail API') { |
|
13 | + function __construct(string $method, string $userAgent = 'CodeIgniter GMail API') { |
|
14 | 14 | $this->method = $method; |
15 | 15 | $this->userAgent = $userAgent; |
16 | 16 | } |
17 | 17 | |
18 | - function __invoke(string $url, array $header=[], array $body=null):array { |
|
18 | + function __invoke(string $url, array $header = [], array $body = null):array { |
|
19 | 19 | if ($body != null) $body = json_encode($body); |
20 | 20 | |
21 | 21 | $ch = curl_init($url); |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | } |
29 | 29 | // Header. |
30 | 30 | $header[] = 'Content-Type: application/json'; |
31 | - if ($body != null) { |
|
31 | + if ($body != null) { |
|
32 | 32 | $header[] = 'Content-Length: '.strlen($body); |
33 | 33 | } else { |
34 | 34 | $header[] = 'Content-Length: 0'; |
@@ -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 |
@@ -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 | $redirectUri = $redirectUri ?? $this->redirectUri; |
61 | 61 | if ($scope == null) throw new Exception("GMail scope cannot be null"); |
62 | 62 | $params = [ |
@@ -67,14 +67,14 @@ discard block |
||
67 | 67 | 'access_type' => $accessType |
68 | 68 | ]; |
69 | 69 | if ($prompt) $params['prompt'] = 'consent'; |
70 | - return self::AUTH_URL . build_url_query($params, false); |
|
70 | + return self::AUTH_URL.build_url_query($params, false); |
|
71 | 71 | } |
72 | 72 | /** |
73 | 73 | * [getToken description] |
74 | 74 | * @param string $code [description] |
75 | 75 | * @return [type] [description] |
76 | 76 | */ |
77 | - public function getToken(string $code, string $redirectUri=null):?array { |
|
77 | + public function getToken(string $code, string $redirectUri = null): ?array { |
|
78 | 78 | $redirectUri = $redirectUri ?? $this->redirectUri; |
79 | 79 | $ch = curl_init(self::TOKEN_URL); |
80 | 80 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | ]); |
92 | 92 | $header = [ |
93 | 93 | 'Content-Type: application/x-www-form-urlencoded', |
94 | - 'Content-Length: ' . strlen($body) |
|
94 | + 'Content-Length: '.strlen($body) |
|
95 | 95 | ]; |
96 | 96 | curl_setopt($ch, CURLOPT_HTTPHEADER, $header); |
97 | 97 | curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent); |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * @param string $refreshToken [description] |
110 | 110 | * @return [type] [description] |
111 | 111 | */ |
112 | - public function refreshAccessToken(string $refreshToken):?array { |
|
112 | + public function refreshAccessToken(string $refreshToken): ?array { |
|
113 | 113 | $ch = curl_init(self::TOKEN_URL); |
114 | 114 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
115 | 115 | curl_setopt($ch, CURLINFO_HEADER_OUT, true); |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | ]); |
125 | 125 | $header = [ |
126 | 126 | 'Content-Type: application/x-www-form-urlencoded', |
127 | - 'Content-Length: ' . strlen($body) |
|
127 | + 'Content-Length: '.strlen($body) |
|
128 | 128 | ]; |
129 | 129 | curl_setopt($ch, CURLOPT_HTTPHEADER, $header); |
130 | 130 | curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent); |
@@ -144,9 +144,9 @@ discard block |
||
144 | 144 | * @param string $user [description] |
145 | 145 | * @return [type] [description] |
146 | 146 | */ |
147 | - public function getProfile(string $user='me'):?array { |
|
147 | + public function getProfile(string $user = 'me'): ?array { |
|
148 | 148 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( |
149 | - self::API . "$user/profile", |
|
149 | + self::API."$user/profile", |
|
150 | 150 | ["Authorization: Bearer $this->token"] |
151 | 151 | ); |
152 | 152 | if ($response !== false) return $this->process_response($code, $response); |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | * @param string $labelFilterAction [description] |
165 | 165 | * @return [type] [description] |
166 | 166 | */ |
167 | - public function watch(string $topic, $labelIds=null, string $userId='me', string $labelFilterAction='include'):?array { |
|
167 | + public function watch(string $topic, $labelIds = null, string $userId = 'me', string $labelFilterAction = 'include'): ?array { |
|
168 | 168 | $body = [ |
169 | 169 | 'topicName' => $topic, |
170 | 170 | 'labelFilterAction' => $labelFilterAction |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | } |
180 | 180 | |
181 | 181 | list($code, $response) = (new GMailCURL(GMailCURL::POST))( |
182 | - self::API . "$userId/watch", |
|
182 | + self::API."$userId/watch", |
|
183 | 183 | ["Authorization: Bearer $this->token"], |
184 | 184 | $body |
185 | 185 | ); |
@@ -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 | /** |
@@ -58,7 +60,9 @@ discard block |
||
58 | 60 | */ |
59 | 61 | public function getAuthorizeUrl(string $scope, string $redirectUri=null, string $responseType='code', string $accessType='offline', bool $prompt=false):string { |
60 | 62 | $redirectUri = $redirectUri ?? $this->redirectUri; |
61 | - if ($scope == null) throw new Exception("GMail scope cannot be null"); |
|
63 | + if ($scope == null) { |
|
64 | + throw new Exception("GMail scope cannot be null"); |
|
65 | + } |
|
62 | 66 | $params = [ |
63 | 67 | 'client_id' => $this->clientId, |
64 | 68 | 'redirect_uri' => $redirectUri, |
@@ -66,7 +70,9 @@ discard block |
||
66 | 70 | 'response_type' => $responseType, |
67 | 71 | 'access_type' => $accessType |
68 | 72 | ]; |
69 | - if ($prompt) $params['prompt'] = 'consent'; |
|
73 | + if ($prompt) { |
|
74 | + $params['prompt'] = 'consent'; |
|
75 | + } |
|
70 | 76 | return self::AUTH_URL . build_url_query($params, false); |
71 | 77 | } |
72 | 78 | /** |
@@ -101,7 +107,9 @@ discard block |
||
101 | 107 | $response = curl_exec($ch); |
102 | 108 | $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
103 | 109 | curl_close($ch); |
104 | - if ($response !== false) return $this->process_response($code, $response); |
|
110 | + if ($response !== false) { |
|
111 | + return $this->process_response($code, $response); |
|
112 | + } |
|
105 | 113 | return null; |
106 | 114 | } |
107 | 115 | /** |
@@ -135,7 +143,9 @@ discard block |
||
135 | 143 | $response = curl_exec($ch); |
136 | 144 | $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
137 | 145 | curl_close($ch); |
138 | - if ($response !== false) return $this->process_response($code, $response); |
|
146 | + if ($response !== false) { |
|
147 | + return $this->process_response($code, $response); |
|
148 | + } |
|
139 | 149 | return null; |
140 | 150 | } |
141 | 151 | /** |
@@ -149,7 +159,9 @@ discard block |
||
149 | 159 | self::API . "$user/profile", |
150 | 160 | ["Authorization: Bearer $this->token"] |
151 | 161 | ); |
152 | - if ($response !== false) return $this->process_response($code, $response); |
|
162 | + if ($response !== false) { |
|
163 | + return $this->process_response($code, $response); |
|
164 | + } |
|
153 | 165 | return null; |
154 | 166 | } |
155 | 167 | /** |
@@ -183,7 +195,9 @@ discard block |
||
183 | 195 | ["Authorization: Bearer $this->token"], |
184 | 196 | $body |
185 | 197 | ); |
186 | - if ($response !== false) return $this->process_response($code, $response); |
|
198 | + if ($response !== false) { |
|
199 | + return $this->process_response($code, $response); |
|
200 | + } |
|
187 | 201 | return null; |
188 | 202 | } |
189 | 203 | /** |