diff --git a/CHANGELOG.md b/CHANGELOG.md index 37393b7..546110f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.0.6] - 2024-11-04 +### Added +- New `getTasks` endpoints for Teams and Workers +- Added Custom field support for node API wrapper + ## [1.0.5] - 2024-05-17 ### Added - Added support for Worker's Route Delivery Manifest diff --git a/README.es.md b/README.es.md index be9dc8a..76833fd 100644 --- a/README.es.md +++ b/README.es.md @@ -88,9 +88,10 @@ Estas son las operaciones disponibles para cada endpoint: | [Organization](https://docs.onfleet.com/reference#organizations) | get(), get(id) | x | insertTask(id, obj) | x | | [Recipients](https://docs.onfleet.com/reference#recipients) | get(id), get(name, 'name'), get(phone, 'phone') | create(obj), matchMetadata(obj) | update(id, obj) | x | | [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) | -| [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) | +| [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) | | [Webhooks](https://docs.onfleet.com/reference#webhooks) | get() | create(obj) | x | deleteOne(id) | -| [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) | +| [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) | +| [Custom Fields](https://docs.onfleet.com/reference#workers) | get(query) | create(obj) | update(obj) | delete(obj) | #### Peticiones GET Para obtener todos los elementos disponibles en un recurso, éstas llamadas retornan un `Promise` con el arreglo de los resultados: diff --git a/README.md b/README.md index 50c2c85..4f22392 100644 --- a/README.md +++ b/README.md @@ -94,9 +94,10 @@ Here are the operations available for each entity: | [Organization](https://docs.onfleet.com/reference#organizations) | get(), get(id) | x | insertTask(id, obj) | x | | [Recipients](https://docs.onfleet.com/reference#recipients) | get(id), get(name, 'name'), get(phone, 'phone') | create(obj), matchMetadata(obj) | update(id, obj) | x | | [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) | -| [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) | +| [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) | | [Webhooks](https://docs.onfleet.com/reference#webhooks) | get() | create(obj) | x | deleteOne(id) | -| [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) | +| [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) | +| [Custom Fields](https://docs.onfleet.com/reference#workers) | get(query) | create(obj) | update(obj) | delete(obj) | #### GET Requests diff --git a/src/Methods.php b/src/Methods.php index 456a278..8eebe80 100644 --- a/src/Methods.php +++ b/src/Methods.php @@ -97,7 +97,10 @@ public static function method(array $methodData, Onfleet $api, ...$args) $hasBody = true; } } - + if (in_array($method, ['PUT', 'DELETE']) && strpos($url, 'customFields') !== false && is_array($args)) { + $body = $args[0]; + $hasBody = true; + } // POST Prep - 3 different cases if ($method === 'POST') { if (is_string($args[0]) && self::isBase64Encoded($args[0])) { // forceComplete, clone, and autoDispatch (with ID) diff --git a/src/Onfleet.php b/src/Onfleet.php index 68ece87..3fcf220 100644 --- a/src/Onfleet.php +++ b/src/Onfleet.php @@ -27,6 +27,7 @@ class Onfleet public Resources\Teams $teams; public Resources\Webhooks $webhooks; public Resources\Workers $workers; + public Resources\CustomFields $customFields; /** * @throws ValidationError @@ -80,6 +81,7 @@ public function initResources() $this->teams = new Resources\Teams($this); $this->webhooks = new Resources\Webhooks($this); $this->workers = new Resources\Workers($this); + $this->customFields = new Resources\CustomFields($this); } /** diff --git a/src/resources/CustomFields.php b/src/resources/CustomFields.php new file mode 100644 index 0000000..2a033ce --- /dev/null +++ b/src/resources/CustomFields.php @@ -0,0 +1,23 @@ +defineTimeout(); + $this->endpoints([ + 'create' => ['method' => 'POST', 'path' => '/customFields'], + 'get' => [ + 'method' => 'GET', 'path' => '/customFields/:modelName', + 'altPath' => '/customFields/Task', 'queryParams' => true + ], + 'update' => ['method' => 'PUT', 'path' => '/customFields'], + 'deleteOne' => ['method' => 'DELETE', 'path' => '/customFields'], + ]); + } +} diff --git a/src/resources/Teams.php b/src/resources/Teams.php index 04e43f0..9e216e5 100644 --- a/src/resources/Teams.php +++ b/src/resources/Teams.php @@ -17,7 +17,8 @@ public function __construct($api) 'deleteOne' => ['method' => 'DELETE', 'path' => '/teams/:teamId'], 'insertTask' => ['method' => 'PUT', 'path' => '/containers/teams/:teamId'], 'autoDispatch' => ['method' => 'POST', 'path' => '/teams/:teamId/dispatch'], - 'getWorkerEta' => ['method' => 'GET', 'path' => '/teams/:teamId/estimate', 'queryParams' => true] + 'getWorkerEta' => ['method' => 'GET', 'path' => '/teams/:teamId/estimate', 'queryParams' => true], + 'getTasks' => ['method' => 'GET', 'path' => '/teams/:teamId/tasks', 'queryParams' => true] ]); } } diff --git a/src/resources/Workers.php b/src/resources/Workers.php index 6939598..2b1b337 100644 --- a/src/resources/Workers.php +++ b/src/resources/Workers.php @@ -30,6 +30,7 @@ public function __construct($api) 'method' => 'POST', 'path' => '/integrations/marketplace', 'deliveryManifestObject' => true ], + 'getTasks' => ['method' => 'GET', 'path' => '/workers/:workerId/tasks', 'queryParams' => true] ]); } } diff --git a/tests/OnfleetTest.php b/tests/OnfleetTest.php index 67fc2c1..1dcbb83 100644 --- a/tests/OnfleetTest.php +++ b/tests/OnfleetTest.php @@ -474,4 +474,48 @@ public function testGetDeliveryManifest($data) self::assertSame($response["manifestDate"], 1694199600000); self::assertSame(count($response["turnByTurn"]), 1); } + + /** + * @dataProvider data + */ + public function testWorkersGetTasks($data) + { + $curlClient = $this->createMock(CurlClient::class); + $curlClient->method('execute')->willReturn(["code" => 200, "success" => true, "data" => $data["workersTasks"]]); + $onfleet = new Onfleet($data["apiKey"]); + $onfleet->api->client = $curlClient; + $response = $onfleet->workers->getTasks('Mdfs*NDZ1*lMU0abFXAT82lM'); + self::assertIsArray($response); + self::assertSame($response[0]["shortId"], 'c77ff497'); + } + + /** + * @dataProvider data + */ + public function testTeamUnassignedTasks($data) + { + $curlClient = $this->createMock(CurlClient::class); + $curlClient->method('execute')->willReturn(["code" => 200, "success" => true, "data" => $data["workersTasks"]]); + $onfleet = new Onfleet($data["apiKey"]); + $onfleet->api->client = $curlClient; + $response = $onfleet->teams->getTasks('K3FXFtJj2FtaO2~H60evRrDc'); + self::assertIsArray($response); + self::assertSame($response[0]["shortId"], 'c77ff497'); + } + + /** + * @dataProvider data + */ + public function testGetCustomFields($data) + { + $curlClient = $this->createMock(CurlClient::class); + $curlClient->method('execute')->willReturn(["code" => 200, "success" => true, "data" => $data["customFields"]]); + $onfleet = new Onfleet($data["apiKey"]); + $onfleet->api->client = $curlClient; + $response = $onfleet->customFields->get([ + "integration" => "shopify", + ]); + self::assertIsArray($response); + self::assertSame($response["fields"][0]["key"], 'test'); + } } diff --git a/tests/Response.php b/tests/Response.php index 8d384cf..c85d03a 100644 --- a/tests/Response.php +++ b/tests/Response.php @@ -556,6 +556,115 @@ ], "totalDistance" => null ], + "customFields" => [ + "fields" => [ + [ + "description" => "this is a test", + "asArray" => false, + "visibility" => [ + "admin", + "api", + "worker" + ], + "editability" => [ + "admin", + "api" + ], + "key" => "test", + "name" => "test", + "type" => "single_line_text_field", + "contexts" => [ + [ + "isRequired" => false, + "conditions" => [], + "name" => "save" + ] + ], + "value" => "order 123" + ] + ] + ], + "workersTasks" => [ + [ + "id" => "Mdfs*NDZ1*lMU0abFXAT82lM", + "timeCreated" => 1643317843000, + "timeLastModified" => 1643319602671, + "organization" => "nYrkNP6jZMSKgBwG9qG7ci3J", + "shortId" => "c77ff497", + "trackingURL" => "https://onf.lt/c77ff497", + "worker" => "ZxcnkJi~79nonYaMTQ960Mg2", + "merchant" => "nYrkNP6jZMSKgBwG9qG7ci3J", + "executor" => "nYrkNP6jZMSKgBwG9qG7ci3J", + "creator" => "vjw*RDMKDljKVDve1Vtcplgu", + "dependencies" => [], + "state" => 1, + "completeAfter" => null, + "completeBefore" => null, + "pickupTask" => false, + "notes" => "", + "completionDetails" => [ + "failureNotes" => "", + "failureReason" => "NONE", + "events" => [], + "actions" => [], + "time" => null, + "firstLocation" => [], + "lastLocation" => [], + "unavailableAttachments" => [] + ], + "feedback" => [], + "metadata" => [], + "overrides" => [], + "quantity" => 0, + "additionalQuantities" => [ + "quantityA" => 0, + "quantityB" => 0, + "quantityC" => 0 + ], + "serviceTime" => 0, + "identity" => [ + "failedScanCount" => 0, + "checksum" => null + ], + "appearance" => [ + "triangleColor" => null + ], + "scanOnlyRequiredBarcodes" => false, + "container" => [ + "type" => "WORKER", + "worker" => "ZxcnkJi~79nonYaMTQ960Mg2" + ], + "trackingViewed" => false, + "recipients" => [], + "eta" => null, + "delayTime" => null, + "estimatedCompletionTime" => null, + "estimatedArrivalTime" => null, + "destination" => [ + "id" => "nk5xGuf1eQguYXg1*mIVl0Ut", + "timeCreated" => 1643317843000, + "timeLastModified" => 1643317843121, + "location" => [ + -117.8764687, + 33.8078476 + ], + "address" => [ + "apartment" => "", + "state" => "California", + "postalCode" => "92806", + "number" => "2695", + "street" => "East Katella Avenue", + "city" => "Anaheim", + "country" => "United States", + "name" => "Honda Center" + ], + "notes" => "", + "metadata" => [], + "googlePlaceId" => "ChIJXyczhHXX3IARFVUqyhMqiqg", + "warnings" => [] + ] + ] + ] ] ] ];