This is part one in a … five? Let’s go with five. Five-part series wherein I talk about how I built a simple app that uses the Instagram API.
In this post, I’m going to focus on the classes I used to build the app. There are only two: bearpanther.InstagramSearch and bearpanther.BingGeocode. Hopefully the name of each conveys their purpose.
Where was I, oh yeah– classes. In both cases, a class is created to talk to some API.
The bing geocode class does basically the same thing. Its find_location method takes a location (an address, place name, zip code, etc., basically anything you can enter in maps.bing.com and expect to be sent to a location) and returns potential locations as lat, long coordinates using a deferred.
I mentioned that these classes return a deferred. You might be saying to yourself, “what the hell is a deferred?” Well, a deferred is a handle to the result of some asynchronous task. Say what? What I mean is, it’s a way of being notified when some task (of which you have no idea how long it will take) finishes. This is easier to explain with a simple example– like a call to some remote web service :).
In this app’s case, I want to search Instagram’s database of photos. Using a deferred basically let’s me say “get some photos from instagram and give me a heads up when they return”. Oh, and since it’s asynchronous, it doesn’t stop the app from doing other things while the search happens (in other words, it doesn’t lock up your browser). This way, the app can just show a loading icon while it waits for the goods from instagram. The bing class works the same way– while bing does it’s thing and converts a place into lat, long coordinates, the app continues to be responsive.
There’s a bit more going on under the covers to integrate the classes into the app: you need to set up a baseUrl as well as a module path so that dojo knows where to find the classes once they’re referenced. Again, I’ll leave it to the dojo documentation for those things.
So there you have it, the two classes I used to build my instagram search app.