Posted in
ColdFusion
| Posted on 12-08-2007
| 6,247 views
Yesterday I posted a quick example of integrating Google's Docs API with ColdFusion. I went ahead and wrapped up the code in a simple set of CFCs. There is a base CFC that handles authentication along with a docs CFC that handles the real interaction. Here is some sample code:
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
<cfset docs = createObject("component", "docs")>
<cfset docs.authenticate("rcamden@gmail.com","foo")>
1<cfset docs = createObject("component", "docs")>
2<cfset docs.authenticate("rcamden@gmail.com","foo")>
This creates an instance of the CFC and logs the user on. If authentication fails, a CF error is thrown, so normally this would probably be wrapped in cfry/cfcatch.
To get all your documents, you would run:
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
<cfset mydocs = docs.getDocumentList()>
1<cfset mydocs = docs.getDocumentList()>
This returns a query. One of the columns contains the sourceurl, which can be used to grab the source:
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
<cfset content = docs.download(mydocs.sourceurl[1])>
<cfoutput>result is #content#</cfoutput>
1<cfset content = docs.download(mydocs.sourceurl[1])>
2<cfoutput>result is #content#</cfoutput>
The getDocumentList() supports 2 filters (Google supports more). You can use max to limit the number of results:
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
<cfset mydocs = docs.getDocumentList(max=9)>
1<cfset mydocs = docs.getDocumentList(max=9)>
You can also apply a title filter:
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
<cfset mydocs = docs.getDocumentList(title="Blog")>
1<cfset mydocs = docs.getDocumentList(title="Blog")>
The title filter is a search, not a direct match.
Download attached file
Thanks a lot for the code.
Question: How can I add a function for uploading docs?
I have created a kind of a forum and the thread creator can upload docs using his gmail login and then the other users can view the docs 'attached' on the thread and edit them.
Thanks to your cfc I can read the files bu I also I need the upload function for the thread creation and the edit process as well.
Any quick solution?
Thanks a lot!
Thanks for your time.