Skip to content
Snippets Groups Projects
Commit b5ccf9d6 authored by Grzegorz Rola's avatar Grzegorz Rola
Browse files

Init

parent fa89f75a
No related branches found
No related tags found
1 merge request!1Feature/first release
Pipeline #4710 passed
This commit is part of merge request !1. Comments created here will be created in the context of that merge request.
Showing
with 24 additions and 431 deletions
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
"require": { "require": {
"php": ">=5.5", "php": ">=5.5",
"psr/log": "^1.0.1", "psr/log": "^1.0.1",
"wpdesk/wp-cache": "dev-master",
"wpdesk/wp-http-client": "dev-master", "wpdesk/wp-http-client": "dev-master",
"psr/simple-cache": "^1.0" "psr/simple-cache": "^1.0"
}, },
......
<?php <?php
namespace WPDesk\SaasPlatformClient\ApiClient; namespace WPDesk\ApiClient\ApiClient;
use Psr\SimpleCache\CacheInterface; use Psr\SimpleCache\CacheInterface;
use WPDesk\SaasPlatformClient\Cache\CacheDispatcher; use WPDesk\ApiClient\Cache\CacheDispatcher;
use WPDesk\SaasPlatformClient\Cache\CacheItemCreator; use WPDesk\ApiClient\Cache\CacheItemCreator;
use WPDesk\SaasPlatformClient\Cache\CacheItemVerifier; use WPDesk\ApiClient\Cache\CacheItemVerifier;
use WPDesk\SaasPlatformClient\HttpClient\HttpClient; use WPDesk\ApiClient\HttpClient\HttpClient;
use WPDesk\SaasPlatformClient\Request\Request; use WPDesk\ApiClient\Request\Request;
use WPDesk\SaasPlatformClient\Response\Response; use WPDesk\ApiClient\Response\Response;
use WPDesk\SaasPlatformClient\Serializer\Serializer; use WPDesk\ApiClient\Serializer\Serializer;
class CachedClient implements Client, CacheItemCreator, CacheItemVerifier class CachedClient implements Client, CacheItemCreator, CacheItemVerifier
{ {
......
<?php <?php
namespace WPDesk\SaasPlatformClient\ApiClient; namespace WPDesk\ApiClient\ApiClient;
use WPDesk\SaasPlatformClient\HttpClient\HttpClient; use WPDesk\ApiClient\HttpClient\HttpClient;
use WPDesk\SaasPlatformClient\Request\Request; use WPDesk\ApiClient\Request\Request;
use WPDesk\SaasPlatformClient\Response\Response; use WPDesk\ApiClient\Response\Response;
use WPDesk\SaasPlatformClient\Serializer\Serializer; use WPDesk\ApiClient\Serializer\Serializer;
interface Client interface Client
{ {
......
<?php <?php
namespace WPDesk\SaasPlatformClient\ApiClient; namespace WPDesk\ApiClient\ApiClient;
use WPDesk\SaasPlatformClient\Cache\WordpressCache; use WPDesk\ApiClient\Cache\WordpressCache;
use WPDesk\SaasPlatformClient\HttpClient\HttpClientFactory; use WPDesk\ApiClient\HttpClient\HttpClientFactory;
use WPDesk\SaasPlatformClient\PlatformFactoryOptions; use WPDesk\ApiClient\PlatformFactoryOptions;
use WPDesk\SaasPlatformClient\Serializer\SerializerFactory; use WPDesk\ApiClient\Serializer\SerializerFactory;
class ClientFactory class ClientFactory
{ {
......
<?php <?php
namespace WPDesk\SaasPlatformClient\ApiClient; namespace WPDesk\ApiClient\ApiClient;
use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use WPDesk\SaasPlatformClient\HttpClient\HttpClient; use WPDesk\HttpClient\HttpClient;
use WPDesk\SaasPlatformClient\HttpClient\HttpClientResponse; use WPDesk\HttpClient\HttpClientResponse;
use WPDesk\SaasPlatformClient\Platform; use WPDesk\SaasPlatformClient\Platform;
use WPDesk\SaasPlatformClient\Request\Request; use WPDesk\SaasPlatformClient\Request\Request;
use WPDesk\SaasPlatformClient\Response\RawResponse; use WPDesk\SaasPlatformClient\Response\RawResponse;
......
<?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
<?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
<?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
<?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
<?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
<?php <?php
namespace WPDesk\SaasPlatformClient\Request; namespace WPDesk\ApiClient\Request;
class BasicRequest implements Request class BasicRequest implements Request
......
<?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
<?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
<?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
<?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
<?php <?php
namespace WPDesk\SaasPlatformClient\Request; namespace WPDesk\ApiClient\Request;
interface Request interface Request
......
<?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
<?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
<?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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment