社会事件/webex事件PHP SDK
Webex事件PHP SDK 查看更多信息:https://github.com/SocioEvents/webex-events-php-sdk
Requires
- php: ^8.1
- ext-curl: *
- ext-json: *
Requires (Dev)
- mockery/mockery: 2.0.x-dev
- phpunit/phpunit: ^10
This package is not auto-updated.
Last update: 2024-09-25 14:46:25 UTC
README
Webex事件API PHP SDK
Webex事件提供了一系列SDK,以加速您的开发过程。它们允许开发者以标准化的方式与功能和特性进行交互和利用。预构建的代码模块将帮助您使用私有密钥访问API,简化数据收集和更新流程。
要求
- PHP ^8.1
安装
通过命令行
composer require socioevents/webex-events-php-sdk
配置
Configuration::setAccessToken('access token'); Configuration::setLogger($logger); // implement your logger via LoggerInterface, default is off Configuration::setMaxRetries(3); //optional default 3 Configuration::setReadTimeoutSeconds(30); //optional default 30 sec Configuration::setConnectTimeoutSeconds(10); //optional default 10 sec
使用
$query = 'query EventsConnection($first: Int) { eventsConnection(first: $first){ edges{ cursor node{ id name } } } }'; $variables = ["first" => 100]; $requestOptions = new RequestOptions(Helpers::generateUUID()); $response = Client::query($query, 'eventsConnection', $variables, $requestOptions ); $data = $response->getJsonResponseBody()['data'];
如果请求成功,WebexEvents\Client.query
将返回包含以下方法的WebexEvents\Response
对象。
对于非200状态码,每个状态码(如针对服务器错误的WebexEvents\Errors\ServerError
)都会引发异常。对于流控制,应按以下方式处理这些异常。以下是一个针对429
状态码的示例。完整列表请参阅此文件。
try { $response = Client::query($query, $operationName, $variables, $requestOptions); } catch (DailyQuotaIsReachedError $e) { // do someteging here } catch (SecondBasedQuotaIsReachedError $e){ $sleepTime = $e->getResponse()->getRateLimiter()->getSecondlyRetryAfterInMs(); usleep($sleepTime * 1000); // do retry }
默认情况下,Webex::Client.query
内部具有重试策略。它会根据Configuration::getMaxRetries()
重试以下异常。
WebexEvents\Errors\RequestTimeoutError => 408
WebexEvents\Errors\ConflictError => 409
WebexEvents\Errors\SecondBasedQuotaIsReachedError => 429
WebexEvents\Errors\BadGatewayError => 502
WebexEvents\Errors\ServiceUnavailableError => 503
WebexEvents\Errors\GatewayTimeoutError => 504
用于内省
WebexEvents\Client.doIntrospectionQuery()
幂等性
API支持幂等性,以确保在安全重试请求时不会意外执行相同的操作两次。在进行突变请求时,请使用幂等性密钥。如果发生连接错误,您可以重复请求而无需担心创建第二个对象或执行更新两次。
要执行突变请求,您必须添加一个包含幂等性密钥的标题,例如Idempotency-Key: <your key>
。如果缺少幂等性密钥,SDK不会为您生成。以下是一个示例:
$mutation = 'mutation ComponentCreate($input: ComponentCreateInput!) { componentCreate(input: $input) { eventId featureTypeId id name } }'; $mutationVariables = [ "input" => [ "eventId" => 1, "featureTypeId" => 6, "name" => "Speakers", "pictureUrl"=>'https://webexevents.com/media_test.jpeg', "settings" => [ "displayMethod" => "GRID", "isHidden" => false ] ] ]; try { $response = Client::query( $mutation, 'ComponentCreate', $mutationVariables, new RequestOptions(Helpers::generateUUID()) ); } catch (ConflictError $e) { // Conflict errors will be retried, but to guarantee it you can handle the exception again. usleep(20000); // do retry }
遥测数据收集
Webex事件通过API请求收集遥测数据,包括主机名、操作系统、语言和SDK版本。这些信息使我们能够改进我们的服务并跟踪任何使用相关的故障/问题。我们高度重视您的隐私,处理所有数据。有关更多详细信息,请参阅隐私政策。
开发
检出仓库后,运行composer install
安装依赖项。然后,运行./vendor/bin/phpunit tests
以运行测试。
贡献
请参阅贡献指南。
许可
该软件库作为开源软件根据MIT许可证提供。
行为准则
所有在Webex事件API项目的代码库、问题跟踪器、聊天室和邮件列表中互动的人预期都要遵守行为准则。