Sunday, 17 January 2010

Picasa API Implementation v 0.1

Today I finally managed to get some time to carry on working on the Picasa API that I started in October or whenever it was (ok, I had to get up at about 5:00 but I couldn’t sleep!).

You can have a look at progress so far here. At the moment it only lists albums and allows you to click on them to go through the Picasa page. Put your own username in at the top and you’ll get your albums listed.

The next stage is to load the images for each album and display them.

I am pretty pleased with the progress I made today. Most of it was spent writing the translators for the XML which I did with some stub data and TDD which worked pretty well. In the past writing tests for xml translation didn’t work especially well and they always broke – but that was because the service layer changed. I am hoping that the Google APIs will be a bit more stable.

The UI code here is pretty ugly with no presentation models or anything like that, just enough to get what you see displayed. At the moment the effort is going into the API code.

I am hoping to eventually add support to this for other photo hosting services such as flickr. The model that I am using here is closely based on the xml format that comes back from Picasa. When I move to include other services there might have to be a few tweaks to make it work with more than one service.

Sunday, 3 January 2010

Implementing Lazy Loading of XML with ArrayCollection

I am still gradually working through my implementation of the Picasa public API to load images into Flex. One of the first apps I want to build is a simple signature app for forums that will loop through images in a Picasa album and display them one by one.

A Picasa album can contain 1000 images and the xml is pretty verbose so this would be a very large download. This would download each time the signature appeared on a page and every time the page was refreshed so downloading the whole lot is really bad idea.

I want to mimic the fill method of DataService. I would ask for an ArrayCollection to be filled but only the first 5 or however many records are specified would initially be loaded. The length of the collection would be reported as the number of items in the album and not the number of items downloaded. Additional items would be loaded as they are required.

Looking at ArrayCollection the getItemAt method has a prefetch argument specifying the number of items to fetch if the item is not local. There is also the ItemPendingError that is despatched if the item that is requested is not local but there isn’t much documentation about this and it’s not clear exactly how this is handled.

I had hoped that List and DataGroup for example would listen for ItemPendingError and add responders but they don’t seem to so it might not be as useful to implement the behaviour in this way.

If anyone has any clues as to how all this holds together I’d be very interested to hear them. I am particularly interested in how the DataService class interacts with ListCollectionView. Somehow DataService has to get ListCollectionView to report the length of the remote list and not the local list.
Unfortunately the source for DataService doesn’t seem to be available.

I could possibly implement this with some specific implementation of IList that is passed to a ListCollectionView but I would rather do it a similar way to the framework.

Any help much appreciated.

Friday, 18 December 2009

Updating Flex 4 SDK GeneratedResourceModule Error

I was updating to the latest Flex 4 SDK today which was a bit involved. For ages we’ve been using 10708 and have been unable to upgrade to a later version as Parsley didn’t work with it. There were some changes to the ModuleManager interface or something like that and Parsley’s Module management code needed to be updated.

Anyway, the parsley bug had been fixed and I was having problems with an SDK bug that I had reported a while ago and which has now been fixed. It seemed like a good time to update to the SDK but it did take a while:

  1. Download and set up new SDK version 13099
  2. Spend a while fixing all the compiler errors and adjusting code to work with new framework
  3. Run App
  4. Got Module errors due to Parsley (as in this thread)
  5. Check out latest parsley code from SVN
  6. build parsley swcs
  7. Run App
  8. Get module errors again
  9. build parsley swcs properly
  10. Run App
  11. Get a different error:

param 2 incompatible
  virt Object mx.core::FlexModuleFactory/callInContext()
  over *
GeneratedResourceModule7445881329779043571_mx_core_FlexModuleFactory/callInContext
()
VerifyError: Error #1053: Illegal override of
GeneratedResourceModule7445881329779043571_mx_core_FlexModuleFactory in
GeneratedResourceModule7445881329779043571_mx_core_FlexModuleFactory.

     at global$init()

Initially I incorrectly blamed this on Parsley again. I did some googling and couldn’t find much about GeneratedResourceModule apart from this. That got me thinking about resource bundles. It turns out that all I needed to do was to re-build my resource bundles with the new SDK so they were compiled with the new Module interface. It was a simple step that I should have done straight away but I had forgotten.

Hopefully this post will save someone else a bit of time if they have the problem as well.

Monday, 23 November 2009

XML Namespaces

Recently I have been lucky enough to be working on a project that uses LCDS so I don’t have to write XML translators – all the objects arrive from server ready typed – it is soooo much easier and saves an awful lot of time.

At home though I have started working with the Picasa data API which means I am back to writing translators.
This is a job I really don’t like – it never works the first time and takes a lot of trial and error to get it write. I am actually going to write a base translator class to make it a bit easier the next time I have to do it.

Getting to grips with xml can be tricky but when namespaces are involved it gets exponentially more difficult and annoying!

I’ll make a note of the syntax of how to deal with namespaces here so that next time I’ve forgotten how to do it I can look it up.

I am trying to retrieve the href of the link node below with the relevance of self:

<feed
    xmlns='http://www.w3.org/2005/Atom'
    xmlns:gphoto='http://schemas.google.com/photos/2007'
    >
    <link
        rel='alternate'
        type='text/html'
        href='http://picasaweb.google.com/Giles.Roadnight'
        />
    <link
        rel='self'
        type='application/atom+xml'
       href='http://picasaweb.google.com/data/feed/api/user/Giles.Roadnight'
        />
</feed>

My first attempt was as follows:

var href : String = xml.link(@rel=’self’)[ 0 ]@href;

but that didn’t work. The give away is this line:

xmlns='http://www.w3.org/2005/Atom'

declaring the default namespace for the xml. What worked in the end was this:

var atom : Namespace = new Namespace( "http://www.w3.org/2005/Atom" );
var href : String = xml.atom::link.( @rel == 'self' )[ 0 ]@href;

Hopefully that’ll save me (and maybe you) a few hours in the future.

Sunday, 15 November 2009

Picasa Web Albums Data API

I have previously tried to get Flex to play nicely with the Picasa API. I use Picasa a lot and host all my pictures there so to be able to do things with them with Flex would be very useful.

Before I have had issues as there was no crossdomain.xml but having had a look at the docs today this seems to now be fixed (or I missed it last time) as detailed here.

There are a couple of small projects I want to build on this API so it’s great that I won’t have to proxy these calls through the server.

Saturday, 10 October 2009

More Waving

I’m excited to learn that there is already an Actionscript client library that enables you to write a flex application as a Google wave extension!

Not sure what I would develop yet but there is a lot of scope for some cool apps I think.

http://code.google.com/p/wave-as-client/

http://wave-samples-gallery.appspot.com/results?q=flex

Google Wave – first impressions

I got my invite to Google Wave today and have had a bit of a play about. If you don’t know what it’s all about then here is a 10 minute video explaining the basics:

So far it’s a bit frustrating as I don’t know many other people who have Google Wave. I can see the potential and would love to be able to use all the features. I am actually organising a trip to Scotland for May next year with Linzi and 4 friends and Google Wave would be great to help organise that but only Linzi and I have access so we can’t use it.

So far I have installed Tweety which is pretty cool – you can get all your twits directly in Google Wave. I’ve also had a play with the map extension and the Sudoku extension.

So, if anyone from Google Wave is listening please give me 4 invites so I can use wave to organise our trip next year!