dant89 / ix-api-client
IX-API项目的PHP客户端。
2.0.2
2023-08-30 11:06 UTC
Requires
- php: ^8.1
- ext-json: *
- symfony/http-client: ^4.3
Requires (Dev)
- phpmd/phpmd: ^2.7
- phpunit/phpunit: ^9.0
- squizlabs/php_codesniffer: ^3.4
This package is auto-updated.
Last update: 2024-09-30 01:26:56 UTC
README
一个轻量级的PHP API客户端,用于IX-API。
安装
要安装,请在项目的根目录下运行 composer require dant89/ix-api-client,或将 dant89/ix-api-client 添加到您的 composer.json 文件中。
查看标记版本,以选择此客户端的 v1 和 v2 实现。
"require": { "dant89/ix-api-client": "^LATEST_VERSION_TAG" }
用法
使用提供的密钥/密钥凭证和指定的实现者URL进行认证,然后设置一个bearer token。
use Dant89\IXAPIClient\Client; // Create base client $client = new Client(IXAPI_URL); // Get a bearer token from key / secret $response = $client->getHttpClient(HttpClientType::AUTH) ->postAuthToken(IXAPI_KEY, IXAPI_SECRET); // Check for valid response status if ($response->getStatus() === 200) { $client->setBearerToken($response->getContent()['access_token']); }
设置bearer token后,您可以返回所有需要认证的端点的数据。
获取产品提供
// Query for products $response = $client->getHttpClient(HttpClientType::PRODUCT_OFFERINGS) ->get(); // Check for valid response and set the array of products if ($response->getStatus() === 200) { $productOfferings = $response->getContent(); }
方法支持和过滤器
所有基础客户端都支持 get、delete、post、patch。
在支持的情况下,还有其他方法可用,例如 getStatistics、getLoa。
$singleItem = $client->getHttpClient(HttpClientType::CONTACTS) ->get('item-uuid') ->getContent(); $filteredItems = $client->getHttpClient(HttpClientType::CONTACTS) ->get(null, ['managing_account' => 'uuid-123']) ->getContent(); $response = $client->getHttpClient(HttpClientType::CONTACTS) ->post([ 'managing_account' => 'uuid-123', 'consuming_account' => 'uuid-456', 'name' => 'sample contact', ]); $client->getHttpClient(HttpClientType::CONTACTS) ->patch('item-uuid', [ 'name' => 'renamed sample contact', ]); $client->getHttpClient(HttpClientType::CONTACTS) ->delete('item-uuid'); // Query for connections timeseries data $timeseries = $client->getHttpClient(HttpClientType::CONNECTIONS) ->getStatisticTimeseries('connection-123-uuid', '30d') ->getContent();
认证
您需要联系交易所以创建API密钥/密钥组合,并找出他们的IX-API实现URL。
问题
问:IX-API是符合OpenAPI 3的,为什么我不使用像Swagger Codegen这样的工具来创建客户端?
答:请这么做!这个客户端设计得非常轻量级,您可以用来入门、构建和实验。由自动工具生成的客户端,如Swagger Codegen,可能会有更深入和丰富的功能,可能满足您应用程序的需求。
贡献
欢迎为客户端做出贡献,要贡献请
- 此仓库
- 创建您的功能分支
- 提交您的更改
- 将更改推送到分支
- 创建一个新的pull request