Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 7f3d7af

Browse files
DIOHz0rajsb85
authored andcommitted
fix(client): updated Client class code
1 parent 90ac326 commit 7f3d7af

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/Glpi/Api/Rest/Client.php

+17-6
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ class Client {
149149
/** @var string Session token obtained after initSession() */
150150
private $sessionToken = null;
151151

152+
/**
153+
* @deprecated this could be moved to ItemHandler
154+
*/
152155
private $simpleEndpoints = [
153156
'Alert',
154157
'APIClient',
@@ -303,16 +306,25 @@ public function initSessionByUserToken($userToken) {
303306
*/
304307
public function killSession() {
305308
$response = $this->request('get', 'killSession');
306-
if (!$response->getStatusCode() != 200) {
309+
if ($response->getStatusCode() != 200) {
307310
throw new Exception('session_token seems invalid');
308311
}
309312
return true;
310313
}
311314

315+
/**
316+
* @deprecated this could be moved to ItemHandler
317+
*/
312318
public function getSimpleEndpoints() {
313319
return $this->simpleEndpoints;
314320
}
315321

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+
*/
316328
public function __call($name, $arguments) {
317329
$name = ucfirst($name);
318330
if (!in_array($name, $this->simpleEndpoints)) {
@@ -343,17 +355,15 @@ public function __call($name, $arguments) {
343355
public function request($method, $uri, array $options = []) {
344356
$apiToken = $this->addTokens();
345357
try {
346-
if (!empty($uri)) {
347-
$options['headers']['Content-Type'] = "application/json";
348-
}
358+
$options['headers']['Content-Type'] = "application/json";
349359
if ($apiToken) {
350360
$sessionHeaders = ['Session-Token' => $apiToken['Session-Token']];
351361
if (key_exists('App-Token', $apiToken)) {
352362
$sessionHeaders['App-Token'] = $apiToken['App-Token'];
353363
}
354364
$options = array_merge_recursive($options, ['headers' => $sessionHeaders]);
355365
}
356-
$response = $this->httpClient->request($method, $this->url.$uri, $options);
366+
$response = $this->httpClient->request($method, $this->url . $uri, $options);
357367
return $response;
358368
} catch (ClientException $e) {
359369
$response = $e->getResponse();
@@ -382,7 +392,7 @@ public function getFullSession() {
382392
* @return array
383393
*/
384394
public function getGlpiConfig() {
385-
$response = $this->request('get', 'getFullSession');
395+
$response = $this->request('get', 'getGlpiConfig');
386396
return ['statusCode' => $response->getStatusCode(), 'body' => $response->getBody()->getContents()];
387397
}
388398

@@ -396,6 +406,7 @@ public function getGlpiConfig() {
396406
* @throws Exception
397407
*
398408
* @return \Psr\Http\Message\ResponseInterface the response sent by the server
409+
* @deprecated this will be removed, use the @method request() instead
399410
*/
400411
protected function doHttpRequest($verb = "get", $relative_uri = "", $params = []) {
401412
if (!empty($relative_uri)) {

0 commit comments

Comments
 (0)