(I want my) Last.fm CFC wrapper

I wrote this tag-based CFC wrapper to access the last.fm api (details and spec can be found here: http://www.last.fm/api)
There are 15 components in total, 13 of which contain methods and functions relating to the last.fm api.

I wanted to try and develop something that was easy to implement, and easy to use.

The system I came up with requires the user to access ONE method within ONE component only,
and all classes, methods and arguments are passed through this one function.

The user only needs to createObject for the API.cfc file.
This takes two params (the api key and secret key provided to you by last.fm).


<cfset api = createObject("component", "cfc.api").init('apikey','secretkey') />

That's it. The api wrapper is effectively ready to go.

To access individual methods, the process is a simple one.
Last.fm organised and arranged their method calls into a class name.method name format eg user.getInfo.

There is one single function within the API.cfc that the user needs to call: methodCall().
This takes three params (the class name, the method name, the params to send to the method)

The param argument takes a struct format argument collection, so a call to user.getInfo (with username) would be like this:


<cfset args = StructNew() />
<cfset args["user"] = "mattgifford" />
<cfset thisUserInfo = api.methodCall('user', 'getinfo', args) />


Each of the functions within the main methods contain an extra argument (return).
This is used to allow you to choose what format you would like to receive the data.
As default, this is 'struct'.
All functions have the option for 'xml' output.

Most of them (with only a few exceptions where there is no repeating data to require it) have the option for 'query',
allowing you to easily loop through and output data.

The wrapper is available for download from http://iwantmylastfm.riaforge.org/

comments powered by Disqus