AOL Journals CFC Sneak Peek
Last week I demonstrated some of the advanced capabilities of the AOL Journals API by integrating the features of AOL Open Authentication. Today we'll take it a step further by creating a fully capable CFC to add to the AOL API CFC project.
The code we wrote last week was functional and intuitive, however it became very clear early on in the demonstration how useful it would be to consolidate code into their own functions. We probably wrote well under 100 lines of code and covered much of the API's capability but now we have the chance to really lighten up our code.
The AOL API CFC project has been out on the RIAForge for a few months and as it matures over time, I'm getting even more excited about the benefits of mixing, mashing, and leveraging the capabilities of supporting APIs to help the others. In the case of the Journals API, we need to use open authentication in order to tap into more advanced features such as creating, deleting, and managing private blogs. We've been using this for a few weeks now so integrating Journals into the framework is a snap. Start off by the downloading the AOL API Pre-Release (it's still in testing before launch to the RIAForge) and run the code in Listing 1.
<!--- create a new Journals object ---> <cfset obj_aolJournals = CreateObject( "component", "AOL.Journals" ).init( "someAOLScreenname", session.obj_openAuth ) /> <!--- get the current workspace ---> <cfset st_workspace = obj_aolJournals.getWorkspace() /> <!--- dump the workspace data structure ---> <cfdump var="#st_workspace#" />Listing 1 - The AOL Journals CFC Workspace
The first thing to notice right away is the creation of the AOL Journals object. A valid AOL screenname and optionally an instance of the AOL OpenAuth CFC are passed in. The OpenAuth component instance is required for any of the advanced features of the AOL Journals API. The instance we pass in is a session-level variable which is part of the security framework we created in previous blog postings (see the Resources section). Next, we call the getWorkspace method which returns a ColdFusion structure representing the workspace for the screenname. The result of this code is shown in Figure 1 below.

Figure 1 - The AOL Journals Workspace
The Journals API is XML-based, however I have often found ColdFusion's XML handling to be a little clunky and awkward compared to other languages. By abstracting the complexity of working with the XML data returned from AOL Journals from the ColdFusion developer, we are keeping the component clean and familiar. Now that we have a workspace structure, we can query the blogs which make up the workspace for the entries. This is demonstrated in Listing 2.
<!--- get the entries for the "My Private Journal" blog ---> <cfset arr_blogEntries = obj_aolJournals.getEntries( st_workspace[ "My Private Journal" ].href ) /> <!--- dump the blog entries data structure ---> <cfdump var="#arr_blogEntries#" />Listing 2 - AOL Journals Blog Entries
Listing 2 uses the getEntries method which accepts the collectionURI of the blog to return an array of structures which represent a blog entry. An example data structure is shown in Figure 2 below.

Figure 2 - My Private Journal Blog Entries
So far, we've accomplished the following with 5 lines of code:
- Leveraged the OpenAuth CFC to manage all authentication considerations
- Obtained a complete snapshot of an AOL screenname's Journals workspace
- Obtained a complete listing of all blog entries for any/all blogs in a workspace
The rest of the currently supported methods of the Journals CFC are demonstrated below.
<!--- create a new Journals object ---> <cfset obj_aolJournals = CreateObject( "component", "AOL.Journals" ).init( "someAOLScreenname", session.obj_openAuth ) /> <!--- create a blog ---> <cfset obj_aolJournals.createBlog( "My New Blog", "The newest", "my-new-blog" ) /> <!--- get the updated workspace ---> <cfset st_workspace = obj_aolJournals.getWorkspace() /> <!--- post a new blog entry ---> <cfset obj_aolJournals.postEntry( st_workspace[ "My New Blog" ].href, "First Entry Title", "My first blog entry!" ) /> <!--- get the blog entries ---> <cfset arr_blogEntries = obj_aolJournals.getEntries( st_workspace[ "My New Blog" ].href ) /> <!--- delete the most recent blog entry ---> <cfset obj_aolJournals.deleteEntry( arr_blogEntries[1].editURI ) /> <!--- delete the new blog ---> <cfset obj_aolJournals.deleteBlog( st_workspace[ "My New Blog" ].href ) />
With the ability to create, read, and delete blogs and blog entries, this CFC is already quite powerful. The rest of the features will be intergrated soon with the finalized code to be posted to the RIAForge.
Resources
- bricemason's blog
- Login or register to post comments
