From 371e7fae844eb434bee9460318e7b2a886eef9ac Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 7 Oct 2022 11:26:58 +0200 Subject: [PATCH] :sparkles: Introduce Unit api endpoint --- src/Api/CompaniesApi.php | 6 +--- src/Api/ContactsApi.php | 6 +--- src/Api/TaxesApi.php | 4 +-- src/Api/UnitsApi.php | 49 ++++++++++++++++++++++++++++++ src/Collections/UnitCollection.php | 25 +++++++++++++++ src/Entities/Unit.php | 27 ++++++++++++++++ 6 files changed, 105 insertions(+), 12 deletions(-) create mode 100644 src/Api/UnitsApi.php create mode 100644 src/Collections/UnitCollection.php create mode 100644 src/Entities/Unit.php diff --git a/src/Api/CompaniesApi.php b/src/Api/CompaniesApi.php index d5bb821..81b0dd0 100644 --- a/src/Api/CompaniesApi.php +++ b/src/Api/CompaniesApi.php @@ -12,6 +12,7 @@ * @author Thomas * @version 1.0 * @access public + * @see https://api.sellsy.com/doc/v2/#tag/Companies */ class CompaniesApi extends AbstractApi { @@ -26,7 +27,6 @@ public function __construct() $this->collection = CompanyCollection::class; } - /** * List all companies. * @@ -47,7 +47,6 @@ public function index(array $query = []): self return $this; } - /** * Show a single company by id. * @@ -69,7 +68,6 @@ public function show(string $id, array $query = []): self return $this; } - /** * Store (create) an company. * @@ -95,7 +93,6 @@ public function store(Company $company, array $query = []): self return $this; } - /** * Update an existing company. * @@ -121,7 +118,6 @@ public function update(Company $company, array $query = []): self return $this; } - /** * Delete an existing company. * diff --git a/src/Api/ContactsApi.php b/src/Api/ContactsApi.php index 0e586b8..6dcf248 100644 --- a/src/Api/ContactsApi.php +++ b/src/Api/ContactsApi.php @@ -12,6 +12,7 @@ * @author Thomas * @version 1.0 * @access public + * @see https://api.sellsy.com/doc/v2/#tag/Contacts */ class ContactsApi extends AbstractApi { @@ -26,7 +27,6 @@ public function __construct() $this->collection = ContactCollection::class; } - /** * List all contacts. * @@ -47,7 +47,6 @@ public function index(array $query = []): self return $this; } - /** * Show a single contact by id. * @@ -69,7 +68,6 @@ public function show(string $id, array $query = []): self return $this; } - /** * Store (create) an contact. * @@ -95,7 +93,6 @@ public function store(Contact $contact, array $query = []): self return $this; } - /** * Update an existing contact. * @@ -121,7 +118,6 @@ public function update(Contact $contact, array $query = []): self return $this; } - /** * Delete an existing contact. * diff --git a/src/Api/TaxesApi.php b/src/Api/TaxesApi.php index c4d94f8..8da9eb9 100644 --- a/src/Api/TaxesApi.php +++ b/src/Api/TaxesApi.php @@ -6,12 +6,13 @@ use Bluerock\Sellsy\Collections\TaxCollection; /** - * The API client for the `companies` namespace. + * The API client for the `taxes` namespace. * * @package sellsy-connector * @author Thomas * @version 1.0 * @access public + * @see https://api.sellsy.com/doc/v2/#tag/Taxes */ class TaxesApi extends AbstractApi { @@ -26,7 +27,6 @@ public function __construct() $this->collection = TaxCollection::class; } - /** * List all taxes. * diff --git a/src/Api/UnitsApi.php b/src/Api/UnitsApi.php new file mode 100644 index 0000000..81709c4 --- /dev/null +++ b/src/Api/UnitsApi.php @@ -0,0 +1,49 @@ + + * @version 1.1 + * @access public + * @see https://api.sellsy.com/doc/v2/#tag/Units + */ +class UnitsApi extends AbstractApi +{ + /** + * @inheritdoc + */ + public function __construct() + { + parent::__construct(); + + $this->entity = Unit::class; + $this->collection = UnitCollection::class; + } + + /** + * List all units. + * + * @param array $query Query parameters. + * + * @return \Illuminate\Http\Client\Response + * @see https://api.sellsy.com/doc/v2/#operation/get-units + */ + public function index(array $query = []): self + { + $response = $this->connection + ->request('units') + ->get($query); + + $this->response = $response; + $this->response->throw(); + + return $this; + } +} diff --git a/src/Collections/UnitCollection.php b/src/Collections/UnitCollection.php new file mode 100644 index 0000000..12760ca --- /dev/null +++ b/src/Collections/UnitCollection.php @@ -0,0 +1,25 @@ + + * @version 1.0 + * @access public + * + * @method \Bluerock\Sellsy\Entities\Unit current + */ +class UnitCollection extends DataTransferObjectCollection implements EntityCollectionContract +{ + public static function create(array $data): UnitCollection + { + return new static(Unit::arrayOf($data)); + } +} diff --git a/src/Entities/Unit.php b/src/Entities/Unit.php new file mode 100644 index 0000000..a58670d --- /dev/null +++ b/src/Entities/Unit.php @@ -0,0 +1,27 @@ + + * @version 1.0 + * @access public + */ +class Unit extends FlexibleDataTransferObject implements EntityContract +{ + /** + * Tax class ID from Sellsy. + */ + public int $id; + + /** + * Tax class label. + */ + public ?string $label; +}