From b5ccf9d6c6a51cdfe2df5ca802b70e5732ee1075 Mon Sep 17 00:00:00 2001 From: Grzegorz Rola <grola@seostudio.pl> Date: Thu, 31 Jan 2019 16:23:03 +0100 Subject: [PATCH] Init --- composer.json | 1 + src/{ApiClient => Client}/CachedClient.php | 16 +- src/{ApiClient => Client}/Client.php | 10 +- src/{ApiClient => Client}/ClientFactory.php | 10 +- .../ClientImplementation.php | 6 +- .../RequestCacheInfoResolver.php | 0 src/Request/AuthRequest.php | 53 ------- .../Authentication/ConnectKeyInfoRequest.php | 28 ---- .../Authentication/ConnectKeyResetRequest.php | 23 --- .../Authentication/RegisterRequest.php | 29 ---- src/Request/Authentication/TokenRequest.php | 26 ---- src/Request/BasicRequest.php | 2 +- src/Request/Cancel/PostCancelRequest.php | 39 ----- src/Request/Fields/GetFieldsRequest.php | 45 ------ src/Request/Label/PostLabelRequest.php | 36 ----- src/Request/Rate/PostRateRequest.php | 36 ----- src/Request/Request.php | 2 +- .../Shipment/GetUserListShipmentRequest.php | 27 ---- src/Request/Shipment/PostShipmentRequest.php | 36 ----- .../ShippingPlan/PutShippingPlanRequest.php | 30 ---- .../ShippingServices/GetListRequest.php | 14 -- .../ShippingServices/GetServiceRequest.php | 29 ---- .../GetSettingsRequest.php | 38 ----- .../PostSettingsRequest.php | 30 ---- .../PutSettingsRequest.php | 36 ----- .../Test/GetSettingsTestRequest.php | 37 ----- src/Request/Status/GetStatusRequest.php | 49 ------ .../Traits/SettingsItemRequestHelper.php | 28 ---- src/Request/Users/GetUserRequest.php | 28 ---- src/Response/ApiResponse.php | 2 +- src/Response/AuthApiResponse.php | 14 -- .../Authentication/ConnectKeyInfoResponse.php | 37 ----- .../ConnectKeyResetResponse.php | 22 --- .../Authentication/RegisterResponse.php | 59 ------- src/Response/Authentication/TokenResponse.php | 56 ------- src/Response/Cancel/PostCancelResponse.php | 11 -- .../Exception/EmptyMessageFromResponse.php | 19 --- .../Exception/EmptyStatusFromResponse.php | 19 --- .../TriedExtractDataFromErrorResponse.php | 19 --- src/Response/Fields/GetFieldsResponse.php | 19 --- src/Response/Label/PostLabelResponse.php | 20 --- .../MaintenanceResponseContext.php | 50 ------ src/Response/ProtectedResponse.php | 8 +- src/Response/Rate/PostRateResponse.php | 31 ---- src/Response/RawResponse.php | 2 +- src/Response/Response.php | 2 +- .../GetListShipmentAdminContextResponse.php | 29 ---- .../Shipment/PostShipmentResponse.php | 30 ---- .../GetShippingServiceResponse.php | 20 --- .../GetShippingServicesListResponse.php | 30 ---- .../GetSettingsResponse.php | 32 ---- .../Test/GetSettingsTestResponse.php | 36 ----- src/Response/Status/GetStatusResponse.php | 20 --- src/Response/Traits/ApiResponseDecorator.php | 145 ------------------ .../Traits/AuthApiResponseDecorator.php | 38 ----- .../Traits/PagedListImplementation.php | 44 ------ src/Response/Users/GetUserResponse.php | 20 --- 57 files changed, 31 insertions(+), 1547 deletions(-) rename src/{ApiClient => Client}/CachedClient.php (83%) rename src/{ApiClient => Client}/Client.php (70%) rename src/{ApiClient => Client}/ClientFactory.php (73%) rename src/{ApiClient => Client}/ClientImplementation.php (97%) rename src/{ApiClient => Client}/RequestCacheInfoResolver.php (100%) delete mode 100644 src/Request/AuthRequest.php delete mode 100644 src/Request/Authentication/ConnectKeyInfoRequest.php delete mode 100644 src/Request/Authentication/ConnectKeyResetRequest.php delete mode 100644 src/Request/Authentication/RegisterRequest.php delete mode 100644 src/Request/Authentication/TokenRequest.php delete mode 100644 src/Request/Cancel/PostCancelRequest.php delete mode 100644 src/Request/Fields/GetFieldsRequest.php delete mode 100644 src/Request/Label/PostLabelRequest.php delete mode 100644 src/Request/Rate/PostRateRequest.php delete mode 100644 src/Request/Shipment/GetUserListShipmentRequest.php delete mode 100644 src/Request/Shipment/PostShipmentRequest.php delete mode 100644 src/Request/ShippingPlan/PutShippingPlanRequest.php delete mode 100644 src/Request/ShippingServices/GetListRequest.php delete mode 100644 src/Request/ShippingServices/GetServiceRequest.php delete mode 100644 src/Request/ShippingServicesSettings/GetSettingsRequest.php delete mode 100644 src/Request/ShippingServicesSettings/PostSettingsRequest.php delete mode 100644 src/Request/ShippingServicesSettings/PutSettingsRequest.php delete mode 100644 src/Request/ShippingServicesSettings/Test/GetSettingsTestRequest.php delete mode 100644 src/Request/Status/GetStatusRequest.php delete mode 100644 src/Request/Traits/SettingsItemRequestHelper.php delete mode 100644 src/Request/Users/GetUserRequest.php delete mode 100644 src/Response/AuthApiResponse.php delete mode 100644 src/Response/Authentication/ConnectKeyInfoResponse.php delete mode 100644 src/Response/Authentication/ConnectKeyResetResponse.php delete mode 100644 src/Response/Authentication/RegisterResponse.php delete mode 100644 src/Response/Authentication/TokenResponse.php delete mode 100644 src/Response/Cancel/PostCancelResponse.php delete mode 100644 src/Response/Exception/EmptyMessageFromResponse.php delete mode 100644 src/Response/Exception/EmptyStatusFromResponse.php delete mode 100644 src/Response/Exception/TriedExtractDataFromErrorResponse.php delete mode 100644 src/Response/Fields/GetFieldsResponse.php delete mode 100644 src/Response/Label/PostLabelResponse.php delete mode 100644 src/Response/Maintenance/MaintenanceResponseContext.php delete mode 100644 src/Response/Rate/PostRateResponse.php delete mode 100644 src/Response/Shipment/GetListShipmentAdminContextResponse.php delete mode 100644 src/Response/Shipment/PostShipmentResponse.php delete mode 100644 src/Response/ShippingServices/GetShippingServiceResponse.php delete mode 100644 src/Response/ShippingServices/GetShippingServicesListResponse.php delete mode 100644 src/Response/ShippingServicesSettings/GetSettingsResponse.php delete mode 100644 src/Response/ShippingServicesSettings/Test/GetSettingsTestResponse.php delete mode 100644 src/Response/Status/GetStatusResponse.php delete mode 100644 src/Response/Traits/ApiResponseDecorator.php delete mode 100644 src/Response/Traits/AuthApiResponseDecorator.php delete mode 100644 src/Response/Traits/PagedListImplementation.php delete mode 100644 src/Response/Users/GetUserResponse.php diff --git a/composer.json b/composer.json index 6980cec..fc3057c 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 a7f512c..7d23f34 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 993f5ca..e63e184 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 a5b45e6..b92f459 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 6153d4c..02e9c52 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 3415812..0000000 --- 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 fe611c6..0000000 --- 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 0c2cd8c..0000000 --- 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 3a231d6..0000000 --- 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 289011b..0000000 --- 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 c185d1e..ae0f599 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 a780ee2..0000000 --- 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 2e5b881..0000000 --- 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 e34dcd7..0000000 --- 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 5352104..0000000 --- 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 2810176..4789c80 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 176c4ba..0000000 --- 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 0913827..0000000 --- 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 010e09d..0000000 --- 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 e23bba6..0000000 --- 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 91785ab..0000000 --- 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 9040b31..0000000 --- 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 20e9af3..0000000 --- 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 ea60793..0000000 --- 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 45009ad..0000000 --- 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 59b9a17..0000000 --- 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 9b97fad..0000000 --- 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 62b0c7a..0000000 --- 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 486e321..b782720 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 05fee14..0000000 --- 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 d89aba8..0000000 --- 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 4f78a30..0000000 --- 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 046a70f..0000000 --- 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 e7a7247..0000000 --- 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 091c610..0000000 --- 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 870a00c..0000000 --- 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 a077eca..0000000 --- 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 38d21ff..0000000 --- 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 710e5e6..0000000 --- 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 83f5985..0000000 --- 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 fa0a066..0000000 --- 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 363fde0..c5195d0 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 8f53e7e..0000000 --- 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 6360d2e..3662483 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 245bfc4..296b6fd 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 3aa1bd0..0000000 --- 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 1153fff..0000000 --- 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 3ea05c4..0000000 --- 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 fc89bbf..0000000 --- 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 1ab9835..0000000 --- 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 ec791b2..0000000 --- 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 222902c..0000000 --- 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 e02c35f..0000000 --- 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 5e45ff8..0000000 --- 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 f364978..0000000 --- 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 199a517..0000000 --- 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 -- GitLab