droath / recurly_client
Recurly REST API 服务。
dev-master
2015-04-03 16:23 UTC
Requires
- php: >=5.4.0
- guzzlehttp/guzzle: ~5.2
- symfony/serializer: ~2.6
Requires (Dev)
- phpunit/phpunit: ~4.5
This package is not auto-updated.
Last update: 2024-09-14 16:34:43 UTC
README
Recurly Client 库允许您简单地与 Recurly.com 提供的公开 RESTful API 服务进行交互。
我们使用 PHP Guzzle 库来构建可用的 Recurly 网络服务的 HTTP 请求。这将给我们机会利用 Guzzle 和其可插拔的 HTTP 适配器。希望这将为处理 Recurly 网络服务提供更丰富的功能体验。
要求
该 PHP 库依赖于 PHP 5.4 或更高版本。
注意:目前我们不支持 PHP:hhvm,因为 HHVM 并未完全支持 SimpleXMLIterator 类。
安装
Composer
如果您正在使用 Composer,您只需将依赖项 droath/recurly_client
添加到您的项目 composer.json 文件中。以下是 composer.json 的片段。
{
"require": {
"droath/recurly_client": "*"
}
}
用法
配置
设置 Recurly API 密钥和子域,这些在您的 Recurly 账户 中定义。
<?php $config = new \RecurlyClient\Config( 'abcdef01234567890abcdef01234567890', 'your-subdomain' ); $client = new \RecurlyClient\Client($config);
服务管理器
请求类型
显示特定 Recurly 服务的可用请求类型。
<?php ... $service = new \RecurlyClient\Service\Account(); $manager = new \RecurlyClient\ServiceManager($client, $service); $request_types = $manager->getRequestTypes(); print $request_types;
调用
根据调用的请求类型动作显示 Recurly 响应对象。
<?php ... $service = new \RecurlyClient\Service\Account(); $manager = new \RecurlyClient\ServiceManager($client, $service); try { $response = $manager->invoke('list')->execute(); } catch (Exception $e) { // Handle errors here } print $response;
响应
提取
简单地从 Recurly 网络服务检索数据。数据可以从以下格式中提取:数组、JSON 或 XML。
<?php ... try { $response = $manager->invoke('list')->execute(); } catch (Exception $e) { // Handle errors here } // Available formats are: array, json, xml. $data = $response->getData()->extract('array');