Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for filtering on getCategories() #1

Merged
merged 1 commit into from
Feb 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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