ePages REST SDK
This is the PHP REST SDK to easily connect to an ePages shop.
You can use it as a developer to develop apps for ePages.
Just sign up for the ePages Developer Program and create a free developer test shop., (*1)
Requirements
To use this SDK, you'll need:, (*2)
All dependencies comes automatically with the client and could be updated via composer., (*3)
Installation via composer
Its easy to get the client via Composer.
Just search for epages/rest-sdk and put this to you composer.yml file:, (*4)
{
"require": {
"epages/rest-sdk": ">=0.2"
}
}
Configuration
You can configure it with putting a config.json into you main directory.
Just copy the config.example.json from GitHub or create a new one:, (*5)
{
"Client": {
"host": "www.some.host",
"shop": "shopName",
"isSSL": true,
"userAgent": "UserAgent",
"token": "TheTokenIfExists"
},
"Logger": {
"level": "ERROR",
"output": "SCREEN"
}
}
The following information are provided with the ePages REST SDK until now., (*6)
Feature |
GET |
PUT |
POST |
DELETE |
PATCH |
information |
carts |
โ |
โ |
โ |
โ |
? |
categories |
โ |
โ |
- |
- |
? |
currencies |
โ |
- |
- |
- |
? |
legal |
โ |
- |
- |
- |
? |
won't do, it's not needed |
legal/contact-information |
โ |
โ |
- |
- |
? |
legal/privacy-policy |
โ |
โ |
- |
- |
? |
legal/rights-of-withdrawal |
โ |
โ |
- |
- |
? |
legal/shipping-information |
โ |
โ |
- |
- |
? |
legal/terms-and-condition |
โ |
โ |
- |
- |
? |
locales |
โ |
- |
- |
- |
? |
products |
โ |
- |
- |
โ |
? |
products//custom-attributes
|
โ |
- |
- |
. |
? |
products//stock-level
|
โ |
โ |
- |
- |
? |
products/export |
โ |
- |
- |
- |
? |
sales |
โ |
โ |
โ |
โ |
? |
search/product-suggest |
โ |
- |
- |
- |
? |
shipping-methods |
โ |
- |
- |
- |
? |
Code examples
For code examples, see the examples folder., (*7)
Example Get 100 products
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();
Utilities
Logger
The library comes with a huge Logger called ep6\Logger
.
To use this (instead of the echo
command) write, (*8)
ep6\Logger::force("Print this!");
The force printer also can print arrays in a simple structure., (*9)
By default all notification messages are printed. To change this use:, (*10)
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
To validate data and check the value of an object there is a InputValidator class:, (*11)
ep6\InputValidator::isHost("www.test.de");
ep6\InputValidator::isJSON("{}");
You can find all InputValidator functions in the documentation, (*12)
Function reference
The complete reference is located here., (*13)
License
The code is available under the terms of the MIT License., (*14)