2626use Throwable ;
2727
2828class GoogleAPIService {
29- /**
30- * @var string
31- */
32- private $ appName ;
3329 /**
3430 * @var LoggerInterface
3531 */
@@ -60,7 +56,6 @@ public function __construct (string $appName,
6056 IConfig $ config ,
6157 INotificationManager $ notificationManager ,
6258 IClientService $ clientService ) {
63- $ this ->appName = $ appName ;
6459 $ this ->logger = $ logger ;
6560 $ this ->l10n = $ l10n ;
6661 $ this ->config = $ config ;
@@ -137,7 +132,7 @@ public function request(string $userId, string $endPoint, array $params = [],
137132 $ this ->logger ->debug (
138133 'REQUESTING Google API, method ' .$ method .', URL: ' . $ url . ' , params: ' . json_encode ($ params )
139134 . 'token length: ' . strlen ($ accessToken ),
140- ['app ' => $ this -> appName ]
135+ ['app ' => Application:: APP_ID ]
141136 );
142137
143138 if ($ method === 'GET ' ) {
@@ -157,14 +152,14 @@ public function request(string $userId, string $endPoint, array $params = [],
157152 if ($ respCode >= 400 ) {
158153 $ this ->logger ->debug (
159154 'Google API request 400 FAILURE, method ' .$ method .', URL: ' . $ url . ' , body: ' . $ body ,
160- ['app ' => $ this -> appName ]
155+ ['app ' => Application:: APP_ID ]
161156 );
162157 return ['error ' => 'Bad credentials ' ];
163158 } else {
164159 $ this ->logger ->debug (
165160 'Google API request SUCCESS: , method ' . $ method . ', URL: ' . $ url
166161 . ' , body: ' . substr ($ body , 0 , 30 ) . '... ' ,
167- ['app ' => $ this -> appName ]
162+ ['app ' => Application:: APP_ID ]
168163 );
169164 return json_decode ($ body , true );
170165 }
@@ -175,15 +170,15 @@ public function request(string $userId, string $endPoint, array $params = [],
175170 'Google API ServerException|ClientException error : ' .$ e ->getMessage ()
176171 . ' status code: ' .$ response ->getStatusCode ()
177172 . ' body: ' . $ body ,
178- ['app ' => $ this -> appName ]
173+ ['app ' => Application:: APP_ID ]
179174 );
180175 return [
181176 'error ' => 'ServerException|ClientException, message: '
182177 . $ e ->getMessage ()
183178 . ' status code: ' . $ response ->getStatusCode (),
184179 ];
185180 } catch (ConnectException $ e ) {
186- $ this ->logger ->warning ('Google API error : ' .$ e ->getMessage (), ['app ' => $ this -> appName ]);
181+ $ this ->logger ->warning ('Google API error : ' .$ e ->getMessage (), ['app ' => Application:: APP_ID ]);
187182 return ['error ' => 'Connection error: ' . $ e ->getMessage ()];
188183 }
189184 }
@@ -231,7 +226,7 @@ public function requestOAuthAccessToken(array $params = [], string $method = 'GE
231226 return json_decode ($ body , true );
232227 }
233228 } catch (Exception $ e ) {
234- $ this ->logger ->warning ('Google OAuth error : ' .$ e ->getMessage (), ['app ' => $ this -> appName ]);
229+ $ this ->logger ->warning ('Google OAuth error : ' .$ e ->getMessage (), ['app ' => Application:: APP_ID ]);
235230 return ['error ' => $ e ->getMessage ()];
236231 }
237232 }
@@ -287,10 +282,10 @@ public function simpleRequest(string $userId, string $url, array $params = [], s
287282 ];
288283 }
289284 } catch (ServerException | ClientException $ e ) {
290- $ this ->logger ->warning ('Google API error : ' .$ e ->getMessage (), ['app ' => $ this -> appName ]);
285+ $ this ->logger ->warning ('Google API error : ' .$ e ->getMessage (), ['app ' => Application:: APP_ID ]);
291286 return ['error ' => $ e ->getMessage ()];
292287 } catch (ConnectException $ e ) {
293- $ this ->logger ->error ('Google API request connection error: ' . $ e ->getMessage (), ['app ' => $ this -> appName ]);
288+ $ this ->logger ->error ('Google API request connection error: ' . $ e ->getMessage (), ['app ' => Application:: APP_ID ]);
294289 return ['error ' => 'Connection error: ' . $ e ->getMessage ()];
295290 }
296291 }
@@ -354,10 +349,10 @@ public function simpleDownload(string $userId, string $url, $resource, array $pa
354349 return ['success ' => true ];
355350 }
356351 } catch (ServerException | ClientException $ e ) {
357- $ this ->logger ->warning ('Google API error : ' .$ e ->getMessage (), ['app ' => $ this -> appName ]);
352+ $ this ->logger ->warning ('Google API error : ' .$ e ->getMessage (), ['app ' => Application:: APP_ID ]);
358353 return ['error ' => $ e ->getMessage ()];
359354 } catch (ConnectException $ e ) {
360- $ this ->logger ->error ('Google API request connection error: ' . $ e ->getMessage (), ['app ' => $ this -> appName ]);
355+ $ this ->logger ->error ('Google API request connection error: ' . $ e ->getMessage (), ['app ' => Application:: APP_ID ]);
361356 return ['error ' => 'Connection error: ' . $ e ->getMessage ()];
362357 } catch (Throwable | Exception $ e ) {
363358 return ['error ' => 'Unknown error: ' . $ e ->getMessage ()];
@@ -378,7 +373,7 @@ private function checkTokenExpiration(string $userId): void {
378373 }
379374
380375 public function refreshToken (string $ userId ): array {
381- $ this ->logger ->debug ('Trying to REFRESH the access token ' , ['app ' => $ this -> appName ]);
376+ $ this ->logger ->debug ('Trying to REFRESH the access token ' , ['app ' => Application:: APP_ID ]);
382377 $ refreshToken = $ this ->config ->getUserValue ($ userId , Application::APP_ID , 'refresh_token ' );
383378 $ clientID = $ this ->config ->getAppValue (Application::APP_ID , 'client_id ' );
384379 $ clientSecret = $ this ->config ->getAppValue (Application::APP_ID , 'client_secret ' );
@@ -390,7 +385,7 @@ public function refreshToken(string $userId): array {
390385 ], 'POST ' );
391386
392387 if (isset ($ result ['access_token ' ])) {
393- $ this ->logger ->debug ('Google access token successfully refreshed ' , ['app ' => $ this -> appName ]);
388+ $ this ->logger ->debug ('Google access token successfully refreshed ' , ['app ' => Application:: APP_ID ]);
394389 $ this ->config ->setUserValue ($ userId , Application::APP_ID , 'token ' , $ result ['access_token ' ]);
395390 if (isset ($ result ['expires_in ' ])) {
396391 $ nowTs = (new Datetime ())->getTimestamp ();
@@ -399,7 +394,7 @@ public function refreshToken(string $userId): array {
399394 }
400395 } else {
401396 $ responseTxt = json_encode ($ result );
402- $ this ->logger ->warning ('Google API error, impossible to refresh the token. Response: ' . $ responseTxt , ['app ' => $ this -> appName ]);
397+ $ this ->logger ->warning ('Google API error, impossible to refresh the token. Response: ' . $ responseTxt , ['app ' => Application:: APP_ID ]);
403398 }
404399
405400 return $ result ;
0 commit comments