|
<!--- tunesBag API Demo for Adobe ColdFusion MX 7 / 8
(c) by Hansjoerg Posch <office@tunesBag.com>
How to use this demo file
a) Copy this file to a ColdFusion server
b) Edit the application key, username and remote key
c) Browse to the file using your favourite browser
d) Read the documentation and build your own application
Feel free to use this example as basis for your application.
--->
<cfparam name="url.action" type="string" default="HelloWorld"> <!--- fill in the right values ---> <cfset your_appKey="ENTER_YOUR_APP_KEY_HERE"> </cfset> <cfset your_username="ENTER_YOUR_USERNAME_HERE"> </cfset> <!--- see section "Authentification: The secure concept of remoteKeys" of the documentation---> <cfset your_remotekey="ENTER_YOUR_REMOTEKEY_HERE"> </cfset> <html> <head>
<title> tunesBag Demo ColdFusion</title>
<script type="text/javascript" src="http://www.tunesBag.com/static/demos/swfobject.js"> </script>
<style type="text/css">
body,td,p,div {
font-family:"Lucida Grande",Tahoma,Arial;
}
</style>
</head>
<body> tunesBag API Demo for Adobe ColdFusion <cfif Len( your_appKey ) IS 0> Please enter the appkey etc in your cfm file
<cfexit method="exittemplate">
Unknown end tag for </cfif> <cfswitch expression="#url.action#"> <cfcase value="HelloWorld">
<!--- say hello to the world! --->
Please select your desired request
Please select the desired request:
</cfcase>
<cfcase value="loadlibrary">
<!--- get library (max 20 items), order by rating --->
<cfset a_struct_params="StructNew()"> </cfset>
<cfset a_struct_params.maxrows = 7 />
<cfset a_struct_params.orderby = 'RATING' />
<!--- perform the request --->
<cfset a_struct = DoAPIRequest( appkey = your_appKey, username = your_username, remotekey = your_remotekey, request = 'items/get/', params = a_struct_params ) />
<!--- parse the incoming XML for the given items --->
<cfset a_items = XmlSearch( a_struct.xml, '//result/items/item') />
Load the first 10 items of the library ordered by the rating.
<cfloop from="1" to="#ArrayLen( a_items )#" index="ii">
<cfoutput>
#htmleditformat( a_itemsii .name.xmltext )#
Unknown end tag for </td>
|
- tmleditformat( a_itemsii .artist.xmltext )#
|
- tmleditformat( a_itemsii .album.xmltext )#
|
Unknown end tag for </tr>
Unknown end tag for </cfoutput>
Unknown end tag for </cfloop>
Unknown end tag for </table>
Unknown end tag for </blockquote>
Unknown end tag for </cfcase>
<cfcase value="playlist">
Get all items of the playlist "Recently played"
<cfset a_struct_params="StructNew()"> </cfset>
<cfset a_struct_params.setkey = 'recentlyplayed' />
<cfset a_struct = DoAPIRequest( appkey = your_appKey, username = your_username, remotekey = your_remotekey, request = 'sets/set/getitems/', params = a_struct_params ) />
<cfset a_items = XmlSearch( a_struct.xml, '//result/items/item') />
<cfloop from="1" to="#ArrayLen( a_items )#" index="ii">
<cfoutput>
#htmleditformat( a_itemsii .name.xmltext )#
Unknown end tag for </td>
|
- tmleditformat( a_itemsii .artist.xmltext )#
|
- tmleditformat( a_itemsii .album.xmltext )#
|
Unknown end tag for </tr>
Unknown end tag for </cfoutput>
Unknown end tag for </cfloop>
Unknown end tag for </table>
Unknown end tag for </blockquote>
Unknown end tag for </cfcase>
<cfcase value="item.play">
Play a track
<cfset a_struct_params="StructNew()"> </cfset>
<cfset a_struct_params.entrykey = url.entrykey />
<cfset a_struct_params.librarykey = '' />
<cfset a_struct = DoAPIRequest( appkey = your_appKey, username = your_username, remotekey = your_remotekey, request = 'items/get/deliver/', params = a_struct_params ) />
<!--- use flash player --->
This text will be replaced
<script type="text/javascript">
var so = new SWFObject('http://www.tunesBag.com/static/demos/player.swf','mpl','470','20','9');
so.addParam('allowscriptaccess','always');
so.addParam('allowfullscreen','true');
so.addParam('flashvars','&type=mp3&file=<cfoutput> #UrlEncodedFormat( a_struct.xml.result.location.xmltext )#</cfoutput> &autostart=true');
so.write('player');
</script>
</cfcase>
Unknown end tag for </cfswitch> Unknown end tag for </body> Unknown end tag for </html> <!--- you can use the following gerneric cffunction for your requests ... don't forget to add try / catch to the http calls ---> <cffunction access="public" name="DoAPIRequest" output="false" returntype="struct" hint="Perform an API request"> <cfargument name="appkey" type="string" required="true"
hint="the application key">
<cfargument name="username" type="string" required="true"
hint="the username">
<cfargument name="remotekey" type="string" required="true"
hint="the remote key">
<cfargument name="request" type="string" required="true"
hint="the request name">
<cfargument name="params" type="struct" required="false" default="#StructNew()#"
hint="parameters">
<cfset var a_struct_return = StructNew() />
<cfset var cfhttp = 0 />
<cfset var a_str_index = '' />
<cfset a_struct_return.result = false />
<cfhttp charset="utf-8" url="http://www.tunesBag.com/api/rest/#arguments.request#" result="cfhttp">
<cfhttpparam type="formfield" name="appkey" value="#arguments.appkey#">
<cfhttpparam type="formfield" name="username" value="#arguments.username#">
<cfhttpparam type="formfield" name="remotekey" value="#arguments.remotekey#">
<!--- add parameters --->
<cfloop list="#StructKeyList( arguments.params )#" index="a_str_index">
<cfhttpparam type="formfield" name="#a_str_index#" value="#arguments.params[ a_str_index ]#">
Unknown end tag for </cfloop>
Unknown end tag for </cfhttp>
<!--- parse returned XML --->
<cfset a_struct_return.xml = XMLParse( cfhttp.FileContent ) />
<!--- set the generic result --->
<cfset a_struct_return.result = a_struct_return.xml.result.result.xmltext />
<cfreturn a_struct_return />
Unknown end tag for </cffunction> <!--- end of file --->
Hosted by
|