diff --git a/src/API/Client.php b/src/API/Client.php index 9bf2ad4..ab0bb80 100644 --- a/src/API/Client.php +++ b/src/API/Client.php @@ -23,7 +23,7 @@ public function get($endpoint = null, array $body = []): array { return $this->parse(function () use ($endpoint, $body) { return $this->client->request('GET', $endpoint, [ - 'json' => $body, + 'query' => $body, 'auth' => $this->auth(), 'headers' => [ 'Content-Type' => 'application/json', diff --git a/src/API/Tracking.php b/src/API/Tracking.php new file mode 100644 index 0000000..5ff73dd --- /dev/null +++ b/src/API/Tracking.php @@ -0,0 +1,37 @@ +get("shipments/$trackingNumber/tracking", [ + 'trackingView' => 'all-checkpoints', + 'levelOfDetail' => 'all' + ]); + } + + public function multi(array $trackingNumbers, ?Carbon $from = null, ?Carbon $to = null) + { + $tracking = array_map(function ($tracking) { + return ['shipmentTrackingNumber' => $tracking]; + }, $trackingNumbers); + + $data = array_filter([ + 'dateRangeFrom' => $from ? $from->format('Y-m-d') : null, + 'dateRangeTo' => $to ? $to->format('Y-m-d') : null, + 'trackingView' => 'all-checkpoints', + 'levelOfDetail' => 'all' + ], fn($row) => $row); + + return $this->get("tracking", $tracking + $data); + } +} diff --git a/src/DHL.php b/src/DHL.php index b81c381..d7bb280 100644 --- a/src/DHL.php +++ b/src/DHL.php @@ -4,6 +4,7 @@ use Booni3\DhlExpressRest\API\Rates; use Booni3\DhlExpressRest\API\Shipments; +use Booni3\DhlExpressRest\API\Tracking; use GuzzleHttp\Client as GuzzleClient; class DHL @@ -45,6 +46,11 @@ public function rates() return new Rates($this->client(), $this->config); } + public function tracking() + { + return new Tracking($this->client(), $this->config); + } + protected function client(): GuzzleClient { if($this->client){