Skip to content

Commit 872f201

Browse files
Merge pull request #18 from onfleet/INT-551
[INT-551][php-onfleet] Add new endpoints
2 parents 7df9aa2 + 5167f89 commit 872f201

File tree

10 files changed

+196
-6
lines changed

10 files changed

+196
-6
lines changed

CHANGELOG.md

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

77
## [Unreleased]
88

9+
## [1.0.6] - 2024-11-04
10+
### Added
11+
- New `getTasks` endpoints for Teams and Workers
12+
- Added Custom field support for node API wrapper
13+
914
## [1.0.5] - 2024-05-17
1015
### Added
1116
- Added support for Worker's Route Delivery Manifest

README.es.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,10 @@ Estas son las operaciones disponibles para cada endpoint:
8888
| [Organization](https://docs.onfleet.com/reference#organizations) | get(), get(id) | x | insertTask(id, obj) | x |
8989
| [Recipients](https://docs.onfleet.com/reference#recipients) | get(id), get(name, 'name'), get(phone, 'phone') | create(obj), matchMetadata(obj) | update(id, obj) | x |
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) |
91-
| [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) |
91+
| [Teams](https://docs.onfleet.com/reference#teams) | get(), get(id), getWorkerEta(id, obj), getTasks(id) | 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), getDeliveryManifest(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), getTasks(id) | create(obj), setSchedule(id, obj), matchMetadata(obj), getDeliveryManifest(obj) | update(id, obj), insertTask(id, obj) | deleteOne(id) |
94+
| [Custom Fields](https://docs.onfleet.com/reference#workers) | get(query) | create(obj) | update(obj) | delete(obj) |
9495

9596
#### Peticiones GET
9697
Para obtener todos los elementos disponibles en un recurso, éstas llamadas retornan un `Promise` con el arreglo de los resultados:

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ Here are the operations available for each entity:
9494
| [Organization](https://docs.onfleet.com/reference#organizations) | get(), get(id) | x | insertTask(id, obj) | x |
9595
| [Recipients](https://docs.onfleet.com/reference#recipients) | get(id), get(name, 'name'), get(phone, 'phone') | create(obj), matchMetadata(obj) | update(id, obj) | x |
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) |
97-
| [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) |
97+
| [Teams](https://docs.onfleet.com/reference#teams) | get(), get(id), getWorkerEta(id, obj), getTasks(id) | 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), getDeliveryManifest(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), getTasks(id) | create(obj), setSchedule(id, obj), matchMetadata(obj), getDeliveryManifest(obj) | update(id, obj), insertTask(id, obj) | deleteOne(id) |
100+
| [Custom Fields](https://docs.onfleet.com/reference#workers) | get(query) | create(obj) | update(obj) | delete(obj) |
100101

101102
#### GET Requests
102103

src/Methods.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ public static function method(array $methodData, Onfleet $api, ...$args)
9797
$hasBody = true;
9898
}
9999
}
100-
100+
if (in_array($method, ['PUT', 'DELETE']) && strpos($url, 'customFields') !== false && is_array($args)) {
101+
$body = $args[0];
102+
$hasBody = true;
103+
}
101104
// POST Prep - 3 different cases
102105
if ($method === 'POST') {
103106
if (is_string($args[0]) && self::isBase64Encoded($args[0])) { // forceComplete, clone, and autoDispatch (with ID)

src/Onfleet.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Onfleet
2727
public Resources\Teams $teams;
2828
public Resources\Webhooks $webhooks;
2929
public Resources\Workers $workers;
30+
public Resources\CustomFields $customFields;
3031

3132
/**
3233
* @throws ValidationError
@@ -80,6 +81,7 @@ public function initResources()
8081
$this->teams = new Resources\Teams($this);
8182
$this->webhooks = new Resources\Webhooks($this);
8283
$this->workers = new Resources\Workers($this);
84+
$this->customFields = new Resources\CustomFields($this);
8385
}
8486

8587
/**

src/resources/CustomFields.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Onfleet\resources;
4+
5+
class CustomFields extends Resources
6+
{
7+
protected $_endpoints = [];
8+
9+
public function __construct($api)
10+
{
11+
parent::__construct($api);
12+
$this->defineTimeout();
13+
$this->endpoints([
14+
'create' => ['method' => 'POST', 'path' => '/customFields'],
15+
'get' => [
16+
'method' => 'GET', 'path' => '/customFields/:modelName',
17+
'altPath' => '/customFields/Task', 'queryParams' => true
18+
],
19+
'update' => ['method' => 'PUT', 'path' => '/customFields'],
20+
'deleteOne' => ['method' => 'DELETE', 'path' => '/customFields'],
21+
]);
22+
}
23+
}

src/resources/Teams.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public function __construct($api)
1717
'deleteOne' => ['method' => 'DELETE', 'path' => '/teams/:teamId'],
1818
'insertTask' => ['method' => 'PUT', 'path' => '/containers/teams/:teamId'],
1919
'autoDispatch' => ['method' => 'POST', 'path' => '/teams/:teamId/dispatch'],
20-
'getWorkerEta' => ['method' => 'GET', 'path' => '/teams/:teamId/estimate', 'queryParams' => true]
20+
'getWorkerEta' => ['method' => 'GET', 'path' => '/teams/:teamId/estimate', 'queryParams' => true],
21+
'getTasks' => ['method' => 'GET', 'path' => '/teams/:teamId/tasks', 'queryParams' => true]
2122
]);
2223
}
2324
}

src/resources/Workers.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function __construct($api)
3030
'method' => 'POST', 'path' => '/integrations/marketplace',
3131
'deliveryManifestObject' => true
3232
],
33+
'getTasks' => ['method' => 'GET', 'path' => '/workers/:workerId/tasks', 'queryParams' => true]
3334
]);
3435
}
3536
}

tests/OnfleetTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,4 +474,48 @@ public function testGetDeliveryManifest($data)
474474
self::assertSame($response["manifestDate"], 1694199600000);
475475
self::assertSame(count($response["turnByTurn"]), 1);
476476
}
477+
478+
/**
479+
* @dataProvider data
480+
*/
481+
public function testWorkersGetTasks($data)
482+
{
483+
$curlClient = $this->createMock(CurlClient::class);
484+
$curlClient->method('execute')->willReturn(["code" => 200, "success" => true, "data" => $data["workersTasks"]]);
485+
$onfleet = new Onfleet($data["apiKey"]);
486+
$onfleet->api->client = $curlClient;
487+
$response = $onfleet->workers->getTasks('Mdfs*NDZ1*lMU0abFXAT82lM');
488+
self::assertIsArray($response);
489+
self::assertSame($response[0]["shortId"], 'c77ff497');
490+
}
491+
492+
/**
493+
* @dataProvider data
494+
*/
495+
public function testTeamUnassignedTasks($data)
496+
{
497+
$curlClient = $this->createMock(CurlClient::class);
498+
$curlClient->method('execute')->willReturn(["code" => 200, "success" => true, "data" => $data["workersTasks"]]);
499+
$onfleet = new Onfleet($data["apiKey"]);
500+
$onfleet->api->client = $curlClient;
501+
$response = $onfleet->teams->getTasks('K3FXFtJj2FtaO2~H60evRrDc');
502+
self::assertIsArray($response);
503+
self::assertSame($response[0]["shortId"], 'c77ff497');
504+
}
505+
506+
/**
507+
* @dataProvider data
508+
*/
509+
public function testGetCustomFields($data)
510+
{
511+
$curlClient = $this->createMock(CurlClient::class);
512+
$curlClient->method('execute')->willReturn(["code" => 200, "success" => true, "data" => $data["customFields"]]);
513+
$onfleet = new Onfleet($data["apiKey"]);
514+
$onfleet->api->client = $curlClient;
515+
$response = $onfleet->customFields->get([
516+
"integration" => "shopify",
517+
]);
518+
self::assertIsArray($response);
519+
self::assertSame($response["fields"][0]["key"], 'test');
520+
}
477521
}

tests/Response.php

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,115 @@
556556
],
557557
"totalDistance" => null
558558
],
559+
"customFields" => [
560+
"fields" => [
561+
[
562+
"description" => "this is a test",
563+
"asArray" => false,
564+
"visibility" => [
565+
"admin",
566+
"api",
567+
"worker"
568+
],
569+
"editability" => [
570+
"admin",
571+
"api"
572+
],
573+
"key" => "test",
574+
"name" => "test",
575+
"type" => "single_line_text_field",
576+
"contexts" => [
577+
[
578+
"isRequired" => false,
579+
"conditions" => [],
580+
"name" => "save"
581+
]
582+
],
583+
"value" => "order 123"
584+
]
585+
]
586+
],
587+
"workersTasks" => [
588+
[
589+
"id" => "Mdfs*NDZ1*lMU0abFXAT82lM",
590+
"timeCreated" => 1643317843000,
591+
"timeLastModified" => 1643319602671,
592+
"organization" => "nYrkNP6jZMSKgBwG9qG7ci3J",
593+
"shortId" => "c77ff497",
594+
"trackingURL" => "https://onf.lt/c77ff497",
595+
"worker" => "ZxcnkJi~79nonYaMTQ960Mg2",
596+
"merchant" => "nYrkNP6jZMSKgBwG9qG7ci3J",
597+
"executor" => "nYrkNP6jZMSKgBwG9qG7ci3J",
598+
"creator" => "vjw*RDMKDljKVDve1Vtcplgu",
599+
"dependencies" => [],
600+
"state" => 1,
601+
"completeAfter" => null,
602+
"completeBefore" => null,
603+
"pickupTask" => false,
604+
"notes" => "",
605+
"completionDetails" => [
606+
"failureNotes" => "",
607+
"failureReason" => "NONE",
608+
"events" => [],
609+
"actions" => [],
610+
"time" => null,
611+
"firstLocation" => [],
612+
"lastLocation" => [],
613+
"unavailableAttachments" => []
614+
],
615+
"feedback" => [],
616+
"metadata" => [],
617+
"overrides" => [],
618+
"quantity" => 0,
619+
"additionalQuantities" => [
620+
"quantityA" => 0,
621+
"quantityB" => 0,
622+
"quantityC" => 0
623+
],
624+
"serviceTime" => 0,
625+
"identity" => [
626+
"failedScanCount" => 0,
627+
"checksum" => null
628+
],
629+
"appearance" => [
630+
"triangleColor" => null
631+
],
632+
"scanOnlyRequiredBarcodes" => false,
633+
"container" => [
634+
"type" => "WORKER",
635+
"worker" => "ZxcnkJi~79nonYaMTQ960Mg2"
636+
],
637+
"trackingViewed" => false,
638+
"recipients" => [],
639+
"eta" => null,
640+
"delayTime" => null,
641+
"estimatedCompletionTime" => null,
642+
"estimatedArrivalTime" => null,
643+
"destination" => [
644+
"id" => "nk5xGuf1eQguYXg1*mIVl0Ut",
645+
"timeCreated" => 1643317843000,
646+
"timeLastModified" => 1643317843121,
647+
"location" => [
648+
-117.8764687,
649+
33.8078476
650+
],
651+
"address" => [
652+
"apartment" => "",
653+
"state" => "California",
654+
"postalCode" => "92806",
655+
"number" => "2695",
656+
"street" => "East Katella Avenue",
657+
"city" => "Anaheim",
658+
"country" => "United States",
659+
"name" => "Honda Center"
660+
],
661+
"notes" => "",
662+
"metadata" => [],
663+
"googlePlaceId" => "ChIJXyczhHXX3IARFVUqyhMqiqg",
664+
"warnings" => []
665+
]
666+
]
667+
]
559668
]
560669
]
561670
];

0 commit comments

Comments
 (0)