radowoj /
另一个Allegro助手 - 简化通信的Allegro WebAPI客户端及其助手类
v0.8.0
2017-04-01 15:05 UTC
Requires (Dev)
- phpunit/phpunit: ^5.7
README
Allegro WebAPI的简单客户端库。
目标
- 简化基本拍卖操作(创建新的拍卖、结束、更改物品数量、获取日志等) - 助手类。
- 避免为每个必填字段(fvalueString、fvalueInt、fvalueDate等)发送默认值 - 拍卖类及其装饰器。
安装
通过composer
$ composer require radowoj/yaah
示例1 - 创建新的拍卖
有关更符合程序员习惯的拍卖接口示例,请参阅yaah-mtg
use Radowoj\Yaah\Auction; use Radowoj\Yaah\Constants\AuctionTimespans; use Radowoj\Yaah\Constants\AuctionFids; use Radowoj\Yaah\Constants\SaleFormats; use Radowoj\Yaah\Constants\ShippingPaidBy; use Radowoj\Yaah\Constants\PaymentForms; use Radowoj\Yaah\HelperFactory\Factory; $helper = (new Factory())->create([ 'apiKey' => 'your-allegro-api-key', 'login' => 'your-allegro-login', 'passwordHash' => 'your-sha-256-hashed-and-then-base64-encoded-allegro-password', 'countryCode' => 'your-country-code', 'isSandbox' => 'true-if-you-intend-to-use-sandbox' ]); $localId = 1; $auction = new Auction([ AuctionFids::FID_TITLE => 'Test auction', AuctionFids::FID_CATEGORY => 26319, AuctionFids::FID_TIMESPAN => AuctionTimespans::TIMESPAN_7_DAYS, AuctionFids::FID_QUANTITY => 1, AuctionFids::FID_BUY_NOW_PRICE => 10.00, AuctionFids::FID_COUNTRY => 1, AuctionFids::FID_REGION => 15, AuctionFids::FID_CITY => 'Poznan', AuctionFids::FID_SHIPPING_PAID_BY => ShippingPaidBy::SHIPPING_PAID_BY_BUYER, AuctionFids::FID_PAYMENT_FORMS => PaymentForms::PAYMENT_FORM_VAT_INVOICE, AuctionFids::FID_DESCRIPTION => 'Test auction description', AuctionFids::FID_POSTCODE => '12-345', AuctionFids::FID_SALE_FORMAT => SaleFormats::SALE_FORMAT_NON_SHOP, AuctionFids::FID_POST_PACKAGE_PRIORITY_PRICE => 11.00 ]); $auction->setPhotos([ //array of (no more than 8) paths to photo files ]); $allegroItemId = $helper->newAuction($auction, $localId); echo "Created auction with itemId = {$allegroItemId}\n";
示例2 - 获取日志
require_once __DIR__ . '/../vendor/autoload.php'; require_once 'config.php'; use Radowoj\Yaah\HelperFactory\Factory; try { $helper = (new Factory())->create(require('config.php')); $deals = $helper->getSiteJournalDeals(); /** * Process journal entries - in this case echo details of every journal * item that creates a deal */ array_map(function($deal){ if ($deal->isTypeCreateDeal()) { echo "Deal {$deal->getId()} (itemId {$deal->getItemId()} - quantity {$deal->getQuantity()}) created at {$deal->getEventTime()}\n"; } }, $deals); } catch (Exception $e) { echo "Exception: {$e->getMessage()}\nFile: {$e->getFile()}; Line: {$e->getLine()}\n\n"; }