Skip to content

Commit

Permalink
Merge pull request #8 from voldern/category-assets
Browse files Browse the repository at this point in the history
Make limit optional and fix wrong return type on categories.fetchAssets endpoint
  • Loading branch information
michalmatoga committed May 19, 2014
2 parents 9aabafd + aab7251 commit 7178561
Show file tree
Hide file tree
Showing 5 changed files with 461 additions and 2 deletions.
10 changes: 9 additions & 1 deletion library/SvpApi/Collection/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ public static function fromCommand(OperationCommand $command) {
if ($command->getResponse()->getStatusCode() == 200) {
try {
$response = $command->getResponse()->json();
$itemsList = isset($response['_embedded']['assets']) ? (array) $response['_embedded']['assets'] : [];

if (isset($response['_embedded']['assets'])) {
$itemsList = (array) $response['_embedded']['assets'];
} else if (isset($response['assets'])) {
$itemsList = (array) $response['assets'];
} else {
$itemsList = [];
}

$halLinks = isset($response['_links']) ? (array) $response['_links'] : [];
} catch (RuntimeException $e) {
$message = 'Can\'t parse json response: %s';
Expand Down
3 changes: 2 additions & 1 deletion library/SvpApi/service.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
'httpMethod' => 'GET',
'uri' => '{provider}/categories/{categoryId}/assets',
'summary' => 'Get category by ID with assets collection',
'responseClass' => 'SvpApi\Collection\Assets',
'parameters' => [
'provider' => [
'description' => 'Data provider',
Expand All @@ -118,7 +119,7 @@
'description' => 'The maximum number of results to return',
'location' => 'query',
'type' => 'string',
'required' => true,
'required' => false,
],
'page' => [
'description' => 'Page number',
Expand Down
18 changes: 18 additions & 0 deletions test/SvpApiTest/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,24 @@ public function testPutCategoryValid() {
$this->assertInstanceOf('SvpApi\Entity\Categories', $category);
}

/**
* Test fetch of assets from category endpoint
*/
public function testFetchCategoryAssets() {
$this->fetchAssetsTest(function() {
return $this->client->fetchCategoryAssets(1);
}, 'category_assets_fetch');
}

/**
* Test fetch of assets from category endpoint with limit and page
*/
public function testFetchCategoryAssetsWithLimitAndPage() {
$this->fetchAssetsTest(function() {
return $this->client->fetchCategoryAssets(1, 2, 3);
}, 'category_assets_fetch_limit_page', 2, 3);
}

/**
* Test fetch assets by barrel id
*/
Expand Down
Loading

0 comments on commit 7178561

Please sign in to comment.