simtabi / netsapiens-api
一个用于调用 NetSapiens REST API 的 PHP 库
dev-master
2023-03-13 17:33 UTC
Requires
- php: >=8.0
- guzzlehttp/guzzle: >=7.5.0
- phpfastcache/phpfastcache: >=9.1.3
Requires (Dev)
- phpunit/phpunit: >=9.0
This package is auto-updated.
Last update: 2024-09-13 21:09:06 UTC
README
NetSapiens REST API 客户端
一个用于调用 NetSapiens API 的 PHP REST API 客户端 (http://netsapiens.com)。
API 专用文档可在 ns-api API 参考 网站上找到。
功能
- REST API 客户端
- 命令行客户端 — 即将推出
安装
您可以通过 composer 安装此软件包
composer require simtabi/netsapiens
用法
use Simtabi\NetSapiens\NetSapiens; use Simtabi\NetSapiens\Helpers\Helpers; // API auth credentials $clientId = ''; // your client id $clientSecret = ''; // your client secret $username = ''; // your username $password = ''; // your password $baseUrl = ''; // i.e https://api.netsapiens.com/ $guzzleConfig = []; // Guzzle HTTP client configuration // Path to store cache files $cachePath = ''; // path to where the cache would be stored // Initialize the API client try { return NetSapiens::getInstance( clientId : $clientId, clientSecret : $clientSecret, username : $username, password : $password, baseUrl : $baseUrl, cacher : function (array $args) use ($cachePath) { $cacheData = $args[0]; $cacheId = $args[1]; return Helpers::cacher( items : $cacheData, cacheId: $cacheId, cachePath : $cachePath, lifeTimeInSeconds: Helpers::CACHE_LIFETIME_IN_SECONDS, resetCache: true, ); }, guzzleConfig : $guzzleConfig ); } catch (NetSapiensException $exception) { // do something if we encountered errors echo $exception->getMessage(); } // you can access resource specific error by calling the following method
访问 Authentication
对象实例
$oAuth2 = $netSapiensClient->getOAuth2();
访问 OAuth2
调用期间遇到的所有错误
$errors = $netSapiensClient->getOAuth2()->getErrors();
使用辅助方法
$netSapiensClient = netSapiensClient($clientId, $clientSecret, $username, $password, $baseUrl, $cacher, $guzzleConfig); // returns a NetSapiens instance or a string if there were errors found
注意
如果您不想使用默认的缓存机制,则 cacher
接受一个 回调函数
,您可以在其中传递自定义的缓存实现。
可用资源
标记为绿色的资源已准备好使用。
1. 创建呼叫队列
// Call queue details $phoneNumber = ''; $queue = ''; $uid = ''; // Create a call queue $newCallQueue = $netSapiensClient ->getCallQueue() ->setQueue($queue) ->setUid($uid) ->create($phoneNumber);
仅在使用辅助函数时使用 $netSapiensClient instanceof NetSapiens
。例如
if($netSapiensClient instanceof NetSapiens) { $newCallQueue = $netSapiensClient ->getCallQueue() ->setQueId($queue) ->setUid($uid) ->create($phoneNumber); if ($newCallQueue) { // do something if successful } } else { // do something if we have errors }
访问 Request
对象实例
这只能在发出资源请求后实现。例如,您可以在创建呼叫队列后访问 Request
实例。
$callQueue = $netSapiensClient->getCallQueue()->setQueue($queue)->setUid($uid); $callNumber = $callQueue->create($phoneNumber); $errors = $callQueue->getRequest()->getErrors();
如果您不想使用默认的缓存机制,则 cacher
接受一个 回调函数
,您可以在其中传递自定义的缓存实现。
测试
composer test
变更日志
请参阅 CHANGELOG 了解最近更改的信息。
贡献
请参阅 CONTRIBUTING 了解详细信息。
安全性
如果您发现任何安全相关的问题,请通过电子邮件发送至 io@io.com,而不是使用问题跟踪器。
鸣谢
许可证
MIT 许可证 (MIT)。请参阅 许可证文件 了解更多信息。