ihasco / client-api-sdk
此包已被废弃且不再维护。未建议替代包。
此包的最新版本(dev-master)没有可用的许可证信息。
客户端API SDK
dev-master
2015-11-27 09:52 UTC
Requires
- php: >=5.3.3
- lib-curl: *
Requires (Dev)
- mockery/mockery: ^0.9.4
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2024-07-24 18:33:26 UTC
README
创建一个新的实例
$ihasco = Ihasco\ClientSDK\Manager::create('your-api-key');
所有对API的调用都将返回一个 Ihasco\ClientSDK\Responses\Response
对象,或者抛出一个 Ihasco\ClientSDK\Exceptions\Exception
。
项目
所有项目
$response = $ihasco->programmes->all(); $allProgrammes = $response->getData();
返回一个包含 Ihasco\ClientSDK\Responses\Programme
对象的数组
一个项目
$response = $ihasco->programmes->one(int $programmeId); $oneProgramme = $response->getData();
返回一个单一的 Ihasco\ClientSDK\Responses\Programme
对象
结果
所有结果
$response = $ihasco->results->all(); $allResults = $response->getData();
返回一个包含 Ihasco\ClientSDK\Responses\Result
对象的数组
一个结果
$response = $ihasco->results->one(int $resultId); $oneResult = $response->getData();
返回一个单一的 Ihasco\ClientSDK\Responses\Result
对象
用户
所有用户
$response = $ihasco->users->all(); $allUsers = $response->getData();
返回一个包含 Ihasco\ClientSDK\Responses\User
对象的数组
一个用户
提供一个userId或电子邮件地址
$response = $ihasco->users->one(mixed $userId); $oneUser = $response->getData();
返回一个单一的 Ihasco\ClientSDK\Responses\User
对象
用户结果
$response = $ihasco->users->results(mixed $resultId, int $cursor = null); $allResults = $response->getData();
返回一个包含 Ihasco\ClientSDK\Responses\Result
对象的数组
创建用户
按照 API规范 发送数据
$response = $ihasco->users->create(array $userData); $oneUser = $response->getData();
返回一个单一的 Ihasco\ClientSDK\Responses\User
对象
编辑用户
按照 API规范 发送数据
$response = $ihasco->users->update(int $userId, array $userData); $oneUser = $response->getData();
返回一个单一的 Ihasco\ClientSDK\Responses\User
对象
删除用户
$response = $users->delete(int $id);
响应异常
除了2xx响应之外的所有响应都将抛出 Ihasco\ClientSDK\Exceptions\Exception
。可能的异常如下
try { $response = $ihasco->programmes->all(); } catch(Ihasco\ClientSDK\Exceptions\CannotConnect $e) { // Cannot connect to server } catch(Ihasco\ClientSDK\Exceptions\CannotAuthenticate $e) { // Bad API key } catch(Ihasco\ClientSDK\Exceptions\InvalidResource $e) { // Non-existent resource } catch(Ihasco\ClientSDK\Exceptions\ServerError $e) { // Something went wrong on the server } catch(Ihasco\ClientSDK\Exceptions\BadMethod $e) { // Invalid HTTP method } catch(Ihasco\ClientSDK\Exceptions\ValidationError $e) { // Something wrong with your submission var_dump($e->getErrors()); } catch(Exception $e) { // something else }
分页
$hasPagination = $response->hasPagination(); // boolean $nextPage = $response->getNextPage(); // Response or null $prevPage = $response->getPrevPage(); // Response or null