Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: persist the HTTP client inside of EasyPostClient #322

Merged
merged 2 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Drops support for PHP 7.4
- Adds support for PHP 8.3
- Persists the HTTP client inside of the `EasyPostClient` via the `httpClient` property to reduce memory consumption on consecutive requests
- Removed `withCarbonOffset` parameter from `create`, `buy`, and `regenerateRates` functions of the Shipment service as EasyPost now offers Carbon Neutral shipments by default for free
- Fixes a bug where the original filtering criteria of `all` calls wasn't passed along to `getNextPage` calls. Now, these are persisted via a `_params` key on response objects locally
- Removes the undocumented `createAndBuy` function from the `Batch` service. The proper usage is to create a batch first and buy it separately
Expand Down
3 changes: 3 additions & 0 deletions lib/EasyPost/EasyPostClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use EasyPost\Service\TrackerService;
use EasyPost\Service\UserService;
use EasyPost\Service\WebhookService;
use GuzzleHttp\Client;

/**
* Client used to send requests to the EasyPost API.
Expand Down Expand Up @@ -71,6 +72,7 @@ class EasyPostClient extends BaseService
private $mockingUtility;
public $requestEvent;
public $responseEvent;
public $httpClient;

/**
* Constructor for an EasyPostClient.
Expand All @@ -93,6 +95,7 @@ public function __construct(
$this->mockingUtility = $mockingUtility;
$this->requestEvent = new RequestHook();
$this->responseEvent = new ResponseHook();
$this->httpClient = new Client();

if (!$this->apiKey) {
throw new MissingParameterException(
Expand Down
4 changes: 1 addition & 3 deletions lib/EasyPost/Http/Requestor.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use EasyPost\Exception\Api\TimeoutException;
use EasyPost\Exception\Api\UnauthorizedException;
use EasyPost\Exception\Api\UnknownApiException;
use GuzzleHttp\Client;

class Requestor
{
Expand Down Expand Up @@ -205,10 +204,9 @@ private static function requestRaw($client, $method, $url, $params, $beta = fals
$httpStatus = $matchingRequest->responseInfo->statusCode;
$responseHeaders = [];
} else {
$guzzleClient = new Client();
$requestOptions['headers'] = $headers;
try {
$response = $guzzleClient->request($method, $absoluteUrl, $requestOptions);
$response = $client->httpClient->request($method, $absoluteUrl, $requestOptions);
} catch (\GuzzleHttp\Exception\ConnectException $error) {
throw new HttpException(sprintf(Constants::COMMUNICATION_ERROR, 'EasyPost', $error->getMessage()));
}
Expand Down
91 changes: 48 additions & 43 deletions test/cassettes/addresses/getNextPage.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading