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
1 change: 1 addition & 0 deletions README.es.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)<br />get(query) | create(obj) | update(id, obj)<br />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) |
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)<br />get(query) | create(obj) | update(id, obj)<br />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) |
Expand Down
14 changes: 7 additions & 7 deletions src/Methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Onfleet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
23 changes: 23 additions & 0 deletions src/resources/Routeplans.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Onfleet\resources;

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

public function __construct($api)
{
parent::__construct($api);
$this->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']
]);
}
}
8 changes: 4 additions & 4 deletions tests/OnfleetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);
}

Expand Down Expand Up @@ -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');
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"type" => 'super',
"name" => 'Onfleet Admin',
"isActive" => true,
"phone" => '+18881881788',
"phone" => '+18885551788',
],
[
"id" => 'hLedWP10pCKvDu7RIe2TfX~Q',
Expand All @@ -38,7 +38,7 @@
"type" => 'standard',
"name" => 'Onfleet wrapper',
"isActive" => false,
"phone" => '+18881881789',
"phone" => '+18885551789',
],
],
"get" => [
Expand Down Expand Up @@ -84,7 +84,7 @@
"id" => '9SY28MU8PYaPP9Iq10bcpBdL',
"organization" => 'BxvqsKQBEeKGMeAsN09ScrVt',
"name" => 'Onfleet Rocks',
"phone" => '+18881787788',
"phone" => '+18885557788',
"skipSMSNotifications" => false,
],
"createTeams" => [
Expand Down Expand Up @@ -132,7 +132,7 @@
"organization" => 'BxvqsKQBEeKGMeAsN09ScrVt',
"name" => 'Stephen Curry',
"displayName" => 'SC30',
"phone" => '+18883033030',
"phone" => '+18885553030',
"activeTask" => null,
"tasks" => [
'ybB97MGXhGoAAKrUAlyywmBN',
Expand Down