Alain Hufkens {Rich Interactive Applications Developer}

14May/093

Retrieve Basecamp data with BasecampAS3Lib

One of the projects I am currently working on is an open source Actionscript library that wraps the Basecamp REST API in an easy to use AS3 classes. The project is called BasecampAS3Lib an can be found on Google Code. The project is still in development and I did some serious refactoring yesterday.

At this point the services can only retrieve data from Basecamp and you can already experiment with the ProjectService, CategoryService and TodoListService classes. The other services still need to be implemented. But this post will give you a sneak peak on how simple it can be to retrieve data (in this case project data) from Basecamp with this lib.

NOTE: This code only works in an Adobe AIR application (see below for more details why).

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication
  xmlns:mx="http://www.adobe.com/2006/mxml"
  xmlns:basecamp="net.hufkens.basecamp.*"
  xmlns:services="net.hufkens.basecamp.services.*"
  layout="absolute"  viewSourceURL="srcview/index.html">
 
  <mx:VBox width="100%" height="100%">
    <mx:HBox width="100%">
      <mx:Label text="url:"/>
      <mx:TextInput id="apiurl" width="100"/>
      <mx:Label text="username:"/>
      <mx:TextInput id="username" width="100"/>
      <mx:Label text="password:"/>
      <mx:TextInput id="password" width="100"/>
      <mx:Button label="get projects"
        click="getProjects()"/>
    </mx:HBox>
    <mx:DataGrid dataProvider="{projects}"
      width="100%" height="100%"/> 
  </mx:VBox>
 
  <basecamp:BasecampAPI id="api"
    url="{apiurl.text}"
    username="{username.text}"
    password="{password.text}"/>
 
  <mx:ArrayCollection id="projects"/>
 
  <mx:Script>
    <![CDATA[
      import net.hufkens.basecamp.events.BasecampEvent;
     
      private function getProjects():void {
        api.projectService.addEventListener(
          BasecampEvent.GET_LIST, handleGetList);

        api.projectService.addEventListener(
          BasecampEvent.FAIL, handleFail);

        api.projectService.getList();
      }
     
      private function handleGetList(event:BasecampEvent):void {
        projects = new ArrayCollection(event.data as Array);
      }
     
      private function handleFail(event:BasecampEvent):void {
        Alert.show(event.data as String);
      }
     
    ]]>
  </mx:Script>
 
</mx:WindowedApplication>

However there is still an issue with the authentication. Apparently using basic authentication from a Flash/Flex application is not that trivial as it would sound. A while ago I wrote a blog post about this (read it here), but this approach only works when you run it from an AIR application. The same code doesn't work when running from a url on a web site.

So, if you have any suggestions or a solution for the basic authentication issue please let me know.

Filed under: air, flex Leave a comment
Comments (3) Trackbacks (0)
  1. Yes, I will be contributing to this project.

    Ill see you on google code…..

  2. Nice job,

    will certainly try it out. ;-)

    grtz

  3. Hey Alain, any progress that you can share we us?

    thanks for your time
    RC


Leave a comment


No trackbacks yet.