@@ -149,6 +149,9 @@ class Client {
149
149
/** @var string Session token obtained after initSession() */
150
150
private $ sessionToken = null ;
151
151
152
+ /**
153
+ * @deprecated this could be moved to ItemHandler
154
+ */
152
155
private $ simpleEndpoints = [
153
156
'Alert ' ,
154
157
'APIClient ' ,
@@ -303,16 +306,25 @@ public function initSessionByUserToken($userToken) {
303
306
*/
304
307
public function killSession () {
305
308
$ response = $ this ->request ('get ' , 'killSession ' );
306
- if (! $ response ->getStatusCode () != 200 ) {
309
+ if ($ response ->getStatusCode () != 200 ) {
307
310
throw new Exception ('session_token seems invalid ' );
308
311
}
309
312
return true ;
310
313
}
311
314
315
+ /**
316
+ * @deprecated this could be moved to ItemHandler
317
+ */
312
318
public function getSimpleEndpoints () {
313
319
return $ this ->simpleEndpoints ;
314
320
}
315
321
322
+ /**
323
+ * @param $name
324
+ * @param $arguments
325
+ * @return \Psr\Http\Message\ResponseInterface
326
+ * @deprecated this will be removed, use the @method request() instead
327
+ */
316
328
public function __call ($ name , $ arguments ) {
317
329
$ name = ucfirst ($ name );
318
330
if (!in_array ($ name , $ this ->simpleEndpoints )) {
@@ -343,17 +355,15 @@ public function __call($name, $arguments) {
343
355
public function request ($ method , $ uri , array $ options = []) {
344
356
$ apiToken = $ this ->addTokens ();
345
357
try {
346
- if (!empty ($ uri )) {
347
- $ options ['headers ' ]['Content-Type ' ] = "application/json " ;
348
- }
358
+ $ options ['headers ' ]['Content-Type ' ] = "application/json " ;
349
359
if ($ apiToken ) {
350
360
$ sessionHeaders = ['Session-Token ' => $ apiToken ['Session-Token ' ]];
351
361
if (key_exists ('App-Token ' , $ apiToken )) {
352
362
$ sessionHeaders ['App-Token ' ] = $ apiToken ['App-Token ' ];
353
363
}
354
364
$ options = array_merge_recursive ($ options , ['headers ' => $ sessionHeaders ]);
355
365
}
356
- $ response = $ this ->httpClient ->request ($ method , $ this ->url . $ uri , $ options );
366
+ $ response = $ this ->httpClient ->request ($ method , $ this ->url . $ uri , $ options );
357
367
return $ response ;
358
368
} catch (ClientException $ e ) {
359
369
$ response = $ e ->getResponse ();
@@ -382,7 +392,7 @@ public function getFullSession() {
382
392
* @return array
383
393
*/
384
394
public function getGlpiConfig () {
385
- $ response = $ this ->request ('get ' , 'getFullSession ' );
395
+ $ response = $ this ->request ('get ' , 'getGlpiConfig ' );
386
396
return ['statusCode ' => $ response ->getStatusCode (), 'body ' => $ response ->getBody ()->getContents ()];
387
397
}
388
398
@@ -396,6 +406,7 @@ public function getGlpiConfig() {
396
406
* @throws Exception
397
407
*
398
408
* @return \Psr\Http\Message\ResponseInterface the response sent by the server
409
+ * @deprecated this will be removed, use the @method request() instead
399
410
*/
400
411
protected function doHttpRequest ($ verb = "get " , $ relative_uri = "" , $ params = []) {
401
412
if (!empty ($ relative_uri )) {
0 commit comments