Make the Client parameter optional for requests

Make the Client parameter optional when creating auth token, customer or
order requests, and create a new Client instance within the abstract
request if one isn't passed in.
This commit is contained in:
Oliver Davies 2020-06-05 20:59:12 +01:00
parent 532dfd43a1
commit 2ba89e1c6a
10 changed files with 15 additions and 14 deletions

View file

@ -13,13 +13,17 @@ abstract class AbstractRequest
{
use UsesConfigTrait;
public const BASE_URL = 'https://server.glassboxx.co.uk/rest/V1';
public const BASE_URL = 'https://server.glassboxx.co.uk';
/** @var HttpClient */
protected $client;
public function __construct(HttpClientInterface $client)
public function __construct(HttpClientInterface $client = null)
{
if (!$client) {
$client = HttpClient::createForBaseUri(self::BASE_URL);
}
$this->client = $client;
}
}

View file

@ -10,7 +10,7 @@ final class AuthTokenRequest extends AbstractRequest implements AuthTokenRequest
{
$response = $this->client->request(
'POST',
self::BASE_URL.self::ENDPOINT,
self::ENDPOINT,
[
'query' => [
'password' => $this->config->getPassword(),

View file

@ -6,7 +6,7 @@ namespace Opdavies\Glassboxx\Request;
interface AuthTokenRequestInterface
{
public const ENDPOINT = '/integration/admin/token';
public const ENDPOINT = '/rest/V1/integration/admin/token';
public function getToken(): string;
}

View file

@ -34,7 +34,7 @@ final class CustomerRequest extends AbstractRequest implements CustomerRequestIn
$response = $this->client->request(
'POST',
self::BASE_URL . self::ENDPOINT,
self::ENDPOINT,
[
'auth_bearer' => $this->authToken,
'headers' => [

View file

@ -8,7 +8,7 @@ use Opdavies\Glassboxx\ValueObject\CustomerInterface;
interface CustomerRequestInterface
{
public const ENDPOINT = '/glassboxxorder/customCustomer';
public const ENDPOINT = '/rest/V1/glassboxxorder/customCustomer';
public function forCustomer(CustomerInterface $customer): AbstractRequest;

View file

@ -47,7 +47,7 @@ class OrderRequest extends AbstractRequest implements OrderRequestInterface
$response = $this->client->request(
'POST',
self::BASE_URL . self::ENDPOINT,
self::ENDPOINT,
[
'auth_bearer' => $this->authToken,
'headers' => [

View file

@ -8,7 +8,7 @@ use Opdavies\Glassboxx\ValueObject\OrderInterface;
interface OrderRequestInterface
{
public const ENDPOINT = '/glassboxxorder/toglassboxx';
public const ENDPOINT = '/rest/V1/glassboxxorder/toglassboxx';
public function forOrder(OrderInterface $order): AbstractRequest;

View file

@ -22,8 +22,7 @@ class AuthTokenRequestTest extends TestCase
->method('request')
->with(
'POST',
AuthTokenRequest::BASE_URL
.AuthTokenRequest::ENDPOINT,
AuthTokenRequest::ENDPOINT,
[
'query' => [
'password' => 'secret',

View file

@ -31,8 +31,7 @@ final class CustomerRequestTest extends TestCase
->method('request')
->with(
'POST',
CustomerRequest::BASE_URL
.CustomerRequest::ENDPOINT,
CustomerRequest::ENDPOINT,
[
'auth_bearer' => $authTokenRequest->getToken(),
'headers' => [

View file

@ -43,8 +43,7 @@ final class OrderRequestTest extends TestCase
->method('request')
->with(
'POST',
OrderRequest::BASE_URL
.OrderRequest::ENDPOINT,
OrderRequest::ENDPOINT,
[
'auth_bearer' => $authTokenRequest->getToken(),
'headers' => [