Skip to content

Commit

Permalink
fix(items): fixed ItemHandler functions
Browse files Browse the repository at this point in the history
  • Loading branch information
DIOHz0r authored and ajsb85 committed Oct 25, 2017
1 parent b019d92 commit 2c258d8
Showing 1 changed file with 55 additions and 20 deletions.
75 changes: 55 additions & 20 deletions src/GlpiProject/API/Rest/ItemHandler.php
Expand Up @@ -31,8 +31,7 @@
namespace GlpiProject\API\Rest;


class ItemHandler
{
class ItemHandler {
/**
* @var Client
*/
Expand All @@ -50,41 +49,57 @@ public function __construct(Client $client) {
* @return array
*/
public function getAnItem($itemType, $id, array $queryString = []) {
$response = $this->client->request('get', $itemType . '/' . $id, $queryString);
$options = [];
if ($queryString) {
$options['query'] = $queryString;
}
$response = $this->client->request('get', $itemType . '/' . $id, $options);
return [
'statusCode' => $response->getStatusCode(),
'body' => $response->getBody()->getContents(),
];
}

/**
* Return a collection of rows of the itemtype.
* Return a collection of rows of the itemtype.
* @param $itemType
* @param array $queryString
* @return array
*/
public function getAllItems($itemType, array $queryString = []) {
$response = $this->client->request('get', $itemType . '/', $queryString);
$options = [];
if ($queryString) {
$options['query'] = $queryString;
}
$response = $this->client->request('get', $itemType . '/', $options);
return [
'statusCode' => $response->getStatusCode(),
'body' => $response->getBody()->getContents(),
'contentRange' => $response->getHeader('Content-Range')[0],
'acceptRange' => $response->getHeader('Accept-Range')[0],
];
}

/**
* Return a collection of rows of the itemtype.
* Return a collection of rows of the itemtype.
* @param $itemType
* @param $id
* @param $subItem
* @param array $queryString
* @return array
*/
public function getSubItems($itemType, $id, $subItem, array $queryString = []) {
$options = [];
if ($queryString) {
$options['query'] = $queryString;
}
$response = $this->client->request('get', $itemType . '/' . $id . '/' . $subItem,
$queryString);
$options);
return [
'statusCode' => $response->getStatusCode(),
'body' => $response->getBody()->getContents(),
'contentRange' => $response->getHeader('Content-Range')[0],
'acceptRange' => $response->getHeader('Accept-Range')[0],
];
}

Expand All @@ -93,11 +108,12 @@ public function getSubItems($itemType, $id, $subItem, array $queryString = []) {
* @param array $queryString
* @return array
*/
public function getMultipleItems(array $queryString = []) {
$response = $this->client->request('get', 'getMultipleItems', $queryString);
public function getMultipleItems(array $queryString){
$options['query'] = $queryString;
$response = $this->client->request('get', 'getMultipleItems', $options);
return [
'statusCode' => $response->getStatusCode(),
'body' => $response->getBody()->getContents(),
'body' => $response->getBody()->getContents()
];
}

Expand All @@ -108,7 +124,11 @@ public function getMultipleItems(array $queryString = []) {
* @return array
*/
public function listSearchOptions($itemType, array $queryString = []) {
$response = $this->client->request('get', 'listSearchOptions/' . $itemType, $queryString);
$options = [];
if ($queryString) {
$options['query'] = $queryString;
}
$response = $this->client->request('get', 'listSearchOptions/' . $itemType, $options);
return [
'statusCode' => $response->getStatusCode(),
'body' => $response->getBody()->getContents(),
Expand All @@ -122,7 +142,11 @@ public function listSearchOptions($itemType, array $queryString = []) {
* @return array
*/
public function searchItems($itemType, array $queryString = []) {
$response = $this->client->request('get', 'search/' . $itemType, $queryString);
$options = [];
if ($queryString) {
$options['query'] = $queryString;
}
$response = $this->client->request('get', 'search/' . $itemType, $options);
return [
'statusCode' => $response->getStatusCode(),
'body' => $response->getBody()->getContents(),
Expand All @@ -140,12 +164,14 @@ public function searchItems($itemType, array $queryString = []) {
* @param array $queryString
* @return array
*/
public function addItem($itemType, array $queryString = []) {
$queryString['input'] = $queryString;
$response = $this->client->request('post', $itemType . '/', $queryString);
public function addItem($itemType, array $queryString) {
$options['body'] = json_encode(['input' => $queryString]);
$response = $this->client->request('post', $itemType . '/', $options);
return [
'statusCode' => $response->getStatusCode(),
'body' => $response->getBody()->getContents(),
'location' => $response->getHeader('location')[0],
'link' => $response->getHeader('Link')[0],
];
}

Expand All @@ -156,18 +182,27 @@ public function addItem($itemType, array $queryString = []) {
* @param array $queryString
* @return array
*/
public function updateItem($itemType, $id, array $queryString = []) {
$queryString['input'] = $queryString;
$response = $this->client->request('put', $itemType . '/' . $id, $queryString);
public function updateItem($itemType, $id, array $queryString) {
$options['body'] = json_encode(['input' => $queryString]);
$response = $this->client->request('put', $itemType . '/' . $id, $options);
return [
'statusCode' => $response->getStatusCode(),
'body' => $response->getBody()->getContents(),
];
}

/**
* @param $itemType
* @param $id
* @param array $queryString
* @return array
*/
public function deleteItem($itemType, $id, array $queryString = []) {
$queryString['input'] = $queryString;
$response = $this->client->request('delete', $itemType . '/' . $id, $queryString);
$options = [];
if($queryString){
$options['body'] = json_encode(['input' => $queryString]);
}
$response = $this->client->request('delete', $itemType . '/' . $id, $options);
return [
'statusCode' => $response->getStatusCode(),
'body' => $response->getBody()->getContents(),
Expand Down

0 comments on commit 2c258d8

Please sign in to comment.