bixev / intervention-sdk
BixevIntervention API SDK
Requires
- php: >=5.3
- bixev/light-logger: >=1.0.0
README
此SDK旨在帮助您处理BixevIntervention API
安装
建议您使用Composer安装InterventionSDK。
composer require bixev/intervention-sdk "~1.0"
这将安装SDK及其所有必需的依赖项。
因此,您每个PHP脚本都需要引入composer自动加载文件
<?php require 'vendor/autoload.php';
使用方法
可用的服务包括
- Intervention(搜索、创建、更新、读取)
- InterventionType(getAvailable)
- ScheduleWizard(getSlots)
API初始化
使用您的访问URL初始化API
$autoconfigUrl = 'https://api.intervention.bixev.com/connectors/XXX/YYYYYYYYY';
$bixevInterventionAPI = \Bixev\InterventionSdk\InterventionApi::init($autoconfigUrl);
Intervention服务
您可以直接从api $bixevInterventionAPI->services
访问服务
$interventionService = $bixevInterventionAPI->services->newServiceIntervention();
搜索干预措施
检索SearchInput
对象以设置所有必要的输入参数
$searchInput = $interventionService->newSearchInput(); $searchInput->status = \Bixev\InterventionSdk\Model\Intervention::STATUS_PENDING;
在interventionService
上使用search
方法以获取您的干预措施
$result = $interventionService->search($searchInput);
返回结果为\Bixev\InterventionSdk\Model\Response\Interventions
实例
echo $results->pagination->returned . " results returned\n"; foreach ($results->interventions as $intervention) { echo "Intervention cref : " . $intervention->cref . "\n"; }
一站式搜索干预措施
// initialize api $autoconfigUrl = 'https://api.intervention.bixev.com/connectors/XXX/YYYYYYYYY'; $bixevInterventionAPI = \Bixev\InterventionSdk\InterventionApi::init($autoconfigUrl); // get service $interventionService = $bixevInterventionAPI->services->newServiceIntervention(); // get input $searchInput = $interventionService->newSearchInput(); $searchInput->status = \Bixev\InterventionSdk\Model\Intervention::STATUS_PENDING; // call method $result = $interventionService->search($searchInput); // process results echo $results->pagination->returned . " results returned\n"; foreach ($results->interventions as $intervention) { echo "Intervention cref : " . $intervention->cref . "\n"; }
读取/创建/更新干预措施
实例化新的intervention模型
$intervention = $bixevInterventionAPI->models->newModelIntervention();
cref
字段是必需的(用于设置或检索唯一干预信息),这是YOUR干预唯一标识符
$intervention->cref = 'myCustomInterventionReference';
读取干预措施数据
$result = $interventionService->read($intervention);
通过cref找到干预措施
创建或更新干预措施
如果需要,您可以实例化新的customer模型
。 customer type/reference
字段是作为唯一标识符必需的
$intervention->customer = $bixevInterventionAPI->models->newModelCustomer(); $intervention->customer->type = \Bixev\InterventionSdk\Model\Customer::CUSTOMER_TYPE_COMPANY; $intervention->customer->reference = 'customerReference';
创建
$result = $interventionService->create($intervention);
如果已经存在具有cref的干预措施,则将其更新
更新
$result = $interventionService->update($intervention);
通过cref找到干预措施
干预措施和客户字段来自相应的类。它们是
$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
InterventionType服务
您可以检索您的可用intervention类型
。如果您有多个,则创建干预措施时将需要指定您想要哪一个。
$interventionTypeService = $bixevInterventionAPI->services->newServiceInterventionType(); $result = $interventionTypeService->getAvailable();
调度向导服务
要获取可用的分配时段,请使用ScheduleWizard
!!!
检索ScheduleWizardInput
对象以设置所有必要的输入参数
$scheduleWizardService = $bixevInterventionAPI->services->newServiceScheduleWizard(); $scheduleWizardInput = $scheduleWizardService->newWizardInput(); $scheduleWizardInput->address = '7 rue de la Dordogne Toulouse';
在scheduleWizardService
上使用getSlots
方法以获取可用时段
$result = $scheduleWizardService->getSlots($scheduleWizardInput);
返回结果为\Bixev\InterventionSdk\Model\Response\ScheduleWizard\ScheduleWizard
实例
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; }
调度向导获取选项
$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)
日志
您可以使用此SDK中的日志记录器对象。它只需实现\Bixev\LightLogger\LoggerInterface
class MyLogger implements \Bixev\LightLogger\LoggerInterface { public function log($log) { print_r($log); } }
然后将它传递给您的API初始化
$logger = new MyLogger; $bixevInterventionAPI = \Bixev\InterventionSdk\InterventionApi::init($autoconfigUrl, $logger);
覆盖路由
您可以使用强制路由的方式使SDK连接到API(不使用autoconfig或覆盖)
路由在客户端级别
$client = $bixevInterventionAPI->getClient(); $routes = $client->getRoutes();
因此,您可以简单地设置自己的路由集。一个路由必须扩展\Bixev\InterventionSdk\Model\Routes\Route
$route = new \Bixev\InterventionSdk\Model\Routes\Route; $route->identifier = \Bixev\InterventionSdk\Model\Routes\Route::IDENTIFIER_INTERVENTION_LIST; $route->method = \Bixev\InterventionSdk\Client\Curl::METHOD_GET; $route->url = 'http://mycutomdomain/mycutomroute'; $routes[] = $route;