From b68a594249ab19c63136231c2225754acb09c0fc Mon Sep 17 00:00:00 2001 From: Shuai Tseng Date: Fri, 26 Sep 2025 19:12:08 -0700 Subject: [PATCH 1/7] adding routeplan endpoints --- src/Methods.php | 14 +++++++------- src/Onfleet.php | 2 ++ src/resources/Routeplans.php | 23 +++++++++++++++++++++++ tests/OnfleetTest.php | 8 ++++---- tests/Response.php | 10 +++++----- 5 files changed, 41 insertions(+), 16 deletions(-) create mode 100644 src/resources/Routeplans.php diff --git a/src/Methods.php b/src/Methods.php index 8eebe80..aabe1c1 100644 --- a/src/Methods.php +++ b/src/Methods.php @@ -27,7 +27,7 @@ public static function isBase64Encoded(string $str): bool */ public static function replaceWithId(string $url, string $id): string { - return preg_replace('/:[a-z]*Id/', $id, $url); + return preg_replace('/:[a-zA-Z]*Id/', $id, $url); } /** @@ -43,7 +43,7 @@ public static function replaceWithEndpointAndParam(string $url, string $endpoint if (in_array($endpoint, ['workers', 'teams', 'organizations'])) { $path = preg_replace('/\/:param/', "", $url); } - return preg_replace('/:[a-z]*Id$/', "{$endpoint}/{$id}", $path); + return preg_replace('/:[a-zA-Z]*Id$/', "{$endpoint}/{$id}", $path); } /** @@ -159,16 +159,16 @@ public static function method(array $methodData, Onfleet $api, ...$args) $errorCode = $result['error']['message']['error']; $errorInfo = [ - $result['error']['message']['message'], - $result['error']['message']['cause'], + $result['error']['message']['message'] ?? '', + $result['error']['message']['cause'] ?? '', $errorCode, - $result['error']['message']['request'], + $result['error']['message']['request'] ?? '', ]; - + if ($errorCode === 2300) { throw new RateLimitError($errorInfo[0], $errorInfo[1] ?? '', $errorInfo[2], $errorInfo[3]); } else if ($errorCode <= 1108 && $errorCode >= 1100) { - throw new PermissionError($errorInfo[0], $errorInfo[1] ?? '', $errorInfo[2], $errorInfo[3]); + throw new PermissionError($errorInfo[0], $errorInfo[1]['message]'] ?? '', $errorInfo[2], $errorInfo[3]); } else if ($errorCode >= 2500) { throw new ServiceError($errorInfo[0], $errorInfo[1] ?? '', $errorInfo[2], $errorInfo[3]); } else if ($errorCode === 2218) { // Precondition error for Auto-Dispatch diff --git a/src/Onfleet.php b/src/Onfleet.php index 3fcf220..e7d386d 100644 --- a/src/Onfleet.php +++ b/src/Onfleet.php @@ -23,6 +23,7 @@ class Onfleet public Resources\Hubs $hubs; public Resources\Organizations $organization; public Resources\Recipients $recipients; + public Resources\Routeplans $routeplans; public Resources\Tasks $tasks; public Resources\Teams $teams; public Resources\Webhooks $webhooks; @@ -77,6 +78,7 @@ public function initResources() $this->hubs = new Resources\Hubs($this); $this->organization = new Resources\Organizations($this); $this->recipients = new Resources\Recipients($this); + $this->routeplans = new Resources\Routeplans($this); $this->tasks = new Resources\Tasks($this); $this->teams = new Resources\Teams($this); $this->webhooks = new Resources\Webhooks($this); diff --git a/src/resources/Routeplans.php b/src/resources/Routeplans.php new file mode 100644 index 0000000..3b25a3b --- /dev/null +++ b/src/resources/Routeplans.php @@ -0,0 +1,23 @@ +defineTimeout(); + $this->endpoints([ + 'create' => ['method' => 'POST', 'path' => '/routePlans'], + 'get' => [ + 'method' => 'GET', 'path' => '/tasks/:routePlanId', 'altPath' => '/routePlanId', 'queryParams' => true + ], + 'update' => ['method' => 'PUT', 'path' => '/tasks/:routePlanId'], + 'deleteOne' => ['method' => 'DELETE', 'path' => '/tasks/:routePlanId'], + 'addTasksToRoutePlan' => ['method' => 'PUT','path'=> '/routePlans/:routePlanId/tasks'] + ]); + } +} diff --git a/tests/OnfleetTest.php b/tests/OnfleetTest.php index 1dcbb83..2f21c28 100644 --- a/tests/OnfleetTest.php +++ b/tests/OnfleetTest.php @@ -99,9 +99,9 @@ public function testRecipientByPhoneNumber($data) $curlClient->method('execute')->willReturn(["code" => 200, "success" => true, "data" => $data["getRecipients"]]); $onfleet = new Onfleet($data["apiKey"]); $onfleet->api->client = $curlClient; - $response = $onfleet->recipients->get('+18881787788', 'phone'); + $response = $onfleet->recipients->get('+18885557788', 'phone'); self::assertIsArray($response); - self::assertSame($response["phone"], "+18881787788"); + self::assertSame($response["phone"], "+18885557788"); self::assertFalse($response["skipSMSNotifications"]); } @@ -191,11 +191,11 @@ public function testUpdateWorker($data) $onfleet->api->client = $curlClient; $response = $onfleet->workers->update('Mdfs*NDZ1*lMU0abFXAT82lM', [ "name" => 'Stephen Curry', - "phone" => '+18883133131', + "phone" => '+18885553131', ]); self::assertIsArray($response); self::assertSame($response["name"], 'Stephen Curry'); - self::assertSame($response["phone"], '+18883033030'); + self::assertSame($response["phone"], '+18885553030'); } /** diff --git a/tests/Response.php b/tests/Response.php index c85d03a..986670b 100644 --- a/tests/Response.php +++ b/tests/Response.php @@ -13,7 +13,7 @@ "pathById" => 'https://onfleet.com/api/v2/admins/7p5Xl5HD1yG~xFqtIselXJjT', "pathWithEndpoint" => 'https://onfleet.com/api/v2/admins/phone/234564839', "parameters" => [ - "phone" => '4055157789', + "phone" => '4055557789', "state" => '0', ], "pathWithQuery" => 'https://onfleet.com/api/v2/admins?phone=4055157789&state=0', @@ -29,7 +29,7 @@ "type" => 'super', "name" => 'Onfleet Admin', "isActive" => true, - "phone" => '+18881881788', + "phone" => '+18885551788', ], [ "id" => 'hLedWP10pCKvDu7RIe2TfX~Q', @@ -38,7 +38,7 @@ "type" => 'standard', "name" => 'Onfleet wrapper', "isActive" => false, - "phone" => '+18881881789', + "phone" => '+18885551789', ], ], "get" => [ @@ -84,7 +84,7 @@ "id" => '9SY28MU8PYaPP9Iq10bcpBdL', "organization" => 'BxvqsKQBEeKGMeAsN09ScrVt', "name" => 'Onfleet Rocks', - "phone" => '+18881787788', + "phone" => '+18885557788', "skipSMSNotifications" => false, ], "createTeams" => [ @@ -132,7 +132,7 @@ "organization" => 'BxvqsKQBEeKGMeAsN09ScrVt', "name" => 'Stephen Curry', "displayName" => 'SC30', - "phone" => '+18883033030', + "phone" => '+18885553030', "activeTask" => null, "tasks" => [ 'ybB97MGXhGoAAKrUAlyywmBN', From edee4d1af3f47bf2c7230da5bcff953a13305997 Mon Sep 17 00:00:00 2001 From: Shuai Tseng Date: Fri, 26 Sep 2025 19:17:15 -0700 Subject: [PATCH 2/7] commit and sync --- src/resources/Routeplans.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resources/Routeplans.php b/src/resources/Routeplans.php index 3b25a3b..dccea41 100644 --- a/src/resources/Routeplans.php +++ b/src/resources/Routeplans.php @@ -19,5 +19,5 @@ public function __construct($api) 'deleteOne' => ['method' => 'DELETE', 'path' => '/tasks/:routePlanId'], 'addTasksToRoutePlan' => ['method' => 'PUT','path'=> '/routePlans/:routePlanId/tasks'] ]); - } + } } From 9f526f8bb57a005aa78446a0a7d5bf148c1da117 Mon Sep 17 00:00:00 2001 From: Shuai Tseng Date: Fri, 26 Sep 2025 20:48:47 -0700 Subject: [PATCH 3/7] fix paths and searches to align with the api doc --- src/Methods.php | 2 +- src/resources/Routeplans.php | 6 +++--- tests/Response.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Methods.php b/src/Methods.php index aabe1c1..1f52ffd 100644 --- a/src/Methods.php +++ b/src/Methods.php @@ -168,7 +168,7 @@ public static function method(array $methodData, Onfleet $api, ...$args) if ($errorCode === 2300) { throw new RateLimitError($errorInfo[0], $errorInfo[1] ?? '', $errorInfo[2], $errorInfo[3]); } else if ($errorCode <= 1108 && $errorCode >= 1100) { - throw new PermissionError($errorInfo[0], $errorInfo[1]['message]'] ?? '', $errorInfo[2], $errorInfo[3]); + throw new PermissionError($errorInfo[0], $errorInfo[1]['message'] ?? '', $errorInfo[2], $errorInfo[3]); } else if ($errorCode >= 2500) { throw new ServiceError($errorInfo[0], $errorInfo[1] ?? '', $errorInfo[2], $errorInfo[3]); } else if ($errorCode === 2218) { // Precondition error for Auto-Dispatch diff --git a/src/resources/Routeplans.php b/src/resources/Routeplans.php index dccea41..7d558e7 100644 --- a/src/resources/Routeplans.php +++ b/src/resources/Routeplans.php @@ -13,10 +13,10 @@ public function __construct($api) $this->endpoints([ 'create' => ['method' => 'POST', 'path' => '/routePlans'], 'get' => [ - 'method' => 'GET', 'path' => '/tasks/:routePlanId', 'altPath' => '/routePlanId', 'queryParams' => true + 'method' => 'GET', 'path' => '/routePlans/:routePlanId', 'altPath' => '/routePlanId', 'queryParams' => true ], - 'update' => ['method' => 'PUT', 'path' => '/tasks/:routePlanId'], - 'deleteOne' => ['method' => 'DELETE', 'path' => '/tasks/:routePlanId'], + 'update' => ['method' => 'PUT', 'path' => '/routePlans/:routePlanId'], + 'deleteOne' => ['method' => 'DELETE', 'path' => '/routePlans/:routePlanId'], 'addTasksToRoutePlan' => ['method' => 'PUT','path'=> '/routePlans/:routePlanId/tasks'] ]); } diff --git a/tests/Response.php b/tests/Response.php index 986670b..5fd5733 100644 --- a/tests/Response.php +++ b/tests/Response.php @@ -13,7 +13,7 @@ "pathById" => 'https://onfleet.com/api/v2/admins/7p5Xl5HD1yG~xFqtIselXJjT', "pathWithEndpoint" => 'https://onfleet.com/api/v2/admins/phone/234564839', "parameters" => [ - "phone" => '4055557789', + "phone" => '4055157789', "state" => '0', ], "pathWithQuery" => 'https://onfleet.com/api/v2/admins?phone=4055157789&state=0', From 3a0964964840972e5c019eee0aa7a2697e6e4b01 Mon Sep 17 00:00:00 2001 From: Shuai Tseng Date: Fri, 26 Sep 2025 20:50:31 -0700 Subject: [PATCH 4/7] fixed spelling --- src/resources/Routeplans.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resources/Routeplans.php b/src/resources/Routeplans.php index 7d558e7..6f1c816 100644 --- a/src/resources/Routeplans.php +++ b/src/resources/Routeplans.php @@ -20,4 +20,4 @@ public function __construct($api) 'addTasksToRoutePlan' => ['method' => 'PUT','path'=> '/routePlans/:routePlanId/tasks'] ]); } -} +} \ No newline at end of file From 701e40967c0a7919aed4cae57ed5efb6e734e12c Mon Sep 17 00:00:00 2001 From: Shuai Tseng Date: Mon, 29 Sep 2025 18:49:08 -0700 Subject: [PATCH 5/7] added break line to prevent POSIX problems --- src/resources/Routeplans.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resources/Routeplans.php b/src/resources/Routeplans.php index 6f1c816..7d558e7 100644 --- a/src/resources/Routeplans.php +++ b/src/resources/Routeplans.php @@ -20,4 +20,4 @@ public function __construct($api) 'addTasksToRoutePlan' => ['method' => 'PUT','path'=> '/routePlans/:routePlanId/tasks'] ]); } -} \ No newline at end of file +} From 187741d6ee5ab366bcdb416daa4bd6c4f559a077 Mon Sep 17 00:00:00 2001 From: Shuai Tseng Date: Thu, 2 Oct 2025 18:44:13 -0700 Subject: [PATCH 6/7] found an error during test and updated the correct url path --- src/resources/Routeplans.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resources/Routeplans.php b/src/resources/Routeplans.php index 7d558e7..052bffa 100644 --- a/src/resources/Routeplans.php +++ b/src/resources/Routeplans.php @@ -13,7 +13,7 @@ public function __construct($api) $this->endpoints([ 'create' => ['method' => 'POST', 'path' => '/routePlans'], 'get' => [ - 'method' => 'GET', 'path' => '/routePlans/:routePlanId', 'altPath' => '/routePlanId', 'queryParams' => true + 'method' => 'GET', 'path' => '/routePlans/:routePlanId', 'altPath' => '/routePlans', 'queryParams' => true ], 'update' => ['method' => 'PUT', 'path' => '/routePlans/:routePlanId'], 'deleteOne' => ['method' => 'DELETE', 'path' => '/routePlans/:routePlanId'], From ab6a717d80f50fa734f95d9c36aff15be914d92b Mon Sep 17 00:00:00 2001 From: Shuai Tseng Date: Thu, 9 Oct 2025 13:48:39 -0700 Subject: [PATCH 7/7] updated readme files --- README.es.md | 1 + README.md | 1 + 2 files changed, 2 insertions(+) diff --git a/README.es.md b/README.es.md index 76833fd..f933045 100644 --- a/README.es.md +++ b/README.es.md @@ -87,6 +87,7 @@ Estas son las operaciones disponibles para cada endpoint: | [Hubs](https://docs.onfleet.com/reference#hubs) | get() | create(obj) | update(id, obj) | x | | [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 | +| [Route Plans](https://docs.onfleet.com/update/reference/routeplan#/) | get(id)
get(query) | create(obj) | update(id, obj)
addTasksToRoutePlan(id, obj) | deleteOne(id) | | [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), 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) | diff --git a/README.md b/README.md index 4f22392..dd57854 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,7 @@ Here are the operations available for each entity: | [Hubs](https://docs.onfleet.com/reference#hubs) | get() | create(obj) | update(id, obj) | x | | [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 | +| [Route Plans](https://docs.onfleet.com/update/reference/routeplan#/) | get(id)
get(query) | create(obj) | update(id, obj)
addTasksToRoutePlan(id, obj) | deleteOne(id) | | [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), 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) |