This post originated from an RSS feed registered with PHP Buzz
by Stephan Schmidt.
Original Post: Services_Ebay 0.11.0 released
Feed Title: a programmer's best friend
Feed URL: http://blog.php-tools.net/rss.php?version=1.0
Feed Description: The blog of PHP Application Tools
I just released a new version of Services_Ebay, which provides two cool new features, as well as several new API-calls. On of the new features is the new caching system, I added to the model classes. As API calls to the eBay API tend to be quite time consuming (and expensive) most users probably will be trying to cache the return values from the eBay API. So I decided to add this as an optional feature to Services_Ebay. Using the cache is extremely easy: <?php
$session = Services_Ebay::getSession($devId, $appId, $certId);
$session->setToken($token);
// use a static expiry of 15 minutes
$userCache->setExpiry('Static', 15);
// use this cache for all user models
Services_Ebay_Model_User::setCache($userCache);
// load a new user model
$user = Services_Ebay::loadModel('User', 'superman-74', $session);
if ($user->isCached()) {
echo 'data had been cached';
print_r($user->toArray());
} else {
echo 'fetching user data from eBay';
$user->Get();
print_r($user->toArray());
}
?>
After instantiating a new cache container, you set the type of expiry you want to use for caching the data. Currently only a fixed expiry time is supported, but this can be changed easily (as expiry checks are objects) and thus an expiry check will be added that caches data of eBay items shorter the nearer the end of the auction draws. I'll probably also add cache containers based on databases, as the are more flexible than filesystem caches.
The second feature I added (with some help by the fabulous Adam Trachtenberg) is the support for product finders. Product finders are those neat and advanced forms that eBay provides on their website, which lets you choose the style, color, size of clothing or any other item you are looking for. eBay's API provides to calls that help you adding those interactive search tools to your site as well: GetProductFinder, which returns XML code with the raw information (form elements and values for a certain category) and GetProductFinderXSL which returns the stylesheet eBay uses to render the HTML from the raw XML data. Services_Ebay makes working with these calls extremely easy, as it provides a ProductFinder model: <?php
$session = Services_Ebay::getSession($devId, $appId, $certId);
$session->setToken($token);
$ebay = new Services_Ebay($session);
// load the product finder XSL, fetching it everytime as too expensive
$xsl = file_get_contents('product_finder.xsl');
// get product finder
list($productFinder) = $ebay->GetProductFinder(1909);
echo $productFinder->render($xsl);
}
?>
Using this code will result in 4 drop-down menus as well as some javascript, which will update them, whenever the user selects an item.
The new release is also the first release which features code by Carsten Lucke, who added two new API calls (that deal with Dutch auctions and member messages) as well as the needed models for these calls.