fzsombor/plentymarkets-rest-client

Plentymarkets REST 客户端

0.1.7 2019-09-10 01:47 UTC

This package is auto-updated.

Last update: 2024-09-29 05:28:47 UTC


README

Latest Version on Packagist Total Downloads

这是一个为 Plentymarkets 新 REST API 定制的 PHP 包。该 API 相对较新(2017 年 3 月),因此可能不是所有功能都能正常工作,此包也可能在某些时候过时。

我与 Plentymarkets 没有任何关联,也没有人为此付钱给我。正如许可证中所述,此软件为“现状”。如果您需要更多功能,请打开 GitHub 问题或提交拉取请求。我会尽力而为 :) 话虽如此,我不再为开发此包的公司工作,因此如果您对成为此存储库的贡献者感兴趣,请告诉我。

您可以在 这里 找到 Plentymarkets 文档

概述

  • 支持 4 个 HTTP 动词:GET、POST、PUT、DELETE
  • 自动登录和刷新,如果登录无效
  • 使用 PHP 数组进行简单的一次性配置(将序列化保存到文件中)
  • 函数返回关联数组
  • 处理速率限制(感谢 hepisec

安装

通过 Packagist 提供

composer require repat/plentymarkets-rest-client

使用方法

use repat\PlentymarketsRestClient\PlentymarketsRestClient;

// path to store the configuration in
$configFilePath = ".plentymarkets-rest-client.config.php";
// $config only has to be set once like this
$config = [
    "username" => "PM_USERNAME",
    "password" => "PM_PASSWORD",
    "url" => "https://www.plentymarkets-system.tld",
];

$client = new PlentymarketsRestClient($configFilePath, $config);

// After that just use it like this:
$client = new PlentymarketsRestClient($configFilePath);

可以使用以下方式使用 4 个 HTTP 动词

$client->get($path, $parameterArray);
$client->post($path, $parameterArray);
$client->put($path, $parameterArray);
$client->delete($path, $parameterArray);

// $parameterArray has to be a PHP array. It will be transformed into JSON automatically in case
// of POST, PUT and DELETE or into query parameters in case of GET.
// You don't _have_ to specify it, it will then just be empty
$parameterArray = [
    "createdAtFrom" => "2016-10-24T13:33:23+02:00"
];

// $path is the path you find in the Plentymarkets documentation
$path = "rest/orders/";

还可以使用该函数,这为您提供了更多自由,因为您可以选择方法,并且给定的 $parameters 将直接传递给 guzzle 对象

$client->singleCall("GET", $guzzleParameterArray);

错误

  • 如果有调用错误(=> guzzle 抛出异常),所有函数都将返回 false
  • 如果指定的配置文件不存在或不包含用户名/密码/URL,将抛出异常

待办事项

  • 使用刷新令牌刷新而不需要新的登录

依赖项

许可证

变更日志

  • 0.1.7 修复构造函数以符合 README(感谢 daniel-mannheimer
  • 0.1.6 支持 HTTP PATCH(感谢 hepisec
  • 0.1.5 删除对 www. 的检查,因为它会破坏子域(感谢 daniel-mannheimer
  • 0.1.4 自动速率限制(感谢 hepisec
  • 0.1.3 修复 PHP 7.2 依赖项
  • 0.1.2 修复 Carbon 依赖项
  • 0.1.1 更新 Guzzle 以支持 PHP 7.2
  • 0.1 初次发布

联系

Flattr this git repo