Skip to content

Commit 7df9aa2

Browse files
Merge pull request #15 from onfleet/INT-1313-php-onfleet-delivery-manifest-endpoint
[INT-1313][php-onfleet] Delivery Manifest endpoint
2 parents da593ec + 6472739 commit 7df9aa2

File tree

7 files changed

+130
-6
lines changed

7 files changed

+130
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [1.0.5] - 2024-05-17
10+
### Added
11+
- Added support for Worker's Route Delivery Manifest
12+
913
## [1.0.4] - 2023-10-05
1014
### Fixed
1115
- Removed library that causes conflicts with Laravel framework

README.es.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Estas son las operaciones disponibles para cada endpoint:
9090
| [Tasks](https://docs.onfleet.com/reference#tasks) | get(query), get(id), get(shortId, 'shortId') | create(obj), clone(id), forceComplete(id), batch(obj), autoAssign(obj), matchMetadata(obj) | update(id, obj) | deleteOne(id) |
9191
| [Teams](https://docs.onfleet.com/reference#teams) | get(), get(id), getWorkerEta(id, obj) | create(obj), autoDispatch(id, obj) | update(id, obj), insertTask(id, obj) | deleteOne(id) |
9292
| [Webhooks](https://docs.onfleet.com/reference#webhooks) | get() | create(obj) | x | deleteOne(id) |
93-
| [Workers](https://docs.onfleet.com/reference#workers) | get(), get(query), get(id), getByLocation(obj), getSchedule(id) | create(obj), setSchedule(id, obj), matchMetadata(obj) | update(id, obj), insertTask(id, obj) | deleteOne(id) |
93+
| [Workers](https://docs.onfleet.com/reference#workers) | get(), get(query), get(id), getByLocation(obj), getSchedule(id) | create(obj), setSchedule(id, obj), matchMetadata(obj), getDeliveryManifest(obj) | update(id, obj), insertTask(id, obj) | deleteOne(id) |
9494

9595
#### Peticiones GET
9696
Para obtener todos los elementos disponibles en un recurso, éstas llamadas retornan un `Promise` con el arreglo de los resultados:
@@ -179,6 +179,20 @@ $datos = [
179179
$onfleet->workers->create($datos);
180180
```
181181

182+
##### Ejemplos de `getDeliveryManifest()`
183+
184+
```php
185+
$data = [
186+
"hubId" => "<hubId>", // Required
187+
"workerId" => "<workerId>", // Required
188+
"googleApiKey" => "<googleApiKey>", // Optional
189+
"startDate" => "<startDate>", // Optional - Timestamp format e.g. 1557936000000
190+
"endDate" => "<endDate>" // Optional - Timestamp format e.g. 1557936000000
191+
];
192+
193+
$onfleet->workers->getDeliveryManifest($data);
194+
```
195+
182196
Otras peticiones POST incluyen `clone`, `forceComplete`, `batchCreate`, `autoAssign` en el recurso *Tasks*; `setSchedule` en el recurso *Workers*; `autoDispatch` en el recurso *Teams*; y `matchMetadata` en todos los recursos que lo soportan. Por ejemplo:
183197

184198
```php
@@ -188,13 +202,14 @@ $onfleet->tasks->batchCreate($datos);
188202
$onfleet->tasks->autoAssign($datos);
189203

190204
$onfleet->workers->setSchedule('<24_digit_ID>', $datos);
205+
$onfleet->workers->getDeliveryManifest($data);
191206

192207
$onfleet->teams->autoDispatch('<24_digit_ID>', $datos);
193208

194209
$onfleet-><entity_name_pluralized>->matchMetadata($datos);
195210
```
196211

197-
Para más información, podemos consultar la documentación sobre [`clone`](https://docs.onfleet.com/reference#clone-task), [`forceComplete`](https://docs.onfleet.com/reference#complete-task), [`batchCreate`](https://docs.onfleet.com/reference#create-tasks-in-batch), [`autoAssign`](https://docs.onfleet.com/reference#automatically-assign-list-of-tasks), [`setSchedule`](https://docs.onfleet.com/reference#set-workers-schedule). [`matchMetadata`](https://docs.onfleet.com/reference#querying-by-metadata) y [`autoDispatch`](https://docs.onfleet.com/reference#team-auto-dispatch).
212+
Para más información, podemos consultar la documentación sobre [`clone`](https://docs.onfleet.com/reference#clone-task), [`forceComplete`](https://docs.onfleet.com/reference#complete-task), [`batchCreate`](https://docs.onfleet.com/reference#create-tasks-in-batch), [`autoAssign`](https://docs.onfleet.com/reference#automatically-assign-list-of-tasks), [`setSchedule`](https://docs.onfleet.com/reference#set-workers-schedule). [`matchMetadata`](https://docs.onfleet.com/reference#querying-by-metadata), [`getDeliveryManifest`](https://docs.onfleet.com/reference/delivery-manifest) y [`autoDispatch`](https://docs.onfleet.com/reference#team-auto-dispatch).
198213

199214
#### Peticiones PUT
200215
Para modificar un elemento de un recurso:

README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Here are the operations available for each entity:
9696
| [Tasks](https://docs.onfleet.com/reference#tasks) | get(query), get(id), get(shortId, 'shortId') | create(obj), clone(id), forceComplete(id), batch(obj), autoAssign(obj), matchMetadata(obj) | update(id, obj) | deleteOne(id) |
9797
| [Teams](https://docs.onfleet.com/reference#teams) | get(), get(id), getWorkerEta(id, obj) | create(obj), autoDispatch(id, obj) | update(id, obj), insertTask(id, obj) | deleteOne(id) |
9898
| [Webhooks](https://docs.onfleet.com/reference#webhooks) | get() | create(obj) | x | deleteOne(id) |
99-
| [Workers](https://docs.onfleet.com/reference#workers) | get(), get(query), get(id), getByLocation(obj), getSchedule(id) | create(obj), setSchedule(id, obj), matchMetadata(obj) | update(id, obj), insertTask(id, obj) | deleteOne(id) |
99+
| [Workers](https://docs.onfleet.com/reference#workers) | get(), get(query), get(id), getByLocation(obj), getSchedule(id) | create(obj), setSchedule(id, obj), matchMetadata(obj), getDeliveryManifest(obj) | update(id, obj), insertTask(id, obj) | deleteOne(id) |
100100

101101
#### GET Requests
102102

@@ -197,6 +197,20 @@ $data = [
197197
$onfleet->workers->create($data);
198198
```
199199

200+
##### Examples of `getDeliveryManifest()`
201+
202+
```php
203+
$data = [
204+
"hubId" => "<hubId>", // Required
205+
"workerId" => "<workerId>", // Required
206+
"googleApiKey" => "<googleApiKey>", // Optional
207+
"startDate" => "<startDate>", // Optional - Timestamp format e.g. 1557936000000
208+
"endDate" => "<endDate>" // Optional - Timestamp format e.g. 1557936000000
209+
];
210+
211+
$onfleet->workers->getDeliveryManifest($data);
212+
```
213+
200214
Extended POST requests include `clone`, `forceComplete`, `batchCreate`, `autoAssign` on the _Tasks_ endpoint; `setSchedule` on the _Workers_ endpoint; `autoDispatch` on the _Teams_ endpoint; and `matchMetadata` on all supported entities. For instance:
201215

202216
```php
@@ -206,13 +220,14 @@ $onfleet->tasks->batchCreate($data);
206220
$onfleet->tasks->autoAssign($data);
207221

208222
$onfleet->workers->setSchedule('<24_digit_ID>', $data);
223+
$onfleet->workers->getDeliveryManifest($data);
209224

210225
$onfleet->teams->autoDispatch('<24_digit_ID>', $data);
211226

212227
$onfleet-><entity_name_pluralized>->matchMetadata($data);
213228
```
214229

215-
For more details, check our documentation on [`clone`](https://docs.onfleet.com/reference#clone-task), [`forceComplete`](https://docs.onfleet.com/reference#complete-task), [`batchCreate`](https://docs.onfleet.com/reference#create-tasks-in-batch), [`autoAssign`](https://docs.onfleet.com/reference#automatically-assign-list-of-tasks), [`setSchedule`](https://docs.onfleet.com/reference#set-workers-schedule), [`matchMetadata`](https://docs.onfleet.com/reference#querying-by-metadata), and [`autoDispatch`](https://docs.onfleet.com/reference#team-auto-dispatch).
230+
For more details, check our documentation on [`clone`](https://docs.onfleet.com/reference#clone-task), [`forceComplete`](https://docs.onfleet.com/reference#complete-task), [`batchCreate`](https://docs.onfleet.com/reference#create-tasks-in-batch), [`autoAssign`](https://docs.onfleet.com/reference#automatically-assign-list-of-tasks), [`setSchedule`](https://docs.onfleet.com/reference#set-workers-schedule), [`matchMetadata`](https://docs.onfleet.com/reference#querying-by-metadata), [`getDeliveryManifest`](https://docs.onfleet.com/reference/delivery-manifest), and [`autoDispatch`](https://docs.onfleet.com/reference#team-auto-dispatch).
216231

217232
#### PUT Requests
218233

src/Methods.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public static function method(array $methodData, Onfleet $api, ...$args)
6363
$path = $methodData['path'] ?? '';
6464
$altPath = $methodData['altPath'] ?? [];
6565
$queryParams = $methodData['queryParams'] ?? [];
66+
$deliveryManifestObject = $methodData['deliveryManifestObject'] ?? [];
6667
$timeoutInMilliseconds = $methodData['timeoutInMilliseconds'] ?? 0;
6768

6869
$url = "{$api->api->baseUrl}{$path}";
@@ -122,6 +123,33 @@ public static function method(array $methodData, Onfleet $api, ...$args)
122123
$url = "{$url}{$httpQueryParams}";
123124
}
124125

126+
// Reference https://docs.onfleet.com/reference/delivery-manifest
127+
if ($deliveryManifestObject && isset($args[0]) && count($args) > 0) {
128+
foreach ($args as $item) {
129+
if (isset($item['hubId']) && isset($item['workerId'])) {
130+
$body = array(
131+
'path' => 'providers/manifest/generate?hubId=' . $item['hubId'] . '&workerId=' . $item['workerId'],
132+
'method' => "GET"
133+
);
134+
$hasBody = true;
135+
}
136+
if (isset($item['googleApiKey'])) {
137+
$api->api->headers[] = 'X-API-Key: Google ' . $item['googleApiKey'];
138+
}
139+
$queryParams = [];
140+
if (isset($item['startDate'])) {
141+
$queryParams['startDate'] = $item['startDate'];
142+
}
143+
if (isset($item['endDate'])) {
144+
$queryParams['endDate'] = $item['endDate'];
145+
}
146+
if (!empty($queryParams)) {
147+
$url .= '?' . http_build_query($queryParams);
148+
}
149+
}
150+
}
151+
152+
125153
$result = $api->api->client->execute($url, $method, $api->api->headers, ($hasBody ? $body : []), $timeoutInMilliseconds);
126154

127155
if ($result['success']) return $method === 'DELETE' ? $result["code"] : $result['data'];

src/resources/Workers.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ public function __construct($api)
2525
'insertTask' => ['method' => 'PUT', 'path' => '/containers/workers/:workerId'],
2626
'getSchedule' => ['method' => 'GET', 'path' => '/workers/:workerId/schedule'],
2727
'setSchedule' => ['method' => 'POST', 'path' => '/workers/:workerId/schedule'],
28-
'matchMetadata' => ['method' => 'POST', 'path' => '/workers/metadata']
28+
'matchMetadata' => ['method' => 'POST', 'path' => '/workers/metadata'],
29+
'getDeliveryManifest' => [
30+
'method' => 'POST', 'path' => '/integrations/marketplace',
31+
'deliveryManifestObject' => true
32+
],
2933
]);
3034
}
3135
}

tests/OnfleetTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,4 +453,25 @@ public function data()
453453
{
454454
return include("Response.php");
455455
}
456+
457+
/**
458+
* @dataProvider data
459+
*/
460+
public function testGetDeliveryManifest($data)
461+
{
462+
$curlClient = $this->createMock(CurlClient::class);
463+
$curlClient->method('execute')->willReturn(["code" => 200, "success" => true, "data" => $data["getManifestProvider"]]);
464+
$onfleet = new Onfleet($data["apiKey"]);
465+
$onfleet->api->client = $curlClient;
466+
$response = $onfleet->workers->getDeliveryManifest([
467+
"hubId" => "kyfYe*wyVbqfomP2HTn5dAe1~*O",
468+
"workerId" => "kBUZAb7pREtRn*8wIUCpjnPu",
469+
"googleApiKey" => "<google_direction_api_key>",
470+
"startDate" => "1455072025000",
471+
"endDate" => "1455072025000'",
472+
]);
473+
self::assertIsArray($response);
474+
self::assertSame($response["manifestDate"], 1694199600000);
475+
self::assertSame(count($response["turnByTurn"]), 1);
476+
}
456477
}

tests/Response.php

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,44 @@
518518
"notes" => "Always orders our GSC special",
519519
"skipSMSNotifications" => false,
520520
"metadata" => []
521-
]
521+
],
522+
"getManifestProvider" => [
523+
"manifestDate" => 1694199600000,
524+
"departureTime" => 1694199600000,
525+
"driver" => [
526+
"name" => "Test One",
527+
"phone" => "+16265555768",
528+
],
529+
"vehicle" => [
530+
"type" => "CAR",
531+
"description" => "Honda",
532+
"licensePlate" => "12345687",
533+
"color" => "Purple",
534+
"timeLastModified" => 1692746334342,
535+
],
536+
"hubAddress" => "1111 South Figueroa Street, Los Angeles, California 90015",
537+
"turnByTurn" => [
538+
[
539+
"start_address" => "1403 W Pico Blvd, Los Angeles, CA 90015, USA",
540+
"end_address" => "2695 E Katella Ave, Anaheim, CA 92806, USA",
541+
"eta" => 1692992466000,
542+
"driving_distance" => "30.6 mi",
543+
"steps" => [
544+
"Head southeast on 12th St E toward S Figueroa StPartial restricted usage road",
545+
"Turn right onto Flower St",
546+
"Turn left onto the Interstate 10 E ramp to 18th St",
547+
"Merge onto I-10 E",
548+
"Take the exit onto I-5 S toward Santa Ana",
549+
"Take exit 109A for Katella Ave",
550+
"Turn right onto E Katella AvePass by Comerica Bank (on the right in 1.3 mi)",
551+
"Turn left onto S Douglass Rd",
552+
"Turn right onto Stanley Cup Wy",
553+
"Turn right"
554+
]
555+
]
556+
],
557+
"totalDistance" => null
558+
],
522559
]
523560
]
524561
];

0 commit comments

Comments
 (0)