Skip to content

Commit

Permalink
fix bugs for "get_next_page" functions for Tracker and Shipment (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
jchen293 authored Mar 29, 2023
1 parent 9bfcd9c commit c682a62
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 16 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"rregeer/phpunit-coverage-check": "^0.3.1"
},
"scripts": {
"coverage": "XDEBUG_MODE=coverage ./bin/phpunit --coverage-html clover.html --coverage-clover build/logs/clover.xml && ./bin/coverage-check build/logs/clover.xml 87 --only-percentage",
"coverage": "XDEBUG_MODE=coverage ./bin/phpunit --coverage-html clover.html --coverage-clover build/logs/clover.xml && ./bin/coverage-check build/logs/clover.xml 86 --only-percentage",
"fix": "./bin/phpcbf",
"lint": "./bin/phpcs",
"scan": "composer update --dry-run roave/security-advisories",
Expand Down
7 changes: 6 additions & 1 deletion lib/EasyPost/Service/BaseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,10 @@ protected function allResources($class, $params = null, $beta = false)
* @param string $class
* @param mixed $collection
* @param int $pageSize
* @param mixed $optionalParams
* @return mixed
*/
protected function getNextPageResources($class, $collection, $pageSize = null)
protected function getNextPageResources($class, $collection, $pageSize = null, $optionalParams = null)
{
$objectName = substr(self::classUrl($class), 1);
$collectionArray = $collection[$objectName];
Expand All @@ -164,6 +165,10 @@ protected function getNextPageResources($class, $collection, $pageSize = null)
'before_id' => $collectionArray[count($collectionArray) - 1]['id']
];

if (isset($optionalParams)) {
$params = array_merge($params, $optionalParams);
}

$response = $this->allResources($class, $params);

if (empty($response[$objectName]) || !$response['has_more']) {
Expand Down
2 changes: 1 addition & 1 deletion lib/EasyPost/Service/EventService.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function all($params = null)
* @param string $pageSize
* @return mixed
*/
public function getNextPage($events, $pageSize)
public function getNextPage($events, $pageSize = null)
{
return $this->getNextPageResources(self::serviceModelClassName(self::class), $events, $pageSize);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/EasyPost/Service/InsuranceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function all($params = null)
* @param string $pageSize
* @return mixed
*/
public function getNextPage($insurances, $pageSize)
public function getNextPage($insurances, $pageSize = null)
{
return $this->getNextPageResources(self::serviceModelClassName(self::class), $insurances, $pageSize);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/EasyPost/Service/PickupService.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function all($params = null)
* @param string $pageSize
* @return mixed
*/
public function getNextPage($pickups, $pageSize)
public function getNextPage($pickups, $pageSize = null)
{
return $this->getNextPageResources(self::serviceModelClassName(self::class), $pickups, $pageSize);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/EasyPost/Service/ReferralCustomerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function all($params = null)
* @param string $pageSize
* @return mixed
*/
public function getNextPage($referrals, $pageSize)
public function getNextPage($referrals, $pageSize = null)
{
return $this->getNextPageResources(self::serviceModelClassName(self::class), $referrals, $pageSize);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/EasyPost/Service/RefundService.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function all($params = null)
* @param string $pageSize
* @return mixed
*/
public function getNextPage($refunds, $pageSize)
public function getNextPage($refunds, $pageSize = null)
{
return $this->getNextPageResources(self::serviceModelClassName(self::class), $refunds, $pageSize);
}
Expand Down
5 changes: 3 additions & 2 deletions lib/EasyPost/Service/ReportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function all($params = null)
$url = self::reportUrl($type);
unset($params['type']);
$response = Requestor::request($this->client, 'get', $url, $params);
$response['type'] = $type;

return InternalUtil::convertToEasyPostObject($this->client, $response);
}
Expand All @@ -53,7 +54,7 @@ public function all($params = null)
* @param string $pageSize
* @return mixed
*/
public function getNextPage($reports, $pageSize)
public function getNextPage($reports, $pageSize = null)
{
$reportArray = $reports['reports'];

Expand All @@ -65,7 +66,7 @@ public function getNextPage($reports, $pageSize)
'page_size' => $pageSize,
'before_id' => $reportArray[count($reportArray) - 1]['id']
];
$url = self::reportUrl($reportArray[0]['object']);
$url = self::reportUrl($reports->type);
$response = Requestor::request($this->client, 'get', $url, $params);

if (empty($response['reports']) || !$response['has_more']) {
Expand Down
2 changes: 1 addition & 1 deletion lib/EasyPost/Service/ScanFormService.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function all($params = null)
* @param string $pageSize
* @return mixed
*/
public function getNextPage($scanforms, $pageSize)
public function getNextPage($scanforms, $pageSize = null)
{
return $this->getNextPageResources(self::serviceModelClassName(self::class), $scanforms, $pageSize);
}
Expand Down
20 changes: 17 additions & 3 deletions lib/EasyPost/Service/ShipmentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ public function retrieve($id)
*/
public function all($params = null)
{
return self::allResources(self::serviceModelClassName(self::class), $params);
self::validate($params);
$response = Requestor::request($this->client, 'get', '/shipments', $params);
$response['purchased'] = $params['purchased'] ?? null;
$response['include_children'] = $params['include_children'] ?? null;

return InternalUtil::convertToEasyPostObject($this->client, $response);
}

/**
Expand All @@ -40,9 +45,18 @@ public function all($params = null)
* @param string $pageSize
* @return mixed
*/
public function getNextPage($shipments, $pageSize)
public function getNextPage($shipments, $pageSize = null)
{
return $this->getNextPageResources(self::serviceModelClassName(self::class), $shipments, $pageSize);
$params = [];

if (isset($shipments->purchased)) {
$params['purchased'] = $shipments->purchased;
}

if (isset($shipments->include_children)) {
$params['include_children'] = $shipments->include_children;
}
return $this->getNextPageResources(self::serviceModelClassName(self::class), $shipments, $pageSize, $params);
}

/**
Expand Down
21 changes: 18 additions & 3 deletions lib/EasyPost/Service/TrackerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace EasyPost\Service;

use EasyPost\Http\Requestor;
use EasyPost\Util\InternalUtil;

/**
* Tracker service containing all the logic to make API calls.
Expand All @@ -28,7 +29,12 @@ public function retrieve($id)
*/
public function all($params = null)
{
return self::allResources(self::serviceModelClassName(self::class), $params);
self::validate($params);
$response = Requestor::request($this->client, 'get', '/trackers', $params);
$response['tracking_code'] = $params['tracking_code'] ?? null;
$response['carrier'] = $params['carrier'] ?? null;

return InternalUtil::convertToEasyPostObject($this->client, $response);
}

/**
Expand All @@ -38,9 +44,18 @@ public function all($params = null)
* @param string $pageSize
* @return mixed
*/
public function getNextPage($trackers, $pageSize)
public function getNextPage($trackers, $pageSize = null)
{
return $this->getNextPageResources(self::serviceModelClassName(self::class), $trackers, $pageSize);
$params = [];

if (isset($trackers->tracking_code)) {
$params['tracking_code'] = $trackers->tracking_code;
}

if (isset($trackers->carrier)) {
$params['carrier'] = $trackers->carrier;
}
return $this->getNextPageResources(self::serviceModelClassName(self::class), $trackers, $pageSize, $params);
}

/**
Expand Down

0 comments on commit c682a62

Please sign in to comment.