meplato/store2

Meplato Store 2.0 API 的 REST 接口。


README

Build Status

这是 Meplato Store 2 API 的 PHP 客户端。它包含一个库,用于将您的基础设施与 Meplato 套件(针对供应商)集成。

先决条件

您需要两样东西来使用 Meplato Store 2 API。

  1. Meplato Store 2 的登录账号。
  2. API 令牌。

通过联系 Meplato 供应商网络服务来获取您的登录账号。API 令牌用于安全地与 Meplato Store 2 API 通信。您可以在登录 Meplato Store 后的个人化部分找到它。

安装

  1. 安装 composer
  2. 运行 composer install

入门指南

使用库实际上非常简单。所有功能都分别归类为服务。例如,您有一个用于处理目录的服务,另一个用于处理目录中的产品等。所有服务都需要使用您的 API 令牌初始化。

以下代码片段展示了如何在 Meplato Store 上列出您的目录。

// Client is responsible for performing HTTP requests.
// The API comes with a default (based on GuzzleHttp),
// but feel free to create your own.
$client = new \Meplato\Store2\HttpClient();

// Create and initialize the Catalogs service with your API token.
$service = new \Meplato\Store2\Catalogs\Service($client);
$service->setUser("<your-api-token>");

// Now get the catalogs and print them.
$response = $service->search()->skip(0)->take(0)->sort("-created,name")->execute();
echo "You have " . $response["totalItems"] . " catalogs.\n";
foreach ($response['items'] as $catalog) {
  echo "Catalog " . $catalog["id"] . " has name " . $catalog["name"] . "\n";
}

请随意阅读库的各个使用场景的单元测试。

文档

Meplato Store 2 API 的完整文档可以在 https://developer.meplato.com/store2 找到。

测试

我们使用 phpunit 进行测试

$ phpunit
$ phpunit --group me
$ phpunit --group catalogs

所有测试都是模拟的,即没有实际访问互联网上的网络服务器。

测试使用 #[Group('x')] 标签进行标记,以便轻松测试某些功能。例如,如果您只想运行 Me 服务的测试,请运行 phpunit --group me。要列出所有可用组,请运行 phpunit --list-groups

许可

本软件采用 Apache 2 许可证授权。

Copyright (c) 2015 Meplato GmbH, Switzerland <http://www.meplato.com>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    https://apache.ac.cn/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.