Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions README.es.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion src/Methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/Onfleet.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Onfleet
public Resources\Teams $teams;
public Resources\Webhooks $webhooks;
public Resources\Workers $workers;
public Resources\CustomFields $customFields;

/**
* @throws ValidationError
Expand Down Expand Up @@ -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);
}

/**
Expand Down
23 changes: 23 additions & 0 deletions src/resources/CustomFields.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Onfleet\resources;

class CustomFields extends Resources
{
protected $_endpoints = [];

public function __construct($api)
{
parent::__construct($api);
$this->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'],
]);
}
}
3 changes: 2 additions & 1 deletion src/resources/Teams.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]
]);
}
}
1 change: 1 addition & 0 deletions src/resources/Workers.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function __construct($api)
'method' => 'POST', 'path' => '/integrations/marketplace',
'deliveryManifestObject' => true
],
'getTasks' => ['method' => 'GET', 'path' => '/workers/:workerId/tasks', 'queryParams' => true]
]);
}
}
44 changes: 44 additions & 0 deletions tests/OnfleetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
109 changes: 109 additions & 0 deletions tests/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -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" => []
]
]
]
]
]
];