diff --git a/composer.json b/composer.json index 6980cec0a9880f590c8dfcdc3110db1a6f8de345..fc3057c3e3e0044a591aa4914bffc82420a48959 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,7 @@ "require": { "php": ">=5.5", "psr/log": "^1.0.1", + "wpdesk/wp-cache": "dev-master", "wpdesk/wp-http-client": "dev-master", "psr/simple-cache": "^1.0" }, diff --git a/src/ApiClient/CachedClient.php b/src/Client/CachedClient.php similarity index 83% rename from src/ApiClient/CachedClient.php rename to src/Client/CachedClient.php index a7f512c2a97ab2827fe8ca83151bc0ee60735470..7d23f344f8b06a770de7f4548dfede9e946a641b 100644 --- a/src/ApiClient/CachedClient.php +++ b/src/Client/CachedClient.php @@ -1,15 +1,15 @@ <?php -namespace WPDesk\SaasPlatformClient\ApiClient; +namespace WPDesk\ApiClient\ApiClient; use Psr\SimpleCache\CacheInterface; -use WPDesk\SaasPlatformClient\Cache\CacheDispatcher; -use WPDesk\SaasPlatformClient\Cache\CacheItemCreator; -use WPDesk\SaasPlatformClient\Cache\CacheItemVerifier; -use WPDesk\SaasPlatformClient\HttpClient\HttpClient; -use WPDesk\SaasPlatformClient\Request\Request; -use WPDesk\SaasPlatformClient\Response\Response; -use WPDesk\SaasPlatformClient\Serializer\Serializer; +use WPDesk\ApiClient\Cache\CacheDispatcher; +use WPDesk\ApiClient\Cache\CacheItemCreator; +use WPDesk\ApiClient\Cache\CacheItemVerifier; +use WPDesk\ApiClient\HttpClient\HttpClient; +use WPDesk\ApiClient\Request\Request; +use WPDesk\ApiClient\Response\Response; +use WPDesk\ApiClient\Serializer\Serializer; class CachedClient implements Client, CacheItemCreator, CacheItemVerifier { diff --git a/src/ApiClient/Client.php b/src/Client/Client.php similarity index 70% rename from src/ApiClient/Client.php rename to src/Client/Client.php index 993f5caafc60b9207476c9db51a71ba872041110..e63e184c6aa9e998cde32ef82cb0be507198e1bf 100644 --- a/src/ApiClient/Client.php +++ b/src/Client/Client.php @@ -1,11 +1,11 @@ <?php -namespace WPDesk\SaasPlatformClient\ApiClient; +namespace WPDesk\ApiClient\ApiClient; -use WPDesk\SaasPlatformClient\HttpClient\HttpClient; -use WPDesk\SaasPlatformClient\Request\Request; -use WPDesk\SaasPlatformClient\Response\Response; -use WPDesk\SaasPlatformClient\Serializer\Serializer; +use WPDesk\ApiClient\HttpClient\HttpClient; +use WPDesk\ApiClient\Request\Request; +use WPDesk\ApiClient\Response\Response; +use WPDesk\ApiClient\Serializer\Serializer; interface Client { diff --git a/src/ApiClient/ClientFactory.php b/src/Client/ClientFactory.php similarity index 73% rename from src/ApiClient/ClientFactory.php rename to src/Client/ClientFactory.php index a5b45e6b6d53a2eb85c44da2c3f3ec6ab478d123..b92f4598bd09b69fb2640286e247e66a43f4171a 100644 --- a/src/ApiClient/ClientFactory.php +++ b/src/Client/ClientFactory.php @@ -1,11 +1,11 @@ <?php -namespace WPDesk\SaasPlatformClient\ApiClient; +namespace WPDesk\ApiClient\ApiClient; -use WPDesk\SaasPlatformClient\Cache\WordpressCache; -use WPDesk\SaasPlatformClient\HttpClient\HttpClientFactory; -use WPDesk\SaasPlatformClient\PlatformFactoryOptions; -use WPDesk\SaasPlatformClient\Serializer\SerializerFactory; +use WPDesk\ApiClient\Cache\WordpressCache; +use WPDesk\ApiClient\HttpClient\HttpClientFactory; +use WPDesk\ApiClient\PlatformFactoryOptions; +use WPDesk\ApiClient\Serializer\SerializerFactory; class ClientFactory { diff --git a/src/ApiClient/ClientImplementation.php b/src/Client/ClientImplementation.php similarity index 97% rename from src/ApiClient/ClientImplementation.php rename to src/Client/ClientImplementation.php index 6153d4ca5ec0d5ad97359b7211dfd01d4bd6ff59..02e9c52bfdf4b481f49d203583d703570d5e6829 100644 --- a/src/ApiClient/ClientImplementation.php +++ b/src/Client/ClientImplementation.php @@ -1,11 +1,11 @@ <?php -namespace WPDesk\SaasPlatformClient\ApiClient; +namespace WPDesk\ApiClient\ApiClient; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerInterface; -use WPDesk\SaasPlatformClient\HttpClient\HttpClient; -use WPDesk\SaasPlatformClient\HttpClient\HttpClientResponse; +use WPDesk\HttpClient\HttpClient; +use WPDesk\HttpClient\HttpClientResponse; use WPDesk\SaasPlatformClient\Platform; use WPDesk\SaasPlatformClient\Request\Request; use WPDesk\SaasPlatformClient\Response\RawResponse; diff --git a/src/ApiClient/RequestCacheInfoResolver.php b/src/Client/RequestCacheInfoResolver.php similarity index 100% rename from src/ApiClient/RequestCacheInfoResolver.php rename to src/Client/RequestCacheInfoResolver.php diff --git a/src/Request/AuthRequest.php b/src/Request/AuthRequest.php deleted file mode 100644 index 34158128cd8aaa61a9bf8937795c9339dee68b88..0000000000000000000000000000000000000000 --- a/src/Request/AuthRequest.php +++ /dev/null @@ -1,53 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Request; - -use WPDesk\SaasPlatformClient\Authentication\Token; - -class AuthRequest extends BasicRequest -{ - /** @var Token */ - private $token; - - public function __construct(Token $token) - { - $this->setToken($token); - } - - /** - * @param Token $token - */ - public function setToken(Token $token) - { - $this->token = $token; - } - - /** - * @return bool - */ - public function isTokenExpired() - { - return $this->token->isExpired(); - } - - /** - * @return bool - */ - public function isTokenInvalid() - { - return !$this->token->isSignatureValid(); - } - - /** - * Returns array of http headers - * - * @return array - */ - public function getHeaders() - { - $headers = array( - 'Authorization' => $this->token->getAuthString() - ); - return array_merge($headers, parent::getHeaders()); - } -} \ No newline at end of file diff --git a/src/Request/Authentication/ConnectKeyInfoRequest.php b/src/Request/Authentication/ConnectKeyInfoRequest.php deleted file mode 100644 index fe611c6ee521791041f60562f16119349f41b243..0000000000000000000000000000000000000000 --- a/src/Request/Authentication/ConnectKeyInfoRequest.php +++ /dev/null @@ -1,28 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Request\Authentication; - -use WPDesk\SaasPlatformClient\Authentication\Token; -use WPDesk\SaasPlatformClient\Request\AuthRequest; - -final class ConnectKeyInfoRequest extends AuthRequest -{ - /** @var string */ - protected $method = 'GET'; - - /** @var string */ - protected $endPoint = '/connectkeyinfo/{connectKey}'; - - - /** - * ConnectKeyInfoRequest constructor. - * @param $connectKey - * @param Token $token - */ - public function __construct($connectKey, Token $token) - { - parent::__construct($token); - - $this->endPoint = str_replace('{connectKey}', $connectKey, $this->endPoint); - } -} \ No newline at end of file diff --git a/src/Request/Authentication/ConnectKeyResetRequest.php b/src/Request/Authentication/ConnectKeyResetRequest.php deleted file mode 100644 index 0c2cd8cd06c831173081c86b99f744bfda7b994e..0000000000000000000000000000000000000000 --- a/src/Request/Authentication/ConnectKeyResetRequest.php +++ /dev/null @@ -1,23 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Request\Authentication; - -use WPDesk\SaasPlatformClient\Authentication\Token; -use WPDesk\SaasPlatformClient\Request\AuthRequest; - -final class ConnectKeyResetRequest extends AuthRequest -{ - /** @var string */ - protected $method = 'POST'; - - /** @var string */ - protected $endPoint = '/users/{id}/connectKeyReset'; - - - public function __construct($user_id, Token $token) - { - parent::__construct($token); - - $this->endPoint = str_replace('{id}', $user_id, $this->endPoint); - } -} \ No newline at end of file diff --git a/src/Request/Authentication/RegisterRequest.php b/src/Request/Authentication/RegisterRequest.php deleted file mode 100644 index 3a231d6335adaf5c2fb42166bec65ba5539db85d..0000000000000000000000000000000000000000 --- a/src/Request/Authentication/RegisterRequest.php +++ /dev/null @@ -1,29 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Request\Authentication; - -use WPDesk\SaasPlatformClient\Request\BasicRequest; - -final class RegisterRequest extends BasicRequest -{ - /** @var string */ - protected $method = 'POST'; - - /** @var string */ - protected $endPoint = '/register'; - - /** - * RegisterRequest constructor. - * @param string $email - * @param string $domain - * @param string $locale - * @param ?string $admin_url - */ - public function __construct($email, $domain, $locale, $admin_url = null) - { - $this->data = compact('email', 'domain', 'locale'); - if ($admin_url !== null) { - $this->data['adminUrl'] = $admin_url; - } - } -} \ No newline at end of file diff --git a/src/Request/Authentication/TokenRequest.php b/src/Request/Authentication/TokenRequest.php deleted file mode 100644 index 289011bc75516763aa2b8639d6e3d3626284e8ea..0000000000000000000000000000000000000000 --- a/src/Request/Authentication/TokenRequest.php +++ /dev/null @@ -1,26 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Request\Authentication; - - -use WPDesk\SaasPlatformClient\Request\BasicRequest; - -final class TokenRequest extends BasicRequest -{ - /** @var string */ - protected $method = 'POST'; - - /** @var string */ - protected $endPoint = '/token'; - - /** - * TokenRequest constructor. - * @param string $connectKey - * @param string $domain - * @param string $locale - */ - public function __construct($connectKey, $domain, $locale) - { - $this->data = compact(['connectKey', 'domain', 'locale']); - } -} \ No newline at end of file diff --git a/src/Request/BasicRequest.php b/src/Request/BasicRequest.php index c185d1eaf3be7b2d72e85e21997cb0e01a1d0194..ae0f599f099ec06cd26b8d551e1bfa4b6d44e844 100644 --- a/src/Request/BasicRequest.php +++ b/src/Request/BasicRequest.php @@ -1,6 +1,6 @@ <?php -namespace WPDesk\SaasPlatformClient\Request; +namespace WPDesk\ApiClient\Request; class BasicRequest implements Request diff --git a/src/Request/Cancel/PostCancelRequest.php b/src/Request/Cancel/PostCancelRequest.php deleted file mode 100644 index a780ee2f1300af6262227aa966b526838644ecc8..0000000000000000000000000000000000000000 --- a/src/Request/Cancel/PostCancelRequest.php +++ /dev/null @@ -1,39 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Request\Cancel; - -use WPDesk\SaasPlatformClient\Authentication\Token; -use WPDesk\SaasPlatformClient\Request\AuthRequest; - -final class PostCancelRequest extends AuthRequest -{ - /** @var string */ - protected $method = 'POST'; - - /** @var string */ - protected $endPoint = '/shops/{shop}/shipping_services/{service}/shipments/{shipment}/cancel'; - - /** - * PostShipmentRequest constructor. - * @param Token $token - * @param int $shippingServiceId - * @param int $shopId - * @param int $shipmentId - */ - public function __construct( - Token $token, - $shippingServiceId, - $shopId, - $shipmentId - ) { - parent::__construct($token); - - $this->endPoint = str_replace( - ['{shop}', '{service}', '{shipment}'], - [$shopId, $shippingServiceId, $shipmentId], - $this->endPoint - ); - - $this->data = []; - } -} \ No newline at end of file diff --git a/src/Request/Fields/GetFieldsRequest.php b/src/Request/Fields/GetFieldsRequest.php deleted file mode 100644 index 2e5b881261d77eb62b97001a8cb9d764f7170425..0000000000000000000000000000000000000000 --- a/src/Request/Fields/GetFieldsRequest.php +++ /dev/null @@ -1,45 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Request\Fields; - -use WPDesk\SaasPlatformClient\Authentication\Token; -use WPDesk\SaasPlatformClient\Request\AuthRequest; - -final class GetFieldsRequest extends AuthRequest -{ - /** @var string */ - protected $method = 'GET'; - - /** @var string */ - protected $endPoint = '/shops/{shop}/shipping_services/{service}/dynamic_fields/{zone_targets}'; - - const ZONE_TARGETS_DELIMITER = ','; - - /** - * @param array $zoneTargets - * @return string - */ - private function serializeZoneTargets(array $zoneTargets) - { - return implode(self::ZONE_TARGETS_DELIMITER, $zoneTargets); - } - - /** - * PostShipmentRequest constructor. - * @param Token $token - * @param int $shippingServiceId - * @param int $shopId - * @param string[] $zoneTargets - */ - public function __construct( - Token $token, - $shippingServiceId, - $shopId, - array $zoneTargets - ) { - parent::__construct($token); - - $this->endPoint = str_replace(['{shop}', '{service}', '{zone_targets}'], - [$shopId, $shippingServiceId, $this->serializeZoneTargets($zoneTargets)], $this->endPoint); - } -} \ No newline at end of file diff --git a/src/Request/Label/PostLabelRequest.php b/src/Request/Label/PostLabelRequest.php deleted file mode 100644 index e34dcd7409ea459080ad61f9e2f1395e1e992a43..0000000000000000000000000000000000000000 --- a/src/Request/Label/PostLabelRequest.php +++ /dev/null @@ -1,36 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Request\Label; - -use WPDesk\SaasPlatformClient\Authentication\Token; -use WPDesk\SaasPlatformClient\Request\AuthRequest; - -final class PostLabelRequest extends AuthRequest -{ - /** @var string */ - protected $method = 'POST'; - - /** @var string */ - protected $endPoint = '/shops/{shop}/shipping_services/{service}/shipments/{shipment}/labels'; - - /** - * PostShipmentRequest constructor. - * @param Token $token - * @param int $shippingServiceId - * @param int $shopId - * @param int $shipmentId - */ - public function __construct( - Token $token, - $shippingServiceId, - $shopId, - $shipmentId - ) { - parent::__construct($token); - - $this->endPoint = str_replace(['{shop}', '{service}', '{shipment}'], [$shopId, $shippingServiceId, $shipmentId], - $this->endPoint); - - $this->data = []; - } -} \ No newline at end of file diff --git a/src/Request/Rate/PostRateRequest.php b/src/Request/Rate/PostRateRequest.php deleted file mode 100644 index 5352104b930daffd9c6ef11b2ad0c8361874ad31..0000000000000000000000000000000000000000 --- a/src/Request/Rate/PostRateRequest.php +++ /dev/null @@ -1,36 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Request\Rate; - -use WPDesk\SaasPlatformClient\Authentication\Token; -use WPDesk\SaasPlatformClient\Model\Rate\RateRequest; -use WPDesk\SaasPlatformClient\Request\AuthRequest; - -final class PostRateRequest extends AuthRequest -{ - /** @var string */ - protected $method = 'POST'; - - /** @var string */ - protected $endPoint = '/shops/{shop}/shipping_services/{service}/rates'; - - /** - * PostRateRequest constructor. - * @param Token $token - * @param int $shippingServiceId - * @param int $shopId - * @param RateRequest $request - */ - public function __construct( - Token $token, - $shippingServiceId, - $shopId, - RateRequest $request - ) { - parent::__construct($token); - - $this->endPoint = str_replace(['{shop}', '{service}'], [$shopId, $shippingServiceId], $this->endPoint); - - $this->data = $request->toArray(); - } -} \ No newline at end of file diff --git a/src/Request/Request.php b/src/Request/Request.php index 2810176c85a98f131200366f45dc7260d69c761e..4789c80ddcd0e7a46323f58d52ea681f45a481cf 100644 --- a/src/Request/Request.php +++ b/src/Request/Request.php @@ -1,6 +1,6 @@ <?php -namespace WPDesk\SaasPlatformClient\Request; +namespace WPDesk\ApiClient\Request; interface Request diff --git a/src/Request/Shipment/GetUserListShipmentRequest.php b/src/Request/Shipment/GetUserListShipmentRequest.php deleted file mode 100644 index 176c4ba0c605439fd66a6b7e766de81228db98f1..0000000000000000000000000000000000000000 --- a/src/Request/Shipment/GetUserListShipmentRequest.php +++ /dev/null @@ -1,27 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Request\Shipment; - -use WPDesk\SaasPlatformClient\Authentication\Token; -use WPDesk\SaasPlatformClient\Model\Shipment\ShipmentRequest; -use WPDesk\SaasPlatformClient\Request\AuthRequest; - -final class GetUserListShipmentRequest extends AuthRequest -{ - /** @var string */ - protected $method = 'GET'; - - /** @var string */ - protected $endPoint = '/users/{id}/shipments'; - - /** - * GetListShipmentRequest constructor. - * @param Token $token - */ - public function __construct($user_id, Token $token) -{ - parent::__construct($token); - - $this->endPoint = str_replace('{id}', $user_id, $this->endPoint); - } -} \ No newline at end of file diff --git a/src/Request/Shipment/PostShipmentRequest.php b/src/Request/Shipment/PostShipmentRequest.php deleted file mode 100644 index 091382736b8d0ad8ddc67baac6f0f3b8b9502de6..0000000000000000000000000000000000000000 --- a/src/Request/Shipment/PostShipmentRequest.php +++ /dev/null @@ -1,36 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Request\Shipment; - -use WPDesk\SaasPlatformClient\Authentication\Token; -use WPDesk\SaasPlatformClient\Model\Shipment\ShipmentRequest; -use WPDesk\SaasPlatformClient\Request\AuthRequest; - -final class PostShipmentRequest extends AuthRequest -{ - /** @var string */ - protected $method = 'POST'; - - /** @var string */ - protected $endPoint = '/shops/{shop}/shipping_services/{service}/shipments'; - - /** - * PostShipmentRequest constructor. - * @param Token $token - * @param int $shippingServiceId - * @param int $shopId - * @param ShipmentRequest $request - */ - public function __construct( - Token $token, - $shippingServiceId, - $shopId, - ShipmentRequest $request - ) { - parent::__construct($token); - - $this->endPoint = str_replace(['{shop}', '{service}'], [$shopId, $shippingServiceId], $this->endPoint); - - $this->data = $request->toArray(); - } -} \ No newline at end of file diff --git a/src/Request/ShippingPlan/PutShippingPlanRequest.php b/src/Request/ShippingPlan/PutShippingPlanRequest.php deleted file mode 100644 index 010e09d5c6384afda712a33a6f080b29d4cdb176..0000000000000000000000000000000000000000 --- a/src/Request/ShippingPlan/PutShippingPlanRequest.php +++ /dev/null @@ -1,30 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Request\ShippingPlan; - -use WPDesk\SaasPlatformClient\Authentication\Token; -use WPDesk\SaasPlatformClient\Model\ShippingPlan; -use WPDesk\SaasPlatformClient\Request\AuthRequest; - - -final class PutShippingPlanRequest extends AuthRequest -{ - /** @var string */ - protected $method = 'PUT'; - - /** @var ShippingPlan */ - private $plan; - - /** @var string */ - protected $endPoint = '/shipping_plans/{id}'; - - public function __construct(Token $token, ShippingPlan $plan) - { - parent::__construct($token); - $this->plan = $plan; - - $this->data = $plan->toArray(); - - $this->endPoint = str_replace('{id}', $plan->getId(), $this->endPoint); - } -} \ No newline at end of file diff --git a/src/Request/ShippingServices/GetListRequest.php b/src/Request/ShippingServices/GetListRequest.php deleted file mode 100644 index e23bba67f94e87236a9dca220d67d7a84c67f01c..0000000000000000000000000000000000000000 --- a/src/Request/ShippingServices/GetListRequest.php +++ /dev/null @@ -1,14 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Request\ShippingServices; - -use WPDesk\SaasPlatformClient\Request\AuthRequest; - -final class GetListRequest extends AuthRequest -{ - /** @var string */ - protected $method = 'GET'; - - /** @var string */ - protected $endPoint = '/shipping_services'; -} \ No newline at end of file diff --git a/src/Request/ShippingServices/GetServiceRequest.php b/src/Request/ShippingServices/GetServiceRequest.php deleted file mode 100644 index 91785ab7146c730e62f3f47cb5ba4961654faeed..0000000000000000000000000000000000000000 --- a/src/Request/ShippingServices/GetServiceRequest.php +++ /dev/null @@ -1,29 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Request\ShippingServices; - -use WPDesk\SaasPlatformClient\Authentication\Token; -use WPDesk\SaasPlatformClient\Request\AuthRequest; - -final class GetServiceRequest extends AuthRequest -{ - /** @var string */ - protected $method = 'GET'; - - /** @var string */ - protected $endPoint = '/shipping_services/{id}'; - - /** - * PutSettingsRequest constructor. - * @param Token $token - * @param int $shippingServiceId - */ - public function __construct( - Token $token, - $shippingServiceId - ) { - parent::__construct($token); - - $this->endPoint = str_replace('{id}', $shippingServiceId, $this->endPoint); - } -} \ No newline at end of file diff --git a/src/Request/ShippingServicesSettings/GetSettingsRequest.php b/src/Request/ShippingServicesSettings/GetSettingsRequest.php deleted file mode 100644 index 9040b31971050be2815ed975019bf93ca6fd76ea..0000000000000000000000000000000000000000 --- a/src/Request/ShippingServicesSettings/GetSettingsRequest.php +++ /dev/null @@ -1,38 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Request\ShippingServicesSettings; - -use WPDesk\SaasPlatformClient\Authentication\Token; -use WPDesk\SaasPlatformClient\Model\ShippingServiceSetting; -use WPDesk\SaasPlatformClient\Request\AuthRequest; -use WPDesk\SaasPlatformClient\Request\Traits\SettingsItemRequestHelper; - -final class GetSettingsRequest extends AuthRequest -{ - use SettingsItemRequestHelper; - - /** @var string */ - protected $method = 'GET'; - - /** @var string */ - protected $endPoint = '/shipping_services/settings/{id}'; - - /** - * PutSettingsRequest constructor. - * @param Token $token - * @param int $shippingServiceId - * @param int $shopId - * @param string $settingType - */ - public function __construct( - Token $token, - $shippingServiceId, - $shopId, - $settingType = ShippingServiceSetting::TYPE_CONNECTION_SETTINGS - ) { - parent::__construct($token); - - $params = $this->buildSettingsId($shippingServiceId, $shopId, $settingType); - $this->endPoint = str_replace('{id}', $params, $this->endPoint); - } -} \ No newline at end of file diff --git a/src/Request/ShippingServicesSettings/PostSettingsRequest.php b/src/Request/ShippingServicesSettings/PostSettingsRequest.php deleted file mode 100644 index 20e9af30262c0b9e2c502e1b3c5dbe7fe26078eb..0000000000000000000000000000000000000000 --- a/src/Request/ShippingServicesSettings/PostSettingsRequest.php +++ /dev/null @@ -1,30 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Request\ShippingServicesSettings; - -use WPDesk\SaasPlatformClient\Authentication\Token; -use WPDesk\SaasPlatformClient\Model\ShippingServiceSetting; -use WPDesk\SaasPlatformClient\Request\AuthRequest; -use WPDesk\SaasPlatformClient\Request\Traits\SettingsItemRequestHelper; - -final class PostSettingsRequest extends AuthRequest -{ - use SettingsItemRequestHelper; - - /** @var string */ - protected $method = 'POST'; - - /** @var ShippingServiceSetting */ - private $setting; - - /** @var string */ - protected $endPoint = '/shipping_services/settings'; - - public function __construct(Token $token, ShippingServiceSetting $setting) - { - parent::__construct($token); - $this->setting = $setting; - - $this->data = $setting->toArray(); - } -} \ No newline at end of file diff --git a/src/Request/ShippingServicesSettings/PutSettingsRequest.php b/src/Request/ShippingServicesSettings/PutSettingsRequest.php deleted file mode 100644 index ea6079381b4d69d8681003edce5b7a46c603f5f7..0000000000000000000000000000000000000000 --- a/src/Request/ShippingServicesSettings/PutSettingsRequest.php +++ /dev/null @@ -1,36 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Request\ShippingServicesSettings; - -use WPDesk\SaasPlatformClient\Authentication\Token; -use WPDesk\SaasPlatformClient\Model\ShippingServiceSetting; -use WPDesk\SaasPlatformClient\Request\AuthRequest; -use WPDesk\SaasPlatformClient\Request\Traits\SettingsItemRequestHelper; - -final class PutSettingsRequest extends AuthRequest -{ - use SettingsItemRequestHelper; - - /** @var string */ - protected $method = 'PUT'; - - /** @var string */ - protected $endPoint = '/shipping_services/settings/{id}'; - - /** - * PutSettingsRequest constructor. - * @param Token $token - * @param int $shippingServiceId - * @param int $shopId - * @param string $settingType - */ - public function __construct(Token $token, ShippingServiceSetting $setting) - { - parent::__construct($token); - - $params = $this->buildSettingsId($setting->getShippingService(), $setting->getShop(), $setting->getType()); - $this->endPoint = str_replace('{id}', $params, $this->endPoint); - - $this->data = $setting->toArray(); - } -} \ No newline at end of file diff --git a/src/Request/ShippingServicesSettings/Test/GetSettingsTestRequest.php b/src/Request/ShippingServicesSettings/Test/GetSettingsTestRequest.php deleted file mode 100644 index 45009ad1d99ce48a838403af57e2b72644cb9e5c..0000000000000000000000000000000000000000 --- a/src/Request/ShippingServicesSettings/Test/GetSettingsTestRequest.php +++ /dev/null @@ -1,37 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Request\ShippingServicesSettings\Test; - -use WPDesk\SaasPlatformClient\Authentication\Token; -use WPDesk\SaasPlatformClient\Model\ShippingServiceSetting; -use WPDesk\SaasPlatformClient\Request\AuthRequest; - -final class GetSettingsTestRequest extends AuthRequest -{ - /** @var string */ - protected $method = 'GET'; - - /** @var string */ - protected $endPoint = '/shops/{shop}/shipping_services/{service}/settings/{type}/test'; - - /** - * PutSettingsRequest constructor. - * @param Token $token - * @param int $shippingServiceId - * @param int $shopId - */ - public function __construct( - Token $token, - $shippingServiceId, - $shopId - ) { - parent::__construct($token); - - $this->endPoint = str_replace( - ['{shop}', '{service}', '{type}'], - [$shopId, $shippingServiceId, ShippingServiceSetting::TYPE_CONNECTION_SETTINGS], - $this->endPoint - ); - } - -} \ No newline at end of file diff --git a/src/Request/Status/GetStatusRequest.php b/src/Request/Status/GetStatusRequest.php deleted file mode 100644 index 59b9a17aa78f7869f4afb185082ac46b3c7058ec..0000000000000000000000000000000000000000 --- a/src/Request/Status/GetStatusRequest.php +++ /dev/null @@ -1,49 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Request\Status; - -use WPDesk\SaasPlatformClient\Authentication\Token; -use WPDesk\SaasPlatformClient\Request\AuthRequest; -use WPDesk\SaasPlatformClient\Request\BasicRequest; - -final class GetStatusRequest extends BasicRequest -{ - - /** @var string */ - protected $method = 'GET'; - - /** @var string */ - protected $endPoint = '/status'; - - /** @var Token */ - private $token; - - /** - * GetStatusRequest constructor. - * - * @param null|Token $token - */ - public function __construct( - Token $token = null - ) { - $this->token = $token; - } - - /** - * Returns array of http headers - * - * @return array - */ - public function getHeaders() - { - if (null !== $this->token) { - $headers = array( - 'Authorization' => $this->token->getAuthString() - ); - return array_merge($headers, parent::getHeaders()); - } else { - return parent::getHeaders(); - } - } - -} \ No newline at end of file diff --git a/src/Request/Traits/SettingsItemRequestHelper.php b/src/Request/Traits/SettingsItemRequestHelper.php deleted file mode 100644 index 9b97fad8a479addfcf4e1d8e6df85376475d9745..0000000000000000000000000000000000000000 --- a/src/Request/Traits/SettingsItemRequestHelper.php +++ /dev/null @@ -1,28 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Request\Traits; - -trait SettingsItemRequestHelper -{ - - /** - * Build multiple compound key id in api-platform - * - * @param int $shippingServiceId - * @param int $shopId - * @param string|null $settingType - * @return string - */ - private function buildSettingsId($shippingServiceId, $shopId, $settingType = null) - { - $query_data = [ - 'shippingService' => $shippingServiceId, - 'shop' => $shopId, - 'type' => $settingType - ]; - if (null !== $settingType) { - $query_data['type'] = $settingType; - } - return http_build_query($query_data, null, ';'); - } -} \ No newline at end of file diff --git a/src/Request/Users/GetUserRequest.php b/src/Request/Users/GetUserRequest.php deleted file mode 100644 index 62b0c7a428e9b7000163780a56ed740de1e1d080..0000000000000000000000000000000000000000 --- a/src/Request/Users/GetUserRequest.php +++ /dev/null @@ -1,28 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Request\Users; - -use WPDesk\SaasPlatformClient\Authentication\Token; -use WPDesk\SaasPlatformClient\Request\AuthRequest; - -final class GetUserRequest extends AuthRequest -{ - /** @var string */ - protected $method = 'GET'; - - /** @var string */ - protected $endPoint = '/users/{id}'; - - /** - * getUserRequest constructor. - * - * @param $user_id - * @param Token $token - */ - public function __construct($user_id, Token $token) - { - parent::__construct($token); - - $this->endPoint = str_replace('{id}', $user_id, $this->endPoint); - } -} \ No newline at end of file diff --git a/src/Response/ApiResponse.php b/src/Response/ApiResponse.php index 486e321e6cfb4684524a6745bae53fa7d44a572a..b782720c20c4bc2af45fb93b975e83023def0b09 100644 --- a/src/Response/ApiResponse.php +++ b/src/Response/ApiResponse.php @@ -1,6 +1,6 @@ <?php -namespace WPDesk\SaasPlatformClient\Response; +namespace WPDesk\ApiClient\Response; interface ApiResponse extends Response diff --git a/src/Response/AuthApiResponse.php b/src/Response/AuthApiResponse.php deleted file mode 100644 index 05fee1449be1b4ac66f0b5e15754b6da4acf5688..0000000000000000000000000000000000000000 --- a/src/Response/AuthApiResponse.php +++ /dev/null @@ -1,14 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Response; - -use WPDesk\SaasPlatformClient\Response\Traits\AuthApiResponseDecorator; - -class AuthApiResponse implements ApiResponse -{ - const RESPONSE_CODE_BAD_CREDENTIALS = 401; - - const RESPONSE_CODE_NOT_EXISTS = 404; - - use AuthApiResponseDecorator; -} \ No newline at end of file diff --git a/src/Response/Authentication/ConnectKeyInfoResponse.php b/src/Response/Authentication/ConnectKeyInfoResponse.php deleted file mode 100644 index d89aba812184796b8fd24d1ccb61c693749a18f1..0000000000000000000000000000000000000000 --- a/src/Response/Authentication/ConnectKeyInfoResponse.php +++ /dev/null @@ -1,37 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Response\Authentication; - -use WPDesk\SaasPlatformClient\Response\ApiResponse; -use WPDesk\SaasPlatformClient\Response\Traits\ApiResponseDecorator; - -final class ConnectKeyInfoResponse implements ApiResponse -{ - use ApiResponseDecorator; - - /** - * @return int - */ - public function getUserId() - { - return (int)$this->getResponseBody()['owner_id']; - } - - /** - * @return \DateTimeImmutable - * @throws \Exception - */ - public function getLastUsed() - { - $lastUsed = $this->getResponseBody()['lastUsed']; - return new \DateTimeImmutable($lastUsed['date']); - } - - /** - * @return array[string] - */ - public function getDomains() - { - return $this->getResponseBody()['domains']; - } -} \ No newline at end of file diff --git a/src/Response/Authentication/ConnectKeyResetResponse.php b/src/Response/Authentication/ConnectKeyResetResponse.php deleted file mode 100644 index 4f78a305d26bfbfd9494a42108b214964495cb84..0000000000000000000000000000000000000000 --- a/src/Response/Authentication/ConnectKeyResetResponse.php +++ /dev/null @@ -1,22 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Response\Authentication; - -use WPDesk\SaasPlatformClient\Response\ApiResponse; -use WPDesk\SaasPlatformClient\Response\Traits\AuthApiResponseDecorator; - -final class ConnectKeyResetResponse implements ApiResponse -{ - use AuthApiResponseDecorator; - - /** - * Returns newly generated connect key - * - * @return string - */ - public function getNewConnectKey() - { - $body = $this->getResponseBody(); - return (string)$body['connectKey']; - } -} \ No newline at end of file diff --git a/src/Response/Authentication/RegisterResponse.php b/src/Response/Authentication/RegisterResponse.php deleted file mode 100644 index 046a70f7d699b4b8f768d50d02253770741b159a..0000000000000000000000000000000000000000 --- a/src/Response/Authentication/RegisterResponse.php +++ /dev/null @@ -1,59 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Response\Authentication; - -use WPDesk\SaasPlatformClient\Response\ApiResponse; -use WPDesk\SaasPlatformClient\Response\RawResponse; -use WPDesk\SaasPlatformClient\Response\Traits\ApiResponseDecorator; - -final class RegisterResponse implements ApiResponse -{ - const API_KEY_FIELD = 'password'; - - const RESPONSE_CODE_USER_ALREADY_EXISTS = 460; - - const RESPONSE_CODE_DOMAIN_ALREADY_EXISTS = 461; - - use ApiResponseDecorator; - - /** - * Returns true if user is registered - * - * @return bool - */ - public function isUserRegistered() - { - return in_array($this->getResponseCode(), - [RawResponse::RESPONSE_CODE_CREATED, RawResponse::RESPONSE_CODE_SUCCESS]); - } - - /** - * Returns true if user is was already registered - * - * @return bool - */ - public function isUserAlreadyExists() - { - return $this->getResponseCode() === self::RESPONSE_CODE_USER_ALREADY_EXISTS; - } - - /** - * Returns true if user cannot be registered because domain is occupied - * - * @return bool - */ - public function isDomainOccupied() - { - return $this->getResponseCode() === self::RESPONSE_CODE_DOMAIN_ALREADY_EXISTS; - } - - /** - * Returns apiKey from register response - * - * @return string - */ - public function getApiKey() - { - return $this->getResponseBody()[self::API_KEY_FIELD]; - } -} \ No newline at end of file diff --git a/src/Response/Authentication/TokenResponse.php b/src/Response/Authentication/TokenResponse.php deleted file mode 100644 index e7a724777482bc0bc11982e361b9cc125a088353..0000000000000000000000000000000000000000 --- a/src/Response/Authentication/TokenResponse.php +++ /dev/null @@ -1,56 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Response\Authentication; - -use WPDesk\SaasPlatformClient\Authentication\JWTToken; -use WPDesk\SaasPlatformClient\Response\ApiResponse; -use WPDesk\SaasPlatformClient\Response\AuthApiResponse; -use WPDesk\SaasPlatformClient\Response\Traits\ApiResponseDecorator; - -final class TokenResponse implements ApiResponse -{ - use ApiResponseDecorator; - - const RESPONSE_CODE_LOGIN_SUCCESS = 200; - - /** - * Returns token if exists - * - * @return JWTToken - */ - public function getToken() - { - $body = $this->getResponseBody(); - return new JWTToken($body['token']); - } - - /** - * @return bool - */ - public function isBadCredentials() - { - return $this->getResponseCode() === AuthApiResponse::RESPONSE_CODE_BAD_CREDENTIALS; - } - - /** - * Returns true if login is a success and token is available - * - * @return bool - */ - public function isLoginSuccess() - { - return $this->getResponseCode() === self::RESPONSE_CODE_LOGIN_SUCCESS; - } - - /** - * Returns true if user cannot be registered because domain is occupied - * - * @return bool - */ - public function isDomainOccupied() - { - return $this->getResponseCode() === RegisterResponse::RESPONSE_CODE_DOMAIN_ALREADY_EXISTS; - } - - -} \ No newline at end of file diff --git a/src/Response/Cancel/PostCancelResponse.php b/src/Response/Cancel/PostCancelResponse.php deleted file mode 100644 index 091c61051f1e82d7abe2eb2fb65a5fa171364d1c..0000000000000000000000000000000000000000 --- a/src/Response/Cancel/PostCancelResponse.php +++ /dev/null @@ -1,11 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Response\Cancel; - -use WPDesk\SaasPlatformClient\Response\ApiResponse; -use WPDesk\SaasPlatformClient\Response\Traits\AuthApiResponseDecorator; - -class PostCancelResponse implements ApiResponse -{ - use AuthApiResponseDecorator; -} diff --git a/src/Response/Exception/EmptyMessageFromResponse.php b/src/Response/Exception/EmptyMessageFromResponse.php deleted file mode 100644 index 870a00cbf47c12699b699ffb4843c5ebcf4b6d96..0000000000000000000000000000000000000000 --- a/src/Response/Exception/EmptyMessageFromResponse.php +++ /dev/null @@ -1,19 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Response\Exception; - -class EmptyMessageFromResponse extends \RuntimeException -{ - /** - * Exception factory - * - * @param string $request - * @param int $errorCode - * @return TriedExtractDataFromErrorResponse - */ - public static function createWithClassInfo($request, $errorCode) - { - return new EmptyStatusFromResponse("Tried to extract message from {$request} when an error occured. Response code: {$errorCode}", - $errorCode); - } -} \ No newline at end of file diff --git a/src/Response/Exception/EmptyStatusFromResponse.php b/src/Response/Exception/EmptyStatusFromResponse.php deleted file mode 100644 index a077eca3145a4239826cac9c444fa423f2e3af4b..0000000000000000000000000000000000000000 --- a/src/Response/Exception/EmptyStatusFromResponse.php +++ /dev/null @@ -1,19 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Response\Exception; - -class EmptyStatusFromResponse extends \RuntimeException -{ - /** - * Exception factory - * - * @param string $request - * @param int $errorCode - * @return TriedExtractDataFromErrorResponse - */ - public static function createWithClassInfo($request, $errorCode) - { - return new EmptyStatusFromResponse("Tried to extract status from {$request} when an error occured. Response code: {$errorCode}", - $errorCode); - } -} \ No newline at end of file diff --git a/src/Response/Exception/TriedExtractDataFromErrorResponse.php b/src/Response/Exception/TriedExtractDataFromErrorResponse.php deleted file mode 100644 index 38d21ffd6ebdd81e72907e9cc3dd0aaf2bbb6405..0000000000000000000000000000000000000000 --- a/src/Response/Exception/TriedExtractDataFromErrorResponse.php +++ /dev/null @@ -1,19 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Response\Exception; - -class TriedExtractDataFromErrorResponse extends \RuntimeException -{ - /** - * Exception factory - * - * @param string $request - * @param int $errorCode - * @return TriedExtractDataFromErrorResponse - */ - public static function createWithClassInfo($request, $errorCode) - { - return new TriedExtractDataFromErrorResponse("Tried to extract data from {$request} when an error occured. Response code: {$errorCode}", - $errorCode); - } -} \ No newline at end of file diff --git a/src/Response/Fields/GetFieldsResponse.php b/src/Response/Fields/GetFieldsResponse.php deleted file mode 100644 index 710e5e68297bed31b98bcf88bfdfaf86ec47c43e..0000000000000000000000000000000000000000 --- a/src/Response/Fields/GetFieldsResponse.php +++ /dev/null @@ -1,19 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Response\Fields; - -use WPDesk\SaasPlatformClient\Response\ApiResponse; -use WPDesk\SaasPlatformClient\Response\Traits\AuthApiResponseDecorator; - -class GetFieldsResponse implements ApiResponse -{ - use AuthApiResponseDecorator; - - /** - * @return array - */ - public function getFields() - { - return $this->getResponseBody()['fieldsJson']; - } -} diff --git a/src/Response/Label/PostLabelResponse.php b/src/Response/Label/PostLabelResponse.php deleted file mode 100644 index 83f598553766ade50ef95a56079463f1dbb01e8b..0000000000000000000000000000000000000000 --- a/src/Response/Label/PostLabelResponse.php +++ /dev/null @@ -1,20 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Response\Label; - -use WPDesk\SaasPlatformClient\Model\Label\Label; -use WPDesk\SaasPlatformClient\Response\ApiResponse; -use WPDesk\SaasPlatformClient\Response\Traits\AuthApiResponseDecorator; - -class PostLabelResponse implements ApiResponse -{ - use AuthApiResponseDecorator; - - /** - * @return Label - */ - public function getLabel() - { - return new Label($this->getResponseBody()); - } -} diff --git a/src/Response/Maintenance/MaintenanceResponseContext.php b/src/Response/Maintenance/MaintenanceResponseContext.php deleted file mode 100644 index fa0a0661be3f807d04a6c23acb9606fcf108d1cc..0000000000000000000000000000000000000000 --- a/src/Response/Maintenance/MaintenanceResponseContext.php +++ /dev/null @@ -1,50 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Response\Maintenance; - -use WPDesk\SaasPlatformClient\Response\Response; - -class MaintenanceResponseContext -{ - - /** - * Response. - * - * @var Response - */ - private $response; - - public function __construct(Response $response) - { - $this->response = $response; - } - - /** - * Get maintenance message. - * - * @return string|null - */ - public function getMaintenanceMessage() - { - $responseBody = $this->response->getResponseBody(); - if (isset($responseBody['message'])) { - return $responseBody['message']; - } - return null; - } - - /** - * Get maintenance till. - * - * @return int|null - */ - public function getMaintenanceTill() - { - $responseBody = $this->response->getResponseBody(); - if (isset($responseBody['maintenance_till'])) { - return intval($responseBody['maintenance_till']); - } - return null; - } - -} \ No newline at end of file diff --git a/src/Response/ProtectedResponse.php b/src/Response/ProtectedResponse.php index 363fde03ebe500ef094bd7fbafec10c3b8ae85e9..c5195d0a4c45d59d592483ce12c15fabbb43ea1e 100644 --- a/src/Response/ProtectedResponse.php +++ b/src/Response/ProtectedResponse.php @@ -1,15 +1,15 @@ <?php -namespace WPDesk\SaasPlatformClient\Response; +namespace WPDesk\ApiClient\Response; -use WPDesk\SaasPlatformClient\Response\Exception\TriedExtractDataFromErrorResponse; -use WPDesk\SaasPlatformClient\Response\Traits\ApiResponseDecorator; +use WPDesk\ApiClient\Response\Exception\TriedExtractDataFromErrorResponse; +use WPDesk\ApiClient\Response\Traits\ApiResponseDecorator; /** * Response is protected in a way so when you try to get body of the response when an error occured you will get an exception * * Class ProtectedResponse - * @package WPDesk\SaasPlatformClient\Response + * @package WPDesk\ApiClient\Response */ class ProtectedResponse implements Response { diff --git a/src/Response/Rate/PostRateResponse.php b/src/Response/Rate/PostRateResponse.php deleted file mode 100644 index 8f53e7e3a0389343f48f404195de193a5dc20dc8..0000000000000000000000000000000000000000 --- a/src/Response/Rate/PostRateResponse.php +++ /dev/null @@ -1,31 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Response\Rate; - -use WPDesk\SaasPlatformClient\Model\Rate\RateResponse; -use WPDesk\SaasPlatformClient\Response\ApiResponse; -use WPDesk\SaasPlatformClient\Response\Traits\AuthApiResponseDecorator; - -class PostRateResponse implements ApiResponse -{ - use AuthApiResponseDecorator; - - const RESPONSE_CODE_RATE_FAILED = 274; - - /** - * @return RateResponse - */ - public function getRate() - { - return new RateResponse($this->getResponseBody()); - } - - /** - * Platform can't respond in meaningful way about rates - * - * @return bool - */ - public function isRateFailedError() { - return $this->rawResponse->getResponseCode() === self::RESPONSE_CODE_RATE_FAILED; - } -} diff --git a/src/Response/RawResponse.php b/src/Response/RawResponse.php index 6360d2e2d8a7efb7617ddce3ce2e7b84395c1dd1..3662483b47731dffc49f66e3a273e34aac6f38ae 100644 --- a/src/Response/RawResponse.php +++ b/src/Response/RawResponse.php @@ -1,6 +1,6 @@ <?php -namespace WPDesk\SaasPlatformClient\Response; +namespace WPDesk\ApiClient\Response; class RawResponse implements Response { diff --git a/src/Response/Response.php b/src/Response/Response.php index 245bfc4158f5021b67cdd6bd572ae6b62ab0cd5e..296b6fdf29635a86bb95bacb769a826f939f3437 100644 --- a/src/Response/Response.php +++ b/src/Response/Response.php @@ -1,6 +1,6 @@ <?php -namespace WPDesk\SaasPlatformClient\Response; +namespace WPDesk\ApiClient\Response; interface Response diff --git a/src/Response/Shipment/GetListShipmentAdminContextResponse.php b/src/Response/Shipment/GetListShipmentAdminContextResponse.php deleted file mode 100644 index 3aa1bd03fbaaeefc73e7e1830ad85a165ec4e3ea..0000000000000000000000000000000000000000 --- a/src/Response/Shipment/GetListShipmentAdminContextResponse.php +++ /dev/null @@ -1,29 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Response\Shipment; - -use WPDesk\SaasPlatformClient\Model\Shipment\ShipmentAdminContext; -use WPDesk\SaasPlatformClient\Response\ApiResponse; -use WPDesk\SaasPlatformClient\Response\Traits\AuthApiResponseDecorator; -use WPDesk\SaasPlatformClient\Response\Traits\PagedListImplementation; - -class GetListShipmentAdminContextResponse implements ApiResponse -{ - use AuthApiResponseDecorator; - use PagedListImplementation; - - /* - * @return ShippingService[] - */ - public function getPage() - { - $page = $this->getRawPage(); - $itemList = []; - if (count($page) > 0) { - foreach ($page as $item) { - $itemList[] = new ShipmentAdminContext($item); - } - } - return $itemList; - } -} \ No newline at end of file diff --git a/src/Response/Shipment/PostShipmentResponse.php b/src/Response/Shipment/PostShipmentResponse.php deleted file mode 100644 index 1153fff015538a8aec6958040dc74a03ec6191e2..0000000000000000000000000000000000000000 --- a/src/Response/Shipment/PostShipmentResponse.php +++ /dev/null @@ -1,30 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Response\Shipment; - -use WPDesk\SaasPlatformClient\Model\Shipment\ShipmentResponse; -use WPDesk\SaasPlatformClient\Response\ApiResponse; -use WPDesk\SaasPlatformClient\Response\Traits\AuthApiResponseDecorator; - -class PostShipmentResponse implements ApiResponse -{ - use AuthApiResponseDecorator; - - const RESPONSE_CODE_SHIPMENT_PLAN_EXCEEDED = 472; - - /** - * @return bool - */ - public function isShipmentPlanExceeded() - { - return $this->getResponseCode() === self::RESPONSE_CODE_SHIPMENT_PLAN_EXCEEDED; - } - - /** - * @return ShipmentResponse - */ - public function getShipment() - { - return new ShipmentResponse($this->getResponseBody()); - } -} diff --git a/src/Response/ShippingServices/GetShippingServiceResponse.php b/src/Response/ShippingServices/GetShippingServiceResponse.php deleted file mode 100644 index 3ea05c4b2a66966d19e2514f649c05b499b02e7a..0000000000000000000000000000000000000000 --- a/src/Response/ShippingServices/GetShippingServiceResponse.php +++ /dev/null @@ -1,20 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Response\ShippingServices; - -use WPDesk\SaasPlatformClient\Model\ShippingService; -use WPDesk\SaasPlatformClient\Response\ApiResponse; -use WPDesk\SaasPlatformClient\Response\Traits\AuthApiResponseDecorator; - -final class GetShippingServiceResponse implements ApiResponse -{ - use AuthApiResponseDecorator; - - /** - * @return ShippingService - */ - public function getShippingService() - { - return new ShippingService($this->getResponseBody()); - } -} \ No newline at end of file diff --git a/src/Response/ShippingServices/GetShippingServicesListResponse.php b/src/Response/ShippingServices/GetShippingServicesListResponse.php deleted file mode 100644 index fc89bbfee1f9c131c629786817dd39745ae723f2..0000000000000000000000000000000000000000 --- a/src/Response/ShippingServices/GetShippingServicesListResponse.php +++ /dev/null @@ -1,30 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Response\ShippingServices; - -use WPDesk\SaasPlatformClient\Model\ShippingService; -use WPDesk\SaasPlatformClient\Response\ApiResponse; -use WPDesk\SaasPlatformClient\Response\Traits\AuthApiResponseDecorator; -use WPDesk\SaasPlatformClient\Response\Traits\PagedListImplementation; - -final class GetShippingServicesListResponse implements ApiResponse -{ - use AuthApiResponseDecorator; - use PagedListImplementation; - - /* - * @return ShippingService[] - */ - public function getPage() - { - $page = $this->getRawPage(); - $itemList = []; - if (count($page) > 0) { - foreach ($page as $item) { - $itemList[] = new ShippingService($item); - } - } - return $itemList; - } - -} \ No newline at end of file diff --git a/src/Response/ShippingServicesSettings/GetSettingsResponse.php b/src/Response/ShippingServicesSettings/GetSettingsResponse.php deleted file mode 100644 index 1ab9835a8e986b37af124ee866f623f52ba72196..0000000000000000000000000000000000000000 --- a/src/Response/ShippingServicesSettings/GetSettingsResponse.php +++ /dev/null @@ -1,32 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Response\ShippingServicesSettings; - -use WPDesk\SaasPlatformClient\Model\ShippingServiceSetting; -use WPDesk\SaasPlatformClient\Response\ApiResponse; -use WPDesk\SaasPlatformClient\Response\Traits\AuthApiResponseDecorator; - -class GetSettingsResponse implements ApiResponse -{ - use AuthApiResponseDecorator; - - /** - * @param array $data - * @return array - */ - private function convertHalReferencesToJson(array $data) - { - foreach ($data['_links'] as $key => $item) { - $data[$key] = $item['href']; - } - return $data; - } - - /** - * @return ShippingServiceSetting - */ - public function getSetting() - { - return new ShippingServiceSetting($this->convertHalReferencesToJson($this->getResponseBody())); - } -} diff --git a/src/Response/ShippingServicesSettings/Test/GetSettingsTestResponse.php b/src/Response/ShippingServicesSettings/Test/GetSettingsTestResponse.php deleted file mode 100644 index ec791b2b3b78bca5b414973dfa56c9d950949174..0000000000000000000000000000000000000000 --- a/src/Response/ShippingServicesSettings/Test/GetSettingsTestResponse.php +++ /dev/null @@ -1,36 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Response\ShippingServicesSettings\Test; - -use WPDesk\SaasPlatformClient\Response\ApiResponse; -use WPDesk\SaasPlatformClient\Response\Exception\EmptyStatusFromResponse; -use WPDesk\SaasPlatformClient\Response\Traits\AuthApiResponseDecorator; - -class GetSettingsTestResponse implements ApiResponse -{ - use AuthApiResponseDecorator; - - const MESSAGE = 'message'; - const STATUS = 'status'; - - public function getMessage() - { - $responseBody = $this->getResponseBody(); - if (isset($responseBody[self::MESSAGE])) { - return $responseBody[self::MESSAGE]; - } else { - throw EmptyMessageFromResponse::createWithClassInfo(get_class($this->rawResponse), $this->getResponseCode()); - } - } - - public function getStatus() - { - $responseBody = $this->getResponseBody(); - if (isset($responseBody[self::STATUS])) { - return $responseBody[self::STATUS]; - } else { - throw EmptyStatusFromResponse::createWithClassInfo(get_class($this->rawResponse), $this->getResponseCode()); - } - } - -} diff --git a/src/Response/Status/GetStatusResponse.php b/src/Response/Status/GetStatusResponse.php deleted file mode 100644 index 222902c5de693722f8767acfb1b16fdb7512584b..0000000000000000000000000000000000000000 --- a/src/Response/Status/GetStatusResponse.php +++ /dev/null @@ -1,20 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Response\Status; - -use WPDesk\SaasPlatformClient\Model\Status; -use WPDesk\SaasPlatformClient\Response\ApiResponse; -use WPDesk\SaasPlatformClient\Response\Traits\AuthApiResponseDecorator; - -class GetStatusResponse implements ApiResponse -{ - use AuthApiResponseDecorator; - - /** - * @return Status - */ - public function getStatus() - { - return new Status($this->getResponseBody()); - } -} diff --git a/src/Response/Traits/ApiResponseDecorator.php b/src/Response/Traits/ApiResponseDecorator.php deleted file mode 100644 index e02c35f6d0a45c0ab406b45111fbf8cd3ce1c0b4..0000000000000000000000000000000000000000 --- a/src/Response/Traits/ApiResponseDecorator.php +++ /dev/null @@ -1,145 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Response\Traits; - -use WPDesk\SaasPlatformClient\Response\AuthApiResponse; -use WPDesk\SaasPlatformClient\Response\RawResponse; -use WPDesk\SaasPlatformClient\Response\Response; - -trait ApiResponseDecorator -{ - - /** @var RawResponse */ - private $rawResponse; - - /** - * RawResponseDecorator constructor. - * @param Response $rawResponse - */ - public function __construct(Response $rawResponse) - { - $this->rawResponse = $rawResponse; - } - - /** - * Returns response http code - * - * @return int - */ - public function getResponseCode() - { - return $this->rawResponse->getResponseCode(); - } - - /** - * Returns response body as array - * - * @return array - */ - public function getResponseBody() - { - return $this->rawResponse->getResponseBody(); - } - - /** - * Returns response body as array - * - * @return array - */ - public function getResponseErrorBody() - { - return $this->rawResponse->getResponseErrorBody(); - } - - /** - * Returns response body as array - * - * @return array - */ - public function getResponseHeaders() - { - return $this->rawResponse->getResponseHeaders(); - } - - /** - * Get links structure to the other request - * - * @return array - */ - public function getLinks() - { - $body = $this->getResponseBody(); - return $body['_links']; - } - - /** - * Is it a BAD REQUEST response - * - * @return bool - */ - public function isBadRequest() - { - return $this->getResponseCode() === RawResponse::RESPONSE_CODE_ERROR_BAD_REQUEST; - } - - /** - * Is it a DOMAIN NOT ALLOWED response - * - * @return bool - */ - public function isDomainNotAllowed() - { - return $this->getResponseCode() === RawResponse::RESPONSE_CODE_DOMAIN_NOT_ALLOWED; - } - - /** - * Is it a FATAL ERROR response - * - * @return bool - */ - public function isServerFatalError() - { - return $this->getResponseCode() === RawResponse::RESPONSE_CODE_ERROR_FATAL; - } - - /** - * Is any error occured - * - * @return bool - */ - public function isError() - { - return $this->rawResponse->isError(); - } - - /** - * Is requested resource exists - * - * @return bool - */ - public function isNotExists() - { - return $this->getResponseCode() === AuthApiResponse::RESPONSE_CODE_NOT_EXISTS; - } - - /** - * Is maintenance. - * - * @return bool - */ - public function isMaintenance() - { - return $this->rawResponse->isMaintenance(); - } - - /** - * Get platform version hash string. - * - * @return bool|string - */ - public function getPlatformVersionHash() - { - return $this->rawResponse->getPlatformVersionHash(); - } - - } \ No newline at end of file diff --git a/src/Response/Traits/AuthApiResponseDecorator.php b/src/Response/Traits/AuthApiResponseDecorator.php deleted file mode 100644 index 5e45ff83a0e82a5da50eb7a0ce9e59c09434e3b8..0000000000000000000000000000000000000000 --- a/src/Response/Traits/AuthApiResponseDecorator.php +++ /dev/null @@ -1,38 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Response\Traits; - -use WPDesk\SaasPlatformClient\Response\AuthApiResponse; - -trait AuthApiResponseDecorator -{ - use ApiResponseDecorator; - - /** - * @return bool - */ - public function isBadCredentials() - { - return $this->getResponseCode() === AuthApiResponse::RESPONSE_CODE_BAD_CREDENTIALS; - } - - /** - * Is bad credential because token expires - * - * @return bool - */ - public function isTokenExpired() - { - return $this->isBadCredentials(); - } - - /** - * Is bad credential because token is invalid - * - * @return bool - */ - public function isTokenInvalid() - { - return $this->isBadCredentials(); - } -} \ No newline at end of file diff --git a/src/Response/Traits/PagedListImplementation.php b/src/Response/Traits/PagedListImplementation.php deleted file mode 100644 index f364978edbec7f04ce436aef19d2eb399e5722e2..0000000000000000000000000000000000000000 --- a/src/Response/Traits/PagedListImplementation.php +++ /dev/null @@ -1,44 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Response\Traits; - -trait PagedListImplementation -{ - /* - * @return array - */ - public function getRawPage() - { - $body = $this->getResponseBody(); - if ($body['_embedded'] !== null && $body['_embedded']['item'] !== null) { - return $body['_embedded']['item']; - } - return []; - } - - /** - * @return int - */ - public function getPageCount() - { - return (int)floor($this->getItemCount() / $this->getItemsPerPage()); - } - - /** - * @return int - */ - public function getItemsPerPage() - { - $body = $this->getResponseBody(); - return (int)$body['itemsPerPage']; - } - - /** - * @return int - */ - public function getItemCount() - { - $body = $this->getResponseBody(); - return (int)$body['totalItems']; - } -} \ No newline at end of file diff --git a/src/Response/Users/GetUserResponse.php b/src/Response/Users/GetUserResponse.php deleted file mode 100644 index 199a51734513136489edd0e7aceb0b116e977655..0000000000000000000000000000000000000000 --- a/src/Response/Users/GetUserResponse.php +++ /dev/null @@ -1,20 +0,0 @@ -<?php - -namespace WPDesk\SaasPlatformClient\Response\Users; - -use WPDesk\SaasPlatformClient\Model\User; -use WPDesk\SaasPlatformClient\Response\Response; -use WPDesk\SaasPlatformClient\Response\Traits\AuthApiResponseDecorator; - -final class GetUserResponse implements Response -{ - use AuthApiResponseDecorator; - - /** - * @return User - */ - public function getUser() - { - return new User($this->getResponseBody()); - } -} \ No newline at end of file