newera / php-sdk
New Era SDK for PHP
此包的官方仓库似乎已不存在,因此该包已被冻结。
This package is not auto-updated.
Last update: 2019-12-09 06:15:58 UTC
README
New Era PHP SDK 是一个 PHP 接口,用于访问 image2art REST API。
安装
该包可在 packagist.org 上找到,因此使用 Composer 安装很简单。只需将以下依赖项添加到您的 composer.json 文件中,然后运行 composer update
。
"require": {
"newera/php-sdk": "dev-master"
}
设置客户端
SDK 包含一个用于连接到 REST API 的客户端。该客户端支持 api.image2art.com 上的所有环境。要设置环境,只需将环境名称传递给客户端构造函数。
允许的环境有
- testing
- staging
- production
以下示例展示了如何使用测试用户凭据初始化客户端。
use Newera\Api\Client;
$this->client = new Client(array(
'environment' => 'testing',
'username' => 'testing',
'secret' => '$2y$08$tEwCIc9DxDNKRvzHhfRRlOHxDbu.MyIk5EnzEmZVEJ/GeuHXa.tki'
));
平台对象
还包括对 平台对象 的支持。可以创建和验证 订单、商品、地址 和 客户。
有关 平台对象 的更多信息,请参阅 REST API 文档。
使用客户端
客户端提供了访问 REST API 的快捷方法。以下概述了这些方法。更详细的 API 文档,包括 平台对象 的类描述,由 phpdoc 生成,并在 docs
文件夹中提供。
ping
向 /ping 发送 GET 请求并返回 TRUE,如果服务器处于运行状态。
示例
$server_up = $this->client->ping();
// returns TRUE
createOrder
向 /orders 发送 POST 请求以创建一个 订单。此方法接受一个类型为 Order 的 平台对象 作为唯一参数。
示例
use Newera\PlatformObjects\Address;
use Newera\PlatformObjects\Customer;
use Newera\PlatformObjects\Item;
use Newera\PlatformObjects\Order;
$order = new Order();
// set the customer information
$order->customer = new Customer();
// set shipping and billing
$order->shipping = new Address();
$order->billing = new Address();
// add items
$order->items = array();
$order->items[] = new Item();
// create the order
$order_id = $this->client->createOrder($order);
getOrders
向 /orders 发送 GET 请求以检索系统中的所有订单。
示例
$orders = $this->client->getOrders(5);
echo count($orders); // 5
getOrder
向 /orders/:id 发送 GET 请求以检索指定的订单。
示例
// return an Order object
$order = $this->client->getOrder(10001);
getOrderStatus
用于检索指定订单状态的快捷方法。
echo $this->client->getOrderStatus(10001);
// prints "IN TRANSIT"
开发设置
为了为开发设置项目,克隆仓库并运行 composer install
以生成测试用的类加载器。
$ git clone git@bitbucket.org:newera/php-sdk.git
$ cd php-sdk
$ composer install
运行单元测试
现在 Composer 已解决所有依赖项,您可以从项目根目录运行 phpunit
。测试位于 tests
文件夹中。您在此处添加的任何新测试都将作为测试套件的一部分运行。
$ phpunit