lexonouri / serwisant-api
https://serwisant.online服务的API客户端
3.0.5
2020-09-11 12:43 UTC
Requires
- ext-json: *
- guzzlehttp/guzzle: ^6.5
README
安装
要在composer环境中安装此包,请使用
composer require lexonouri/serwisant-api
要求
- PHP 7.2或更高版本
- ext-mbstring
- ext-curl
关于版本号的说明
SDK的版本控制非常重要。它看起来像3.<major>.<minor>,例如3.0.1。当您将SDK包含到composer配置中时,强烈建议将主要版本设置为固定,例如
"require": {
"lexonouri/serwisant-api": "3.0.*"
},
这很重要,因为涉及到类型查询和突变。如果模式发生变化,传递给查询和突变的参数也将发生变化。这可以是新必需的参数,甚至参数的顺序也可能改变。在这种情况下,SDK将发布带有增加的主要版本的版本。如果您决定升级,可能会破坏您的应用程序。
您已被警告。
对此有一个单一例外。internal模式不是供公众使用的。破坏性更改将排除在上面的规则之外。
使用说明
首先,准备一个API实例供以后使用,它应该在整个应用程序中共享
use Serwisant\SerwisantApi; // get own client and secret by creating an application via webpage // 4th argument is a access token cache, it's optional, but recommended for performance reasons $access_token = new SerwisantApi\AccessTokenOauth('client', 'secret', 'public', (new SerwisantApi\AccessTokenContainerFile)); $api = new SerwisantApi\Api(); $api->setAccessToken($access_token);
带有内联查询的基本示例
/* please note __typename at each type - it's required for proper typecast */ $query = ' query($token: String!) { repairByToken(token: $token) { __typename displayName status { __typename displayName } } }'; /* @var SerwisantApi\Types\SchemaPublic\Repair $repair */ $repair = $api->publicQuery()->newRequest()->set($query, ['token' => 'abc-def'])->execute()->fetch(); echo $repair->displayName; echo $repair->status->displayName;
带有批量查询的示例 - 为了性能原因,尽可能多地使用批量。批量查询可以减少HTTP流量。
/* please note __typename at each type - it's required for proper typecast */ $query = ' query($token: String!) { repair: repairByToken(token: $token) { __typename displayName } me: viewer { __typename employee { __typename displayName } } }'; $result = $api->publicQuery()->newRequest()->set($query, ['token' => 'abc-def'])->execute(); $repair = $result->fetch('repair'); $me = $result->fetch('me'); echo $repair->displayName; echo $me->displayName;