Skip to content

Commit

Permalink
add tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
booni3 committed Feb 23, 2021
1 parent b5ae9ed commit ad38bc7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/API/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
37 changes: 37 additions & 0 deletions src/API/Tracking.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php


namespace Booni3\DhlExpressRest\API;


use Booni3\DhlExpressRest\DHL;
use Booni3\DhlExpressRest\Response\RatesResponse;
use Booni3\DhlExpressRest\DTO\ShipmentCreator;
use Carbon\Carbon;

class Tracking extends Client
{
public function single(string $trackingNumber)
{
return $this->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);
}
}
6 changes: 6 additions & 0 deletions src/DHL.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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){
Expand Down

0 comments on commit ad38bc7

Please sign in to comment.