exchangegroup / exchangegroup-api
此包已废弃,不再维护。未建议替代包。
v1.0.0
2015-02-04 05:27 UTC
Requires
This package is not auto-updated.
Last update: 2024-02-07 04:27:39 UTC
README
PHP API 客户端,用于http://www.bikeexchange.com.au/,http://www.tinitrader.com.au/,http://www.houseofhome.com.au/,http://www.bikeexchange.co.nz,http://www.bikeexchange.de 和 http://www.bikeexchange.com
需要 https://getcomposer.org.cn/
所有响应数据均以关联数组的形式提供,便于处理
<?php require('vendor/autoload.php'); $client = new ExchangeGroup\Client('username', 'password'); // retrieving more information about one random advert from that list $adverts = $client->getAdverts(); // updating the title and price of one random advert from that list $randomAdvert = array_rand($adverts, 1); $client->updateAdvert( $advertToUpdate['id'], array('title' => 'New Product Title', 'price' => '12.34') ); // retrieving a list of variants from the server $variants = $client->getVariants(); // retrieving more information about one variant advert from that list $randomVariant = array_rand($variants, 1); $variantDetails = $client->getVariant($randomVariant['id']); // and from the list attached to the advert foreach($randomAdvert['variant_ids'] as $variantId) { var_dump($client->getVariant($variantId)); } // OR $advertVariants = array_map( function($id) use ($client) { return $client->getVariant($id); }, $randomAdvert['variant_ids'] ); // updating the count_on_hand and sku of one of those variants $client->updateVariant( $advertVariants[0]['id'], array('count_on_hand' => 1, 'sku' => 'A3334C') );
处理 API 错误
如果 API 返回错误对象,客户端将抛出 ExchangeGroup\ClientException
。此异常包含所有请求错误的消息,同时还提供了一个公开的 errors
属性,用于遍历错误。
try { $client->updateVariant( 1234, array('count_on_hand' => -3, 'sku' => 'A3334C') ); } catch(ExchangeGroup\ClientException $e) { // "Errors in API request - count_on_hand: must be greater than zero" echo($e->getMessage()); }