|
Documentation
a quick overview of supported API methods and classes
Featured IntroductionThis project is intended to get you up and running with accessing Dopplr data from Flash 9 applications. It is also a playground for me to experiment with finding the most elegant and aesthetically pleasing way to code such applications. Your input is welcome if you have opinions on how the code might be improved, or if you want to implement some of the Dopplr API methods I didn't get to yet. ExamplesExample code is in the com.dopplr.examples package. The simplest one is DopplrBasics but some of the others are better documented or more interesting. These three examples should be self-contained:
These four examples also require you to download and include Modest Maps in your build path.
Building / CompilingI'm going to assume you're up and running with a development environment such as Flex Builder and that you've checked out the API classes and placed them in your build path already. If you're new to Actionscript 3 development, I can recommend Jeff Heer's excellent Flare Tutorial as good supplement to the official Adobe documentation about Flex Builder. Getting a TokenFirst of all you'll need an AuthSub token from Dopplr testing with, if you're logged into Dopplr you can get one here. You can worry about how to get a proper token later (there's example html and javascript here, just don't share your testing token or any swfs made with it in the meantime! API CallsFirst create an instance of the API class and add some listeners for statuses and errors: var api:API = new API("your token goes here");
api.addEventListener(StatusEvent.STATUS, onStatus);
api.addEventListener(ErrorEvent.ERROR, onError);onStatus and onError should be implemented in your class. Next call one of the following methods with a callback that expects the appropriate response.
// call one of these functions first:
api.loadAuthenticatedUser(onUserLoaded);
api.loadTravellerInfo('mattb', onUserLoaded);
api.loadFellowTravellers(onUsersLoaded);
The onUserLoaded callback will receive a Traveller, the onUsersLoaded callback will receive an array of Travellers:
public function onUserLoaded(user:Traveller):void
{
// do something with the traveller here
}
public function onUsersLoaded(users:Array):void
{
// loop through the travellers here
}
Once you have a traveller or an array of them, you can call some additional functions. Since a request for one traveller doesn't include trip info, you can call api.loadTravellerTrips with a Traveller to fill in their trips. When you load the authenticated user's fellow travellers they don't come with trips or home/current city info. To load the former, use api.loadFellowTravellersTrips, and to load the latter use api.loadFellowTravellersInfo. API ClassesThe Model class (which belongs to the API class) attempts to keep a list of unique Traveller, Trip and City instances and hashes of those objects by their unique identifiers. Each Traveller has an array of trips, each Trip has a city (destination) and a departure. Cities also store their Dopplr colour in the rgb variable. Each city also keeps an array of all the trips it knows about. |