Wednesday, March 2. 2005Buzzing the Yahoo! Search Web ServicesMarch 22. Update: And here is the Flickr version: flickr.progphp.com
Apart from a bunch of messy CSS, the application is actually quite simple. Pulling from the RSS and REST servers is trivial. Here is a one-liner to pull an RSS feed from a url: $url = 'http://buzz.yahoo.com/feeds/buzzoverl.xml'; $xml = simplexml_load_file($url);The actual implementation wraps this and returns an associative array with just the title and the link, like this:
foreach($xml->channel->item as $item) {
$ret[(string)$item->title] = (string)$item->link;
}
return $ret;
For the search REST queries it isn't much harder. You build your query string:
$url = 'http://api.search.yahoo.com/'; $url .= 'ImageSearchService/V1/imageSearch'; $url .= '?query='.rawurlencode($q); $url .= "&appid=$appid"; $url .= "&results=$results"; $url .= "&type=$type";I then throw a cacheing layer in front of all these so I don't hit the feeds on every request. The core of the cache layer looks like this:
$stream = fopen($url,'r');
$tmpf = tempnam('/tmp','YWS');
file_put_contents($tmpf, $stream);
fclose($stream);
rename($tmpf, $dest_file);
A straight fopen() can be used since this is a simple REST query and the result is streamed directly to a temp file which is then renamed when complete to make sure other processes never see a half-written file. Check the mtime on $dest_file and read it until it gets too old, then refresh it.
Although I am not using any SOAP in this particular example, it isn't much harder to pull from a SOAP service. Here is a simple example that pulls from Amazon's SOAP service (they have a REST interface as well). It caches a serialized version of the generated object based on the service index and keywords requested.
$amazon_index = array(
'DVD', 'Photo', 'Electronics', 'OfficeProducts', 'HealthPersonalCare',
'Toys', 'Baby', 'VideoGames', 'MusicTracks', 'OutdoorLiving',
'Blended', 'MusicalInstruments', 'Magazines', 'DigitalMusic',
'Jewelry', 'Video', 'Tools', 'PCHardware', 'SportingGoods',
'Classical', 'Software', 'Books', 'VHS', 'Wireless', 'Restaurants',
'Music', 'GourmetFood', 'Miscellaneous', 'Kitchen', 'WirelessAccessories',
'Merchants', 'Beauty', 'Apparel'
);
function amazon($index, $keywords, $timeout=7200) {
$dest_file = "/tmp/aws_{$index}_".md5($keywords);
if(file_exists($dest_file) && filemtime($dest_file) > (time()-$timeout)) {
$result = unserialize(file_get_contents($dest_file));
} else {
$aws = new SoapClient('http://webservices.amazon.com/'.
'AWSECommerceService/US/AWSECommerceService.wsdl',
array("trace" => 1));
$result = $aws->ItemSearch(array(
'SubscriptionId'=>'XXXXXXXXXXXXXX',
'AssociateTag'=>'lerdorf-20',
'Request'=>array(array('SearchIndex'=>$index,
'Keywords'=>$keywords))
)
);
$tmpf = tempnam('/tmp','YWS');
file_put_contents($tmpf, serialize($result));
rename($tmpf, $dest_file);
}
return $result;
}
I still much prefer the REST services out there. SOAP always reminds me of being stuck behind the guy in a hat driving a Lincoln Towncar. You eventually get to where you want to go, but the journey is painful. With REST you can just toss your query into your browser and have a look at the returned XML. SOAP starts to make more sense when the queries you are sending get more complex than just tossing a couple of keywords to a search service and setting a couple of flags. But don't even try to read the SOAP spec. If you managed to fight your way through that spec already, try the new WSDL 2.0 Draft Spec. This is the sort of stuff that makes my brain hurt.
And yes, I know the thumbnails don't jump to the front in IE. IE's z-index handling on position: absolute elements is braindead. So use Firefox or Safari or some other browser with decent CSS support. Also, you'll need to let the cookie through. It's just a javascript cookie with your window dimensions so I'll know how big to make the oval. And no, it isn't really meant to be useful. Just a bit of fun visual candy. Last modified on 2005-04-16 23:23
Wednesday, November 24. 2004Skype - Talk to your Laptop
Skype has been out for a couple of months now, but I only recently had a look. I have never been very impressed with the audio quality of these various voice-chat systems. However, Skype is a whole different story. With similar-looking clients for Windows, Linux, OSX and PocketPC, a mechanism called SkypeOut for making calls to regular phones and some nifty P2P principles applied to the problem of getting in and out from behind firewalls and NAT gateways all combining to create something that works extremely well for most people. The biggest problem people generally have with it is figuring out how to get a microphone installed and configured for their systems. I installed it on a machine at home before heading to Paris and have been using it to talk to Christine from Paris. I also got my parents to install it by themselves and have had 3-way conference calls with me in Paris, my parents in Toronto and Christine in California. I have also called landlines in the US from Paris and Christine called my hotel landline in Paris using Skype. Overall the quality of all these calls were amazing. Every now and then there would be a slight drop or when 2 or 3 people all spoke at once it would occasionally garble things, but it is definitely the coolest piece of software I have used in a while. Although I may have to invest in a headset for it. You get some strange looks when you sit there talking to your laptop. Last modified on 2005-04-16 23:24
Saturday, September 11. 2004Gallery and the Coral Distribution Network
The Coral Distribution Network (CDN) is a very nice shiny toy for all of us who sometimes struggle with limited bandwidth. Let the NSF pay for it!
My photo album is what chews up the most bandwidth from my site, so it made sense to rig it up first to optionally be available via CDN. CDN is basically just a big Akamai-like network of servers that cache things and serve them up to you from servers that are close to you network-wise. It is has some fancy code behind it, but who cares how it works, it just does. Let's get to the interesting part. As you have probably figured out by now, you can access any site on the Web via Coral by simply appending ".nyud.net:8090" to the domain part of the URL and there are plugins available that add a menu item to automatically do this for you client-side. The problem with this is that you don't want to have to do this for every page on a site. It would be much nicer if the site would adjust its links such that if you enter the site via Coral, all the local links from that site would be Coral links. You may of course want to make some exceptions for pages that are interactive in some way, but for something like a photo album where 99% of people just look at mostly static content it works well. You can see the patch at http://gallery.menalto.com Note again that this quick hack does not in any way handle links that shouldn't be Coral'ed. Like the login link, comment stuff or all the administrative tools. It turns your Gallery into a read-only site if you come in using Coral. As the administrator of my album I can figure out that I need to go directly to it in order to add photos. But a more complete patch that doesn't Coralize stuff that shouldn't be would be nice. You can have a look at it in action at http://www.phpics.com.nyud.net:8090/ I submitted it to the Gallery Folks so let's see if they take it and run with it to integrate it completely. Update: A variation of this that also supports people running their Gallery on weird ports has been committed to Gallery's CVS, so you may just want to update from there to get it. Last modified on 2005-04-16 23:24
« previous page
(Page 4 of 5, totaling 14 entries)
» next page
View as PDF: Category Software | This month | Full blog |
Why a toys page?I love geeky toys and people are always asking me about them. So this page is where I keep track of the gadgets that interest me.
QuicksearchSyndicate This BlogMy LinksPopular EntriesTemplate dropdownBlog AdministrationCreative Commons |
