Skip to content

Commit

Permalink
Add support for filtering on getCategories() (#1)
Browse files Browse the repository at this point in the history
Support for filtering product categories to those the vendor
can upload designs for was added to the api.
The change here makes this usable by this client implementation.
  • Loading branch information
Chris Hepner committed Feb 16, 2018
1 parent b545f0c commit 72a8afa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/DesignsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,18 @@ public function resubmitDesign($id, $resubmissionData)
return json_decode($res->getBody()->getContents(), true);
}

public function getCategories()
/**
* Returns a list of product categories
*
* Supports passing additional filter params, i.e., "'licensed' => 1"
* @see http://apidocs.affinitygateway.com/#operation/listCategories
* @param array $params key/value pairs of additional params
* @return array Product categories listing
*/
public function getCategories(array $params = [])
{
$path = '/product_categories';
$res = $this->client->request('GET', $path);
$res = $this->client->request('GET', $path, ['query' => $params]);

if ($res->getStatusCode() !== 200) {
$this->throwInvalidResponseException($res);
Expand Down
10 changes: 10 additions & 0 deletions tests/Affinity/ListCategoriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ public function request_has_appropriate_headers()
$this->assertEquals('test-api-key', $requestHeaders['X-Api-Key'][0]);
}

/** @test */
public function request_includes_parameters()
{
$this->designs->getCategories(['is_available' => true]);

$request = $this->historyContainer[0]['request'];

$this->assertEquals('is_available=1', $request->getUri()->getQuery());
}

/** @test */
public function throws_exception_on_non_200_response()
{
Expand Down

0 comments on commit 72a8afa

Please sign in to comment.