Create a RSS Feed out of your Share Files

Adobe’s Share service doesn’t have RSS feeds yet (as far as I know), but there is no reason you can’t role your own! Here is a quick example. The first piece is ShareCFC, my open source wrapper for the Share service. Grab the bits - get the required logon bits, and then create an instance:

<cfapplication name="shareapi">

<cfset appkey = “harrypotter”> <cfset sharedsecret = “parishiltonisactuallyreallysmart”>

<cfif not isDefined(“application.share”)> <cfset application.share = createObject(“component”, “share”).init(“ray@camdenfamily.com”,”password-noreally”,appkey,sharedsecret)> </cfif> </code>

The initial logon to the Share service can be a bit slow so the cache here is important. Next we grab the files. Now the Share service is still in development and currently has some performance issues (like Lindsey has drinking issues), but I’ve been assured this will be fixed soon. For my testing I cached the results. To get all of my Share files it is one simple CFC call:

<cfif not isDefined("application.files")> <cfset application.files = application.share.list()> </cfif> <cfset files = application.files>

I copied from the application scope to save myself some typing. So far so good? We don’t want to create an RSS feed that points to items that folks can’t use, so let’s filter out the non-public stuff (and maybe this is a good idea to add to my code):

<!--- filter by public ---> <cfquery name="files" dbtype="query"> select * from files where sharelevel = 'public' </cfquery>

Last but not least - lets make the feed. I create a column map to define columns to CFFEED required items, and create a struct of metadata:

<cfset cmap = structNew()> <cfset cmap.publisheddate = "createddate"> <cfset cmap.title = "name"> <cfset cmap.rsslink = "recipienturl">

<cfset meta = structNew()> <cfset meta.title = “My Public Share Files”> <cfset meta.description = “All of my public files from Share”> <cfset meta.link = “http://www.raymondcamden.com”> <cfset meta.version = “rss_2.0”> </code>

And finally - serve up the RSS:

<cffeed action="create" properties="#meta#" query="#files#" columnMap="#cmap#" xmlVar="feedXML">

<cfcontent type=”text/xml” reset=”true”><cfoutput>#feedxml#</cfoutput> </code>

Easy peasy, lemon squeezy as my son would say. I see two potential things I can add to ShareCFC now - an optional share level filter to List(), and perhaps an automatic way to return the data in the RSS form.

I’ve saved my RSS here: feed://www.coldfusionjedi.com/demos/test.xml

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Comments