epages/rest-sdk

这是连接到epages商店的REST SDK。您可以将其作为开发者来开发epages应用程序。

0.2.1 2016-10-26 14:14 UTC

This package is not auto-updated.

Last update: 2024-09-17 11:55:28 UTC


README

这是连接到ePages商店的PHP REST SDK,易于使用。您可以使用它作为开发者来开发ePages应用程序。只需注册ePages开发者计划并创建一个免费的开发者测试商店。

要求

要使用此SDK,您需要

  • 至少 PHP 7.0

所有依赖项都自动包含在客户端中,并且可以通过Composer更新。

通过Composer安装

通过Composer获取客户端很简单。只需搜索epages/rest-sdk并将其放入您的composer.yml文件中

{
   "require": {
      "epages/rest-sdk": ">=0.2"
    }
}

配置

您可以通过在主目录中放置一个config.json来配置它。只需从GitHub复制config.example.json或创建一个新的

{
    "Client": {
        "host": "www.some.host",
        "shop": "shopName",
        "isSSL": true,
        "userAgent": "UserAgent",
        "token": "TheTokenIfExists"
    },
    "Logger": {
        "level": "ERROR",
        "output": "SCREEN"
    }
}

版本信息

以下信息是随着ePages REST SDK提供的。

代码示例

有关代码示例,请参阅示例文件夹

示例 获取100个产品

require_once("libraries/epages-rest-client.phar");
ep6\Logger::setLogLevel(ep6\LogLevel::NOTIFICATION);	// activate visible output

// set connection constants
$HOST		= "www.meinshop.de";
$SHOP		= "DemoShop";
$AUTHTOKEN	= "xyzxyzxyzxyzxyzxyzxyzxyz";
$ISSSL		= true;

// connect to shop
$shop = new ep6\Shop($HOST, $SHOP, $AUTHTOKEN, $ISSSL);

// use a product filter to search for products
$productFilter = new ep6\ProductFilter();
$productFilter->setLocale("de_DE");
$productFilter->setCurrency("EUR");
$productFilter->setSort("name");
$productFilter->setResultsPerPage(100);
$products = $productFilter->getProducts();

// print the products
foreach ($products as $product) {

    echo "<h2>" . htmlentities($product->getName()) . "</h2>";
    echo "<p>";
    echo "<img style=\"float:left\" src=\"" . $product->getSmallImage()->getOriginURL() . "\"/>";
    echo "<strong>ProductID:</strong> " . $product->getID() . "<br/>";
    echo "<strong>Description:</strong> " . htmlentities($product->getDescription()) . "<br/><br/>";
    echo "<strong>This product is ";
    if (!$product->isForSale()) {
        echo "NOT ";
    }
    echo "for sale and is ";
    if ($product->isSpecialOffer()) {
        echo "<u>a</u> ";
    }
    else {
        echo "not a ";
    }
    echo "special offer.</strong>";
    echo "</p><hr style=\"clear:both\"/>";
}

示例 检索商店信息

require_once("libraries/epages-rest-php.phar");
ep6\Logger::setLogLevel(ep6\LogLevel::NOTIFICATION);	//activate visible output

// set connection constants
$HOST		= "www.meinshop.de";
$SHOP		= "DemoShop";
$AUTHTOKEN	= "xyzxyzxyzxyzxyzxyzxyzxyz";
$ISSSL		= true;

// connect to shop
$shop = new ep6\Shop($HOST, $SHOP, $AUTHTOKEN, $ISSSL);

// prints the default currency and localization
echo $shop->getDefaultLocales();
echo $shop->getDefaultCurrencies();

// prints the name of the contact information in default language and in german
$contactInformation = $shop->getContactInformation();
echo $contactInformation->getDefaultName();
echo $contactInformation->getName();

实用工具

日志记录器

该库包含一个名为ep6\Logger的巨大日志记录器。要使用它(而不是echo命令),请编写

ep6\Logger::force("Print this!");

强制打印机还可以以简单结构打印数组。

默认情况下,所有通知消息都会打印。要更改此设置,请使用

ep6\Logger::setLogLevel(ep6\LogLevel::NOTIFICATION);	// shows all messages
ep6\Logger::setLogLevel(ep6\LogLevel::WARNING);			// shows warning and error messages
ep6\Logger::setLogLevel(ep6\LogLevel::ERROR);			// shows only error messages
ep6\Logger::setLogLevel(ep6\LogLevel::NONE);			// don't log anything

InputValidator

要验证数据和检查对象的值,有一个InputValidator类

ep6\InputValidator::isHost("www.test.de");
ep6\InputValidator::isJSON("{}");

您可以在文档中找到所有InputValidator函数

函数参考

完整参考位于此处

许可

代码可在MIT许可的条款下使用。