mvenghaus/saloon-plenty-connector

Plentymarkets 的 Saloon 连接器

dev-main 2024-05-31 04:50 UTC

This package is auto-updated.

Last update: 2024-08-31 00:37:32 UTC


README

Saloon - 带有令牌处理功能的 Plentymarkets 连接器,让您轻松开始构建自己的请求。

安装

通过 Composer 安装该软件包

composer require mvenghaus/saloon-plenty-connector

使用方法

基本结构

$configuration = new Configuration(...);
$connector = new Connector($configuration);

$response = $connector->send(new Your_Request());

配置 - 结构

class Configuration
{
    public function __construct(
        public string $endpoint, // https://www.your-domain.com/rest/
        public string $username,
        public string $password,
        public ?string $authenticator = null, // saloon authenticator (serialized)
        public ?Closure $authenticatorUpdateCallback = null, // callback to save authenticator if changed
        public ?Closure $debugCallback = null // callback for debugging
    ) {
    }
}

配置 - 示例

$authenticator = load_from_your_cache();

$configuration = new Configuration(
    'https://www.your-domain.com/rest/',
    'USERNAME',
    'PASSWORD',
    $authenticator,
    function (string $authenticator) {
        save_to_your_cache($authenticator);
    },
    function (PendingRequest $pendingRequest, RequestInterface $psrRequest) {
        echo $pendingRequest->getUrl() . PHP_EOL;
    }
);