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) | diff --git a/src/Methods.php b/src/Methods.php index 8eebe80..1f52ffd 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..052bffa --- /dev/null +++ b/src/resources/Routeplans.php @@ -0,0 +1,23 @@ +defineTimeout(); + $this->endpoints([ + 'create' => ['method' => 'POST', 'path' => '/routePlans'], + 'get' => [ + 'method' => 'GET', 'path' => '/routePlans/:routePlanId', 'altPath' => '/routePlans', 'queryParams' => true + ], + 'update' => ['method' => 'PUT', 'path' => '/routePlans/:routePlanId'], + 'deleteOne' => ['method' => 'DELETE', 'path' => '/routePlans/: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..5fd5733 100644 --- a/tests/Response.php +++ b/tests/Response.php @@ -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',