boldgrid/reseller-api
Composer 安装命令:
composer require boldgrid/reseller-api
包简介
SDK for the BoldGrid API
README 文档
README
Using composer, you can get started quickly:
$ composer require boldgrid/api
In your code, use the normal procedures of requiring the autoloader. This client uses PSR-4 specification for autoloading:
require __DIR__ . '/vendor/autoload.php';
Now you can start using the API. The examples below will assume that your using the namespaces:
use Boldgrid\Api\Boldgrid;
Then you can kick off by creating a new api call using the default settings:
$api = new Boldgrid();
The endpoint is pointing to production, but you can easily switch this to the Reseller API sandbox endpoints by passing in the sandbox instance to the new Boldgrid constructor like this:
use Boldgrid\Api\Environment\Sandbox; $api = new Boldgrid( new Sandbox );
Alternatively, you can this syntax to accomplish the same goal:
use Boldgrid\Api\Environment\Sandbox; $api = new Boldgrid(); $api = $api->setEnvironment( new Sandbox );
The calls will utilize token based authentication and look for stored responses in the session data. You can choose to store the data in memcache instead by passing an instance of a class utilizing the Storage interface. This example shows how to set the storage to use Memcache instead of Session:
use Boldgrid\Api\Environment; use Boldgrid\Api\Storage; $api = new Boldgrid( new Environment\Sandbox, new Storage\Memcache );
Alternatively you can use the following syntax to accomplish the same thing:
use Boldgrid\Api\Environment\Sandbox; use Boldgrid\Api\Storage\Memcache; $api = $api ->setEnvironment( new Sandbox ) ->setStorage( new Memcache );
Using the token based authentication, which is the default auth method - you will need to set the auth params. The tokens have a set expiration of 2 days for the BoldGrid Reseller API, so you will need to provide a way to retrieve the key/secret securely in your application. This can be done by passing in the key and reseller key, like this:
$api = $api ->setKey( $key ) ->setResellerKey( $resellerKey );
We recommend sticking with the token based authentication for making calls from distributed applications, but you may wish to use other authentication methods when making calls. If you decide to use one of the other authentication methods you can simply pass the auth type desired to the setAuth method. The supported types are token, basic, and key. You can read more about the API authentication methods in our API documentation.
This example shows how to switch to using Basic Authentication for your call, which will require you to pass in your key and reseller key secret:
$api = $api ->setAuth( 'basic' ) ->setKey( $key ) ->setResellerKey( $resellerKey );
This example shows how to authorize with only the key and reseller key:
$api = $api ->setAuth( 'key' ) ->setKey( $key ) ->setResellerKey( $resellerKey );
Now that you know how to set the environment, authorization, and storage types - you can start making calls utilizing the BoldGrid Reseller API Client. Each call is segmented to it's base and endpoint. For instance, if you're looking to make a call to the key/list endpoint, the syntax would be like:
$api->key()->list();
Here's an example that sets the environment to the sandbox API, uses token authorization (default ), stores the token in memcache, and generates the key list of the clients under the reseller:
require __DIR__ . '/vendor/autoload.php'; use Boldgrid\Api\Boldgrid; use Boldgrid\Api\Environment\Sandbox; use Boldgrid\Api\Storage\Memcache; $api = new Boldgrid(); $api = $api ->setEnvironment( new Sandbox ) ->setStorage( new Memcache ) ->setKey( $key ) ->setResellerKey( $resellerKey ); $call = $api ->key() ->list(); var_dump( $call ); die;
Here's a list of available calls that can be made:
Auth
$api->auth() ->getToken( $key, $resellerKey );
Coin
$api->coin() ->balance( $connectId ); $api->coin() ->add( $connectId, $coins ); $api->coin() ->remove( $connectId, $coins );
Key
$api->key() ->list(); $api->key() ->details( $connectId ); $api->key() ->create( $email, $isPremium ); $api->key() ->suspend( $connectId, $reason ); $api->key() ->unsuspend( $connectId, $reason ); $api->key() ->revoke( $connectId ); $api->key() ->changeType( $connectId, $type ); $api->key() ->createReseller( $title, $email, $optional );
Site
$api->site() ->list( $connectId, $dateFrom, $dateTo );
User
$api->user() ->update( $connectId, $email, $displayName ); $api->user() ->updateReseller( $title, $email );
boldgrid/reseller-api 适用场景与选型建议
boldgrid/reseller-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18 次下载、GitHub Stars 达 1, 最近一次更新时间为 2017 年 03 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 boldgrid/reseller-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 boldgrid/reseller-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 18
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL2.0
- 更新时间: 2017-03-06