diff --git a/composer.json b/composer.json index b89da66d..5776c830 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/lib/EasyPost/Service/BaseService.php b/lib/EasyPost/Service/BaseService.php index 443cb7f6..f2bc6d2a 100644 --- a/lib/EasyPost/Service/BaseService.php +++ b/lib/EasyPost/Service/BaseService.php @@ -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]; @@ -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']) { diff --git a/lib/EasyPost/Service/EventService.php b/lib/EasyPost/Service/EventService.php index d9bf60b9..10a93779 100644 --- a/lib/EasyPost/Service/EventService.php +++ b/lib/EasyPost/Service/EventService.php @@ -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); } diff --git a/lib/EasyPost/Service/InsuranceService.php b/lib/EasyPost/Service/InsuranceService.php index 80b9e7f8..1753dec7 100644 --- a/lib/EasyPost/Service/InsuranceService.php +++ b/lib/EasyPost/Service/InsuranceService.php @@ -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); } diff --git a/lib/EasyPost/Service/PickupService.php b/lib/EasyPost/Service/PickupService.php index e65ba5b2..b927be75 100644 --- a/lib/EasyPost/Service/PickupService.php +++ b/lib/EasyPost/Service/PickupService.php @@ -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); } diff --git a/lib/EasyPost/Service/ReferralCustomerService.php b/lib/EasyPost/Service/ReferralCustomerService.php index 5d4ecd05..4e3244ae 100644 --- a/lib/EasyPost/Service/ReferralCustomerService.php +++ b/lib/EasyPost/Service/ReferralCustomerService.php @@ -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); } diff --git a/lib/EasyPost/Service/RefundService.php b/lib/EasyPost/Service/RefundService.php index bdcb4553..8075970a 100644 --- a/lib/EasyPost/Service/RefundService.php +++ b/lib/EasyPost/Service/RefundService.php @@ -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); } diff --git a/lib/EasyPost/Service/ReportService.php b/lib/EasyPost/Service/ReportService.php index 09c9df82..2953ed44 100644 --- a/lib/EasyPost/Service/ReportService.php +++ b/lib/EasyPost/Service/ReportService.php @@ -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); } @@ -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']; @@ -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']) { diff --git a/lib/EasyPost/Service/ScanFormService.php b/lib/EasyPost/Service/ScanFormService.php index b8ae0c64..767d6193 100644 --- a/lib/EasyPost/Service/ScanFormService.php +++ b/lib/EasyPost/Service/ScanFormService.php @@ -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); } diff --git a/lib/EasyPost/Service/ShipmentService.php b/lib/EasyPost/Service/ShipmentService.php index 9b30fd92..2b548bb4 100644 --- a/lib/EasyPost/Service/ShipmentService.php +++ b/lib/EasyPost/Service/ShipmentService.php @@ -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); } /** @@ -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); } /** diff --git a/lib/EasyPost/Service/TrackerService.php b/lib/EasyPost/Service/TrackerService.php index 910f83b0..52b64410 100644 --- a/lib/EasyPost/Service/TrackerService.php +++ b/lib/EasyPost/Service/TrackerService.php @@ -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. @@ -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); } /** @@ -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); } /**