-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add repositories and requests (#5)
- Loading branch information
1 parent
b95f737
commit 03b23f1
Showing
64 changed files
with
2,141 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,11 @@ | |
"description": "MyParcel Plugin Development Kit", | ||
"type": "library", | ||
"homepage": "https://www.myparcel.nl", | ||
"minimum-stability": "dev", | ||
"require": { | ||
"myparcelnl/sdk": "^7.1", | ||
"php": ">=7.1.0", | ||
"myparcelnl/sdk": "^7.1" | ||
"php-di/php-di": "~6.0.0", | ||
"guzzlehttp/guzzle": "^7.4" | ||
}, | ||
"require-dev": { | ||
"pestphp/pest": "^1.21", | ||
|
@@ -20,14 +21,16 @@ | |
"MyParcelNL\\Pdk\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"MyParcelNL\\Pdk\\": "tests/Unit", | ||
"MyParcelNL\\Pdk\\Tests\\": "tests" | ||
} | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Edie Lemoine", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Joeri van Veen", | ||
"email": "[email protected]" | ||
"email": "[email protected]" | ||
} | ||
], | ||
"config": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" colors="true" cacheResult="true" | ||
executionOrder="depends,defects"> | ||
<coverage> | ||
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
> | ||
<testsuites> | ||
<testsuite name="Test Suite"> | ||
<directory>./tests/Unit</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<coverage processUncoveredFiles="true"> | ||
<include> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
<exclude> | ||
<file>./src/Api/MyParcelApiService.php</file> | ||
</exclude> | ||
</coverage> | ||
<testsuites> | ||
<testsuite name="Unit"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<php> | ||
<env name="TEST" value="true" /> | ||
</php> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MyParcelNL\Pdk\Account; | ||
|
||
class Platform | ||
{ | ||
public const FLESPAKKET_ID = 3; | ||
public const FLESPAKKET_NAME = 'flespakket'; | ||
public const MYPARCEL_ID = 1; | ||
public const MYPARCEL_NAME = 'myparcel'; | ||
public const SENDMYPARCEL_ID = 2; | ||
public const SENDMYPARCEL_NAME = 'belgie'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MyParcelNL\Pdk\Account\Repository; | ||
|
||
use MyParcelNL\Pdk\Account\Request\GetAccountsRequest; | ||
use MyParcelNL\Pdk\Account\Response\GetAccountsResponseWithBody; | ||
use MyParcelNL\Pdk\Base\Repository\AbstractRepository; | ||
use MyParcelNL\Sdk\src\Model\Account\Account; | ||
|
||
class AccountRepository extends AbstractRepository | ||
{ | ||
/** | ||
* @return \MyParcelNL\Sdk\src\Model\Account\Account | ||
* @throws \GuzzleHttp\Exception\GuzzleException | ||
* @throws \MyParcelNL\Sdk\src\Exception\ApiException | ||
*/ | ||
public function getAccount(): Account | ||
{ | ||
return $this->retrieve('account', function () { | ||
/** @var GetAccountsResponseWithBody $response */ | ||
$response = $this->api->doRequest(new GetAccountsRequest(), GetAccountsResponseWithBody::class); | ||
|
||
return $response->getAccount(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MyParcelNL\Pdk\Account\Repository; | ||
|
||
use MyParcelNL\Pdk\Account\Request\GetCarrierOptionsRequest; | ||
use MyParcelNL\Pdk\Account\Response\GetCarrierOptionsResponseWithBody; | ||
use MyParcelNL\Pdk\Base\Repository\AbstractRepository; | ||
use MyParcelNL\Sdk\src\Support\Collection; | ||
|
||
class CarrierOptionsRepository extends AbstractRepository | ||
{ | ||
/** | ||
* @param int $carrierId | ||
* | ||
* @return \MyParcelNL\Sdk\src\Support\Collection | ||
* @throws \GuzzleHttp\Exception\GuzzleException | ||
* @throws \MyParcelNL\Sdk\src\Exception\ApiException | ||
*/ | ||
public function getCarrierOptions(int $carrierId): Collection | ||
{ | ||
return $this->retrieve('carrier_options', function () use ($carrierId) { | ||
/** @var \MyParcelNL\Pdk\Account\Response\GetCarrierOptionsResponseWithBody $response */ | ||
$response = $this->api->doRequest( | ||
new GetCarrierOptionsRequest($carrierId), | ||
GetCarrierOptionsResponseWithBody::class | ||
); | ||
|
||
return $response->getCarrierOptions(); | ||
}); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/Account/Repository/ShopCarrierConfigurationRepository.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MyParcelNL\Pdk\Account\Repository; | ||
|
||
use MyParcelNL\Pdk\Account\Request\GetShopCarrierConfigurationRequest; | ||
use MyParcelNL\Pdk\Account\Request\GetShopCarrierConfigurationsRequest; | ||
use MyParcelNL\Pdk\Account\Response\GetShopCarrierConfigurationsResponseWithBody; | ||
use MyParcelNL\Pdk\Base\Repository\AbstractRepository; | ||
use MyParcelNL\Sdk\src\Model\Account\CarrierConfiguration; | ||
use MyParcelNL\Sdk\src\Support\Collection; | ||
|
||
class ShopCarrierConfigurationRepository extends AbstractRepository | ||
{ | ||
/** | ||
* @param int $shopId | ||
* @param string $carrier | ||
* | ||
* @return \MyParcelNL\Sdk\src\Model\Account\CarrierConfiguration | ||
* @throws \GuzzleHttp\Exception\GuzzleException | ||
* @throws \MyParcelNL\Sdk\src\Exception\ApiException | ||
*/ | ||
public function getCarrierConfiguration(int $shopId, string $carrier): CarrierConfiguration | ||
{ | ||
return $this->retrieve('carrier_configurations', function () use ($carrier, $shopId) { | ||
/** @var \MyParcelNL\Pdk\Account\Response\GetShopCarrierConfigurationsResponseWithBody $response */ | ||
$response = $this->api->doRequest( | ||
new GetShopCarrierConfigurationRequest($shopId, $carrier), | ||
GetShopCarrierConfigurationsResponseWithBody::class | ||
); | ||
|
||
return $response | ||
->getCarrierConfigurations() | ||
->first(); | ||
}); | ||
} | ||
|
||
/** | ||
* @param int $shopId | ||
* | ||
* @return \MyParcelNL\Sdk\src\Support\Collection | ||
* @throws \GuzzleHttp\Exception\GuzzleException | ||
* @throws \MyParcelNL\Sdk\src\Exception\ApiException | ||
*/ | ||
public function getCarrierConfigurations(int $shopId): Collection | ||
{ | ||
return $this->retrieve('carrier_configurations', function () use ($shopId) { | ||
/** @var \MyParcelNL\Pdk\Account\Response\GetShopCarrierConfigurationsResponseWithBody $response */ | ||
$response = $this->api->doRequest( | ||
new GetShopCarrierConfigurationsRequest($shopId), | ||
GetShopCarrierConfigurationsResponseWithBody::class | ||
); | ||
|
||
return $response->getCarrierConfigurations(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MyParcelNL\Pdk\Account\Repository; | ||
|
||
use MyParcelNL\Pdk\Account\Request\GetShopsRequest; | ||
use MyParcelNL\Pdk\Account\Response\GetShopsResponseWithBody; | ||
use MyParcelNL\Pdk\Base\Repository\AbstractRepository; | ||
use MyParcelNL\Sdk\src\Model\Account\Shop; | ||
|
||
class ShopRepository extends AbstractRepository | ||
{ | ||
/** | ||
* @throws \GuzzleHttp\Exception\GuzzleException | ||
* @throws \MyParcelNL\Sdk\src\Exception\ApiException | ||
*/ | ||
public function getShop(): Shop | ||
{ | ||
return $this->retrieve('shop', function () { | ||
/** @var \MyParcelNL\Pdk\Account\Response\GetShopsResponseWithBody $response */ | ||
$response = $this->api->doRequest(new GetShopsRequest(), GetShopsResponseWithBody::class); | ||
|
||
return $response->getShop(); | ||
}); | ||
} | ||
} |
Oops, something went wrong.