26
26
use Throwable ;
27
27
28
28
class GoogleAPIService {
29
- /**
30
- * @var string
31
- */
32
- private $ appName ;
33
29
/**
34
30
* @var LoggerInterface
35
31
*/
@@ -60,7 +56,6 @@ public function __construct (string $appName,
60
56
IConfig $ config ,
61
57
INotificationManager $ notificationManager ,
62
58
IClientService $ clientService ) {
63
- $ this ->appName = $ appName ;
64
59
$ this ->logger = $ logger ;
65
60
$ this ->l10n = $ l10n ;
66
61
$ this ->config = $ config ;
@@ -137,7 +132,7 @@ public function request(string $userId, string $endPoint, array $params = [],
137
132
$ this ->logger ->debug (
138
133
'REQUESTING Google API, method ' .$ method .', URL: ' . $ url . ' , params: ' . json_encode ($ params )
139
134
. 'token length: ' . strlen ($ accessToken ),
140
- ['app ' => $ this -> appName ]
135
+ ['app ' => Application:: APP_ID ]
141
136
);
142
137
143
138
if ($ method === 'GET ' ) {
@@ -157,14 +152,14 @@ public function request(string $userId, string $endPoint, array $params = [],
157
152
if ($ respCode >= 400 ) {
158
153
$ this ->logger ->debug (
159
154
'Google API request 400 FAILURE, method ' .$ method .', URL: ' . $ url . ' , body: ' . $ body ,
160
- ['app ' => $ this -> appName ]
155
+ ['app ' => Application:: APP_ID ]
161
156
);
162
157
return ['error ' => 'Bad credentials ' ];
163
158
} else {
164
159
$ this ->logger ->debug (
165
160
'Google API request SUCCESS: , method ' . $ method . ', URL: ' . $ url
166
161
. ' , body: ' . substr ($ body , 0 , 30 ) . '... ' ,
167
- ['app ' => $ this -> appName ]
162
+ ['app ' => Application:: APP_ID ]
168
163
);
169
164
return json_decode ($ body , true );
170
165
}
@@ -175,15 +170,15 @@ public function request(string $userId, string $endPoint, array $params = [],
175
170
'Google API ServerException|ClientException error : ' .$ e ->getMessage ()
176
171
. ' status code: ' .$ response ->getStatusCode ()
177
172
. ' body: ' . $ body ,
178
- ['app ' => $ this -> appName ]
173
+ ['app ' => Application:: APP_ID ]
179
174
);
180
175
return [
181
176
'error ' => 'ServerException|ClientException, message: '
182
177
. $ e ->getMessage ()
183
178
. ' status code: ' . $ response ->getStatusCode (),
184
179
];
185
180
} 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 ]);
187
182
return ['error ' => 'Connection error: ' . $ e ->getMessage ()];
188
183
}
189
184
}
@@ -231,7 +226,7 @@ public function requestOAuthAccessToken(array $params = [], string $method = 'GE
231
226
return json_decode ($ body , true );
232
227
}
233
228
} 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 ]);
235
230
return ['error ' => $ e ->getMessage ()];
236
231
}
237
232
}
@@ -287,10 +282,10 @@ public function simpleRequest(string $userId, string $url, array $params = [], s
287
282
];
288
283
}
289
284
} 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 ]);
291
286
return ['error ' => $ e ->getMessage ()];
292
287
} 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 ]);
294
289
return ['error ' => 'Connection error: ' . $ e ->getMessage ()];
295
290
}
296
291
}
@@ -354,10 +349,10 @@ public function simpleDownload(string $userId, string $url, $resource, array $pa
354
349
return ['success ' => true ];
355
350
}
356
351
} 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 ]);
358
353
return ['error ' => $ e ->getMessage ()];
359
354
} 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 ]);
361
356
return ['error ' => 'Connection error: ' . $ e ->getMessage ()];
362
357
} catch (Throwable | Exception $ e ) {
363
358
return ['error ' => 'Unknown error: ' . $ e ->getMessage ()];
@@ -378,7 +373,7 @@ private function checkTokenExpiration(string $userId): void {
378
373
}
379
374
380
375
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 ]);
382
377
$ refreshToken = $ this ->config ->getUserValue ($ userId , Application::APP_ID , 'refresh_token ' );
383
378
$ clientID = $ this ->config ->getAppValue (Application::APP_ID , 'client_id ' );
384
379
$ clientSecret = $ this ->config ->getAppValue (Application::APP_ID , 'client_secret ' );
@@ -390,7 +385,7 @@ public function refreshToken(string $userId): array {
390
385
], 'POST ' );
391
386
392
387
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 ]);
394
389
$ this ->config ->setUserValue ($ userId , Application::APP_ID , 'token ' , $ result ['access_token ' ]);
395
390
if (isset ($ result ['expires_in ' ])) {
396
391
$ nowTs = (new Datetime ())->getTimestamp ();
@@ -399,7 +394,7 @@ public function refreshToken(string $userId): array {
399
394
}
400
395
} else {
401
396
$ 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 ]);
403
398
}
404
399
405
400
return $ result ;
0 commit comments