This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(endpoint): added new handler fot endpoints
- Loading branch information
Showing
1 changed file
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
|
||
namespace GlpiProject\API\Rest; | ||
|
||
|
||
|
||
use GlpiProject\API\Rest\Exception\InsufficientArgumentsException; | ||
|
||
class EndPointHandler | ||
{ | ||
|
||
/** | ||
* @var Client | ||
*/ | ||
protected $client; | ||
|
||
public function __construct(Client $client) { | ||
$this->client = $client; | ||
} | ||
|
||
/** | ||
* Return all the profiles associated to logged user. | ||
* @return array | ||
*/ | ||
public function getMyProfiles() { | ||
$response = $this->client->request('get', 'getMyProfiles'); | ||
return ['statusCode' => $response->getStatusCode(), 'body' => json_decode($response->getBody()->getContents())]; | ||
} | ||
|
||
/** | ||
* Return the current active profile. | ||
* @return array | ||
*/ | ||
public function getActiveProfile() { | ||
$response = $this->client->request('get', 'getActiveProfile'); | ||
return ['statusCode' => $response->getStatusCode(), 'body' => json_decode($response->getBody()->getContents())]; | ||
} | ||
|
||
/** | ||
* Change active profile to the profiles_id one. | ||
* @see getMyProfiles endpoint for possible profiles. | ||
* | ||
* @param $profiles_id | ||
* @return array | ||
*/ | ||
public function changeActiveProfile($profiles_id) { | ||
$options['body'] = json_encode(['profiles_id' => $profiles_id]); | ||
$response = $this->client->request('post', 'changeActiveProfile', $options); | ||
return ['statusCode' => $response->getStatusCode(), 'body' => json_decode($response->getBody()->getContents())]; | ||
} | ||
|
||
/** | ||
* Return all the possible entities of the current logged user (and for current active profile). | ||
* @param array $options | ||
* @return array | ||
*/ | ||
public function getMyEntities(array $options = array()) { | ||
$response = $this->client->request('get', 'getMyEntities', $options); | ||
return ['statusCode' => $response->getStatusCode(), 'body' => json_decode($response->getBody()->getContents())]; | ||
} | ||
|
||
/** | ||
* Return active entities of current logged user. | ||
* @return array | ||
*/ | ||
public function getActiveEntities() { | ||
$response = $this->client->request('get', 'getActiveEntities'); | ||
return ['statusCode' => $response->getStatusCode(), 'body' => json_decode($response->getBody()->getContents())]; | ||
} | ||
|
||
/** | ||
* Change active entity to the entities_id one. | ||
* @see getMyEntities endpoint for possible entities. | ||
* | ||
* @param array $options | ||
* @return array | ||
*/ | ||
public function changeActiveEntities(array $options = array()) { | ||
$response = $this->client->request('post', 'changeActiveEntities', $options); | ||
return ['statusCode' => $response->getStatusCode(), 'body' => json_decode($response->getBody()->getContents())]; | ||
} | ||
|
||
|
||
} |