This post originated from an RSS feed registered with PHP Buzz
by Stephan Schmidt.
Original Post: Making huge progress with Services_Ebay
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
1a72
About 6 months ago, I started a wrapper for the eBay webservice and created a draft in Pepr.
As I realized that eBay already is promoting a PHP package for accessing their API, I put this project on hold and worked on my other projects. But after some coverage of the project by Harry Fuecks and the PHP MagazineAdam Trachtenberg, technical evangelist at eBay, contacted me and asked me to update the project to implement eBay's new authentication method.
After we exchanged some mails, Adam told me that there's no official eBay package for PHP yet and so I started working on this again.
This was about 10 days ago, and I made huge progress already. I implemented 50 of the available API calls and now only some of the seldomly used methods are left to implement. The project makes heavy use of PHP5's new OO-features like overloading (methods are loaded on demand) and SPL's iterators. This allows you to work with eBay entities, like they were some native PHP objects, available on your system. Adam, who already saw some of my examples, was absolutely amazed, how easy it is to work with the complex API.
But enough of the talk and let's take a look at some examples:
<?PHP
// get information about a user
$user = $ebay->GetUser('superman-74');
// display user ID
echo $user->UserId;
// display all user data
print_r($user->toArray());
// get feedback for the user
$feedback = $user->getFeedback(Services_Ebay::FEEDBACK_BRIEF);
foreach ($feedback as $entry) {
echo $entry;
}
?>
All these return values are objects, that may also be used in foreach() loops or echo'd to the user, overloading will take care of how they are handled.
// Add the item
$result = $ebay->AddItem($item);
?>
If you realised that there's a mistake in the recently added item, just change it and send it back to eBay:
<?PHP
$item = $ebay->GetItem('ItemId');
$item->Title = 'The new title';
$ebay->ReviseItem($item);
?>
Most methods can be either called on the Services_Ebay object or on the model directly:
<?PHP
$item = $ebay->GetItem('ItemId');
$item->Title = 'The new title';
$item->Revise();
?>
When calling a method, you may either pass scalar parameters in the parameter order defined in the call object itself or you pass an associative array, using the names specified in the official API documentation. This keeps Services_Ebay simple for all users, while offering the full, complex functionality for the users who want to use advanced features of the API.
Services_Ebay already provides Calls and Models for working with users, items, searchresults, feedback, transactions, feedback, MyEbay, etc.
All code and a lot of examples are available in my CVS, there you can see all methods that have been implemented at a glance.
I'll probably start a real PEAR proposal next week, so this can be included in PEAR as fast as possible.
26a