Wallogit.com
2017 © Pedro Peláez
Cadulis API SDK
This SDK aims to help you dealing with Cadulis APIs, (*1)
It's recommended that you use Composer to install InterventionSDK., (*2)
composer require cadulis/sdk "~1.0"
This will install SDK and all required dependencies., (*3)
so each of your php scripts need to require composer autoload file, (*4)
<?php require 'vendor/autoload.php';
Available services are, (*5)
Initialize api with your access url, (*6)
$autoconfigUrl = 'https://api.cadulis.com/connectors/XXX/YYYYYYYYY';
$cadulisAPI = \Cadulis\Sdk\InterventionApi::init($autoconfigUrl);
You can access services directly from the api $cadulisAPI->services, (*7)
$cadulisSdkService = $cadulisAPI->services->newServiceIntervention();
Retrieve the SearchInput object to set all-what-you-need input parameters, (*8)
$searchInput = $cadulisSdkService->newSearchInput(); $searchInput->status = \Cadulis\Sdk\Model\Intervention::STATUS_PENDING;
Use the search method on the interventionService to get your interventions, (*9)
$result = $interventionService->search($searchInput);
Returned result is instance of \Cadulis\Sdk\Model\Response\Interventions, (*10)
echo $results->pagination->returned . " results returned\n";
foreach ($results->interventions as $intervention) {
echo "Intervention cref : " . $intervention->cref . "\n";
}
All in one to search interventions :, (*11)
// initialize api
$autoconfigUrl = 'https://api.cadulis.com/connectors/XXX/YYYYYYYYY';
$cadulisAPI = \Cadulis\Sdk\InterventionApi::init($autoconfigUrl);
// get service
$cadulisSdkService = $cadulisAPI->services->newServiceIntervention();
// get input
$searchInput = $cadulisSdkService->newSearchInput();
$searchInput->status = \Cadulis\Sdk\Model\Intervention::STATUS_PENDING;
// call method
$result = $cadulisSdkService->search($searchInput);
// process results
echo $results->pagination->returned . " results returned\n";
foreach ($results->interventions as $intervention) {
echo "Intervention cref : " . $intervention->cref . "\n";
}
Instanciate new intervention model, (*12)
$intervention = $cadulisAPI->models->newModelIntervention();
cref field is required (to set or retrieve unique intervention informations), this is YOUR intervention unique identifier, (*13)
$intervention->cref = 'myCustomInterventionReference';
$result = $interventionService->read($intervention);
Intervention is find by cref, (*14)
If needed you can instanciate new customer model. customer type/reference fields are required as unique identifier, (*15)
$intervention->customer = $cadulisAPI->models->newModelCustomer(); $intervention->customer->type = \Cadulis\Sdk\Model\Customer::CUSTOMER_TYPE_COMPANY; $intervention->customer->reference = 'customerReference';
Create :, (*16)
$result = $interventionService->create($intervention);
If intervention with cref already exists, it is updated, (*17)
Update :, (*18)
$result = $interventionService->update($intervention);
Intervention is find by cref, (*19)
Intervention and customer fields are available from corresponding classes. They are :, (*20)
$intervention->cref // unique identifier $intervention->reference $intervention->address $intervention->address_additional $intervention->comment $intervention->duration // seconds $intervention->scheduled_start_at // ISO 8601 format, can be set by $intervention->setScheduledStart($date) $intervention->custom_fields // associative array of $key => $value additional fields $customer->reference $customer->type $customer->name $customer->address $customer->address_additional $customer->phone $customer->mobile $customer->email $customer->comment
you can retrieve your available intervention types. If you have multiple ones, creating intervention will required which one you want., (*21)
$interventionTypeService = $cadulisAPI->services->newServiceInterventionType(); $result = $interventionTypeService->getAvailable();
To get available assignment slots, use ScheduleWizard !!!, (*22)
Retrieve the ScheduleWizardInput object to set all-what-you-need input parameters, (*23)
$scheduleWizardService = $cadulisAPI->services->newServiceScheduleWizard(); $scheduleWizardInput = $scheduleWizardService->newWizardInput(); $scheduleWizardInput->address = '7 rue de la Dordogne Toulouse';
Use the getSlots method on the scheduleWizardService to get available slots, (*24)
$result = $scheduleWizardService->getSlots($scheduleWizardInput);
Returned result is instance of \Cadulis\Sdk\Model\Response\ScheduleWizard\ScheduleWizard, (*25)
echo count($result) . ' dates returned' . "\n";
echo 'best slot : ';
$bestSlot = $result->getBestSlot();
if ($bestSlot === null) {
echo "No slot available";
} else {
echo "Best slot : " . $bestSlot->date;
}
Schedule Wizard get options are :, (*26)
$scheduleWizardInput->address $scheduleWizardInput->date_min // ISO 8601 format, can be set by $intervention->setDateMin($date) $scheduleWizardInput->date_max // ISO 8601 format, can be set by $intervention->setDateMax($date)
You can use a logger object within this sdk. It has just to implement \Bixev\LightLogger\LoggerInterface, (*27)
class MyLogger implements \Bixev\LightLogger\LoggerInterface
{
public function log($log)
{
print_r($log);
}
}
Then pass it to your api initialization :, (*28)
$logger = new MyLogger; $cadulisAPI = \Cadulis\Sdk\InterventionApi::init($autoconfigUrl, $logger);
You're able to force routes the sdk use to connect to the api (no use of autoconfig, or override), (*29)
Routes are on client level :, (*30)
$client = $cadulisAPI->getClient(); $routes = $client->getRoutes();
So you can simply set your own set of routes. A route must extend \Cadulis\Sdk\Model\Routes\Route, (*31)
$route = new \Cadulis\Sdk\Model\Routes\Route; $route->identifier = \Cadulis\Sdk\Model\Routes\Route::IDENTIFIER_INTERVENTION_LIST; $route->method = \Cadulis\Sdk\Client\Curl::METHOD_GET; $route->url = 'http://mycutomdomain/mycutomroute'; $routes[] = $route;