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

Implemented the products category endpoint #19

Merged
merged 1 commit into from
Oct 2, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Next release
New features:
- `GET /api/v1/cloudstorages` added. (`Client::getCloudStorages()`)
- `GET /api/v1/products/category` added. (`Client::getCategories()`)

## 1.6.2 (16 Sep 2019)

Expand Down
23 changes: 20 additions & 3 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function __construct($username, $apiPassword, $apiKey, LoggerInterface $l
try {
$this->jom = new ObjectMapper(new JsonSerializer());
} catch (Exception $ex) {
if($logger !== null) {
if ($logger !== null) {
$this->logger->critical('Object Mapper could not be created.');
}
throw $ex;
Expand Down Expand Up @@ -139,12 +139,11 @@ public function getProducts($page = 1, $pageSize = 50, DateTime $minCreatedAt =
*
* @param int $productId The product id
* @param string $lookupBy Either the value id, ean or the value sku to specify the meaning of the id parameter
* @see \BillbeeDe\BillbeeAPI\Type\ProductLookupBy
*
* @return Response\GetProductResponse The product response
*
* @throws QuotaExceededException If the maximum number of calls per second exceeded
* @throws Exception If the response cannot be parsed
* @see \BillbeeDe\BillbeeAPI\Type\ProductLookupBy
*/
public function getProduct($productId, $lookupBy = Type\ProductLookupBy::ID)
{
Expand All @@ -155,6 +154,24 @@ public function getProduct($productId, $lookupBy = Type\ProductLookupBy::ID)
);
}

/**
* Get a list of all defined categories
*
* @return Response\GetCategoriesResponse The category response
*
* @throws QuotaExceededException If the maximum number of calls per second exceeded
* @throws Exception If the response cannot be parsed
*
*/
public function getCategories()
{
return $this->requestGET(
'products/category',
[],
Response\GetCategoriesResponse::class
);
}

#endregion

#region POST
Expand Down
24 changes: 24 additions & 0 deletions src/Response/GetCategoriesResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* This file is part of the Billbee API package.
*
* Copyright 2017 - 2019 by Billbee GmbH
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code.
*
* Created by Julian Finkler <julian@billbee.io>
*/

namespace BillbeeDe\BillbeeAPI\Response;

use MintWare\DMM\DataField;

class GetCategoriesResponse extends BaseResponse
{
/**
* @var \BillbeeDe\BillbeeAPI\Model\Category[]
* @DataField(name="Data", type="\BillbeeDe\BillbeeAPI\Model\Category[]")
*/
public $data = null;
}
1 change: 1 addition & 0 deletions test_config.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ test_delete_web_hooks: false # If true, the delete all web hooks call will be te
customer_id: '' # Id of a customer
address_id: '' # Id of an address
cloud_storage_id: 0 # Id of an cloud storage
category_id: 0 # Id of c category
# Test Shipping:
shippable_order_id: '' # Id of an order which can be shipped
shipping_provider_id: '' # The Id of a shipping provider
Expand Down
26 changes: 26 additions & 0 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class ClientTest extends TestCase
protected $shippingProviderId;
protected $shippingProviderProduct;
protected $cloudStorageId = 0;
protected $categoryId = 0;

public function __construct($name = null, array $data = [], $dataName = '')
{
Expand All @@ -114,6 +115,7 @@ public function __construct($name = null, array $data = [], $dataName = '')
$this->shippingProviderId,
$this->shippingProviderProduct,
$this->cloudStorageId,
$this->categoryId,
) = [
$data['username'],
$data['password'],
Expand All @@ -134,6 +136,7 @@ public function __construct($name = null, array $data = [], $dataName = '')
$data['shipping_provider_id'],
$data['shipping_provider_product'],
$data['cloud_storage_id'],
$data['category_id'],
];
}

Expand Down Expand Up @@ -1171,6 +1174,29 @@ public function testGetCloudStorages()
$this->assertTrue($containsCloudStorage);
}

/** @throws Exception */
public function testGetCategories()
{
if ($this->categoryId == 0) {
return;
}

$client = $this->getClient();
sleep(1);
$categories = $client->getCategories();
$this->assertGreaterThanOrEqual(1, count($categories->data));

$containsCategory = false;
foreach ($categories->data as $category) {
if ($category->id == $this->categoryId) {
$containsCategory = true;
break;
}
}

$this->assertTrue($containsCategory);
}

/** @throws Exception */
public function getClient()
{
Expand Down