mirror of
https://github.com/opdavies/glassboxx-sdk-php.git
synced 2025-01-22 12:07:32 +00:00
Refactor, add traits
This commit is contained in:
parent
506b5689fe
commit
0426632a08
|
@ -5,28 +5,21 @@ declare(strict_types=1);
|
|||
namespace Opdavies\Glassboxx\Request;
|
||||
|
||||
use Opdavies\Glassboxx\Config;
|
||||
use Opdavies\Glassboxx\Traits\UsesConfigTrait;
|
||||
use Symfony\Component\HttpClient\HttpClient;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
abstract class AbstractRequest
|
||||
{
|
||||
use UsesConfigTrait;
|
||||
|
||||
public const BASE_URL = 'https://server.glassboxx.co.uk/rest/V1';
|
||||
|
||||
/** @var HttpClient */
|
||||
protected $client;
|
||||
|
||||
/** @var Config */
|
||||
protected $config;
|
||||
|
||||
public function __construct(HttpClientInterface $client)
|
||||
{
|
||||
$this->client = $client;
|
||||
}
|
||||
|
||||
public function withConfig(Config $config): AbstractRequest
|
||||
{
|
||||
$this->config = $config;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,10 +4,13 @@ declare(strict_types=1);
|
|||
|
||||
namespace Opdavies\Glassboxx\Request;
|
||||
|
||||
use Opdavies\Glassboxx\Traits\UsesAuthTokenTrait;
|
||||
use Opdavies\Glassboxx\ValueObject\CustomerInterface;
|
||||
|
||||
final class CustomerRequest extends AbstractRequest
|
||||
{
|
||||
use UsesAuthTokenTrait;
|
||||
|
||||
public const ENDPOINT = '/glassboxxorder/customCustomer';
|
||||
|
||||
/** @var string */
|
||||
|
@ -23,13 +26,6 @@ final class CustomerRequest extends AbstractRequest
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function withAuthToken(string $authToken): self
|
||||
{
|
||||
$this->authToken = $authToken;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(): string
|
||||
{
|
||||
$body = [
|
||||
|
|
15
src/Glassboxx/Traits/UsesAuthTokenTrait.php
Normal file
15
src/Glassboxx/Traits/UsesAuthTokenTrait.php
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Opdavies\Glassboxx\Traits;
|
||||
|
||||
trait UsesAuthTokenTrait
|
||||
{
|
||||
public function withAuthToken(string $authToken): self
|
||||
{
|
||||
$this->authToken = $authToken;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
20
src/Glassboxx/Traits/UsesConfigTrait.php
Normal file
20
src/Glassboxx/Traits/UsesConfigTrait.php
Normal file
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Opdavies\Glassboxx\Traits;
|
||||
|
||||
use Opdavies\Glassboxx\Config;
|
||||
|
||||
trait UsesConfigTrait
|
||||
{
|
||||
/** @var Config */
|
||||
protected $config;
|
||||
|
||||
public function withConfig(Config $config): self
|
||||
{
|
||||
$this->config = $config;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue