Kevin Nelson Marshall
Other entries:
« Tidbits of random nothingness ...

Well I'm back to once again to demonstrate just how bad a Factor programmer I still am. Tonight I'm going to dive into a little xml-rpc code to pull down an 'interesting' photo from Flickr.

Before we get into the mess of Factor code I used to actually get this working I need to do a little background first. (when you see my example, you'll see that I clearly have a lot of Factor shortcuts still to learn)

When you are working with any sort of Web Service, the first step you need to do is to get familiar with the various methods and details of that service. In our case, we'll be calling the flickr.interestingness.getList method, which for our needs accepts two parameters (api_key and per_page).

NOTE: In order to attempt this example, you'll need to get your own api_key from Flickr (they're free so take two!)

Without getting into all the boring details about XML-RPC or the Flickr Web Service itself, we do have to at least state that XML-RPC services are strongly-typed. That is they expect their parameters to be passed as one of a set of defined types (such as integers, strings, or structures). In our example, the interestingness method expects a one element struct, which itself contains a hashtable of our api_key and per_page values.

OK so assuming you have the basic understanding of the Flickr service, and what it's expecting to get and return, let's move on to our Factor code.

The first thing we'll need to do is define some of the things we'll be using with our USE statements (I'm doing all of this in the Factor Listener this time around, but usually with an example this lengthy in words you will want to create a factor file or vocabulary and factor out a lot of the craziness I do below)

USE: xml
USE: xml-rpc
USE: xml.utilities

Now we need to go ahead and do our crazy one line Factor bit (see if you can decipher this in it's given state):

{ H{ { "api_key" "YOUR_API_KEY_GOES_HERE" } { "per_page" 1 } } } "flickr.interestingness.getList" "http://www.flickr.com/services/xmlrpc/" invoke-method rpc-response-params 0 over nth nip string>xml "photo" tag-named* "http://farm" swap "farm" over at swap ".static.flickr.com/" swap "server" over at swap "/" swap "id" over at swap "_" swap "secret" over at swap ".jpg" swap drop append append append append append append append append


When it's all said and done, you should have a URL left on your stack. You can copy/paste that URL into your favorite web browser to see what it produces (pretty interesting eh?).

Tomorrow, when I have a little more time, I'll go over the details of the mess above and explain the hows and whys (at least as far as why I did what I did; which isn't to say it's the right Factor way to do it)...perhaps I'll even find a few new shortcuts to make it all a little less of a jumble as I walk through the explanation...

So stay tuned!

posted by Kevin Marshall on 2008-01-17 00:00:00+00


Subscribe to my RSS feed »

BotFu feed with RSS reader

BotFu feed by Email


Search All Posts »


Kevin Marshall - Who's That?

I'm just your basic programmer. I can't spell to save my life, I'm not the greatest story teller, and I often ramble on about nothing. This blog showcases all of that!

If you're bored drop me an email at info at falicon.com or view my outdated resume.


Stalk Kevin on »

bit.ly
Delicious
Digg
Disqus
Facebook
Flickr
FriendFeed
Github
Last.fm
LinkedIn
StumbleUpon
Twitter (@falicon)

Archives by Category »

(28) Code »
(8) ColdFusion »
(15) Database »
(10) Factor »
(3) Falcons »
(321) General »
(13) JavaScript »
(18) Perl »
(17) PHP »
(20) Ruby »

Archives by Month »

(1) September 2010 »
(2) August 2010 »
(3) July 2010 »
(13) June 2010 »
(8) May 2010 »
(2) April 2010 »
(2) March 2010 »
(5) January 2010 »
(2) October 2009 »
(6) August 2009 »
(11) July 2009 »
(2) May 2009 »
(3) April 2009 »
(2) March 2009 »
(7) February 2009 »
(9) January 2009 »
(14) December 2008 »
(5) November 2008 »
(12) October 2008 »
(13) September 2008 »
(16) August 2008 »
(23) July 2008 »
(20) June 2008 »
(24) May 2008 »
(23) April 2008 »
(27) March 2008 »
(28) February 2008 »
(26) January 2008 »
(7) December 2007 »

Published Works »

Beginning Amazon's SimpleDB (Apress in dev.)
Pro Active Record (Apress 2007)
Web Services with Rails (O'Reilly 2006).

Contributed To »

Ruby Cookbook (O'Reilly 2006)
SQL Cookbook (O'Reilly 2005)
Various Reviews published in Computing Reviews

Free Code I've Created »

SimpleDB library in Python 3.0



This blog is powered by KickAssCode.