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

Commit

Permalink
feat(endpoint): added new handler fot endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
DIOHz0r authored and ajsb85 committed Oct 25, 2017
1 parent 8724c9b commit 8789b0d
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions src/GlpiProject/API/Rest/EndPointHandler.php
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())];
}


}

0 comments on commit 8789b0d

Please sign in to comment.