Skip to content

Commit

Permalink
Expose the service http client so you can set auth and proxy settings
Browse files Browse the repository at this point in the history
  • Loading branch information
aln-1 committed Jan 14, 2021
1 parent 45f8408 commit 63e18b7
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions Soneritics/PostNL/Service/AbstractService.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ abstract class AbstractService
*/
private $endpoint;

/**
*
* @var \PestJSON
*/
private $httpClient;

/**
*
* @var Customer
Expand All @@ -63,6 +69,29 @@ public function __construct(string $apiKey, Customer $customer, string $endpoint
$this->customer = $customer;
}

/**
* Get http client instance
*
* @return \PestJSON
*/
public function getHttpClient()
{
if(!$this->httpClient) {
$this->httpClient = new \PestJSON($this->endpoint);
}
return $this->httpClient;
}

/**
* Set http client instance
*
* @param \PestJSON $client
*/
public function setHttpClient(\PestJSON $client)
{
$this->httpClient = $client;
}

/**
* Get data from a REST call.
*
Expand All @@ -73,7 +102,7 @@ public function __construct(string $apiKey, Customer $customer, string $endpoint
*/
protected function get($url, $data)
{
return (new \PestJSON($this->endpoint))->get($url, $data, $this->getHeaders());
return $this->getHttpClient()->get($url, $data, $this->getHeaders());
}

/**
Expand All @@ -86,7 +115,7 @@ protected function get($url, $data)
*/
protected function post($url, $data)
{
return (new \PestJSON($this->endpoint))->post($url, $data, $this->getHeaders());
return $this->getHttpClient()->post($url, $data, $this->getHeaders());
}

/**
Expand Down

0 comments on commit 63e18b7

Please sign in to comment.