mirror of
https://github.com/opdavies/glassboxx-sdk-php.git
synced 2025-01-22 12:07:32 +00:00
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:
parent
532dfd43a1
commit
2ba89e1c6a
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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' => [
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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' => [
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -22,8 +22,7 @@ class AuthTokenRequestTest extends TestCase
|
|||
->method('request')
|
||||
->with(
|
||||
'POST',
|
||||
AuthTokenRequest::BASE_URL
|
||||
.AuthTokenRequest::ENDPOINT,
|
||||
AuthTokenRequest::ENDPOINT,
|
||||
[
|
||||
'query' => [
|
||||
'password' => 'secret',
|
||||
|
|
|
@ -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' => [
|
||||
|
|
|
@ -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' => [
|
||||
|
|
Loading…
Reference in a new issue