tamble/bluedrone-client-php

PHP版的Bluedrone API客户端

0.1.6 2015-12-07 18:06 UTC

This package is not auto-updated.

Last update: 2024-09-24 03:59:32 UTC


README

Bluedrone是一家履行服务提供商。您可以在https://bluedrone.com注册账户。

要求

支持任何PHP版本 >= 5.3。

此客户端基于guzzle http库构建,并需要json php扩展

虽然建议安装curl php扩展,但这不是必需的。

安装

通过Composer

在项目根目录中的composer.json中创建或添加以下内容

{
    "require": {
        "tamble/bluedrone-client-php": "*"
    }
}

安装composer依赖项

php composer.phar install

composer install

要求依赖项

require_once("/path/to/vendor/autoload.php");

存储

由于Bluedrone API使用Oauth2,您需要在请求之间存储访问令牌。为此,提供了两个存储适配器,但只要实现Token\Storage\StorageInterface接口,您就可以使用任何其他适配器。

捆绑的示例目录显示了使用这些适配器的各种方法。

如果您使用的是Mysql适配器,您需要创建以下结构的表(如果需要,引擎可以是MyISAM)

CREATE TABLE IF NOT EXISTS `bluedrone_tokens` (
  `id` int(10) unsigned NOT NULL,
  `value` varchar(255) NOT NULL,
  `eol_timestamp` int(10) unsigned NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

示例

<?php

namespace Tamble\Bluedrone\Api;

use Tamble\Bluedrone\Api\Token\Storage\Pdo\Mysql;

require('../vendor/autoload.php');

/*
 * Example is passing all the data to the storage adapter instead of using a PDO instance
 */
$storage = new Mysql('bluedrone_tokens', '127.0.0.1', 'user', 'password', 'database');

$client = new Client('CLIENT_ID', 'CLIENT_SECRET', $storage);

try {
    $client->createOrUpdateProduct(
        '2345-09-F-RED',
        array(
            "sales_channel_id" => 23,
            "name" => "Gheisa Hair Pin Red",
            "unit_system" => "imperial",
            "weight" => 10,
            "length" => 4,
            "width" => 1,
            "height" => 1,
            "price" => 3.5,
            "currency_code" => "USD",
            "is_unfulfillable" => false,
            "is_fragile" => true,
            "is_dangerous" => false,
            "is_perishable" => false
        )
    );
} catch (BluedroneException $e) {
    /*
     * Any problem that occurs results in an exception being thrown.
     * Each exception offers a 'title', 'details' and 'code' (http status code)
     *
     * The lack of an exception means that the api call was successful.
     */
    echo $e->getTitle();
    echo $e->getDetail();
}

文档

最新的API文档可在:http://docs.bluedrone.apiary.io/