The first task I gave myself when writing the Celery Application is to obtain nutritional information for various foods. I’ll need to provide a means to request a list of food that matches a search query and a way of getting more information about a particular food from that list. As I mentioned before, I found the FatSecret REST API, and decided to use this for these two requests. FatSecret supports “foods.search” and “food.get” methods that meet my needs. FatSecret also uses oauth for authentication.
My list of tasks were as follows:
- Obtain the necessary keys to communicate with FatSecret.
- Find a Cocoa Library to use oauth.
- Establish a connection and call methods as needed.
1. Obtain the necessary keys to communicate with FatSecret. This was easy enough, simply went to this site and registered the application I was making. This provided me with a Public Consumer Key and the applications Private Key. These keys were emailed to me, and they were ready to be used.
2. Find a Cocoa Library to use oauth. As I mentioned in a previous post, I found MPOauthConnection for establishing an oauth connection and calling methods on a REST Library. I downloaded the source using Subversion and opened the library. After running the Build, Xcode proceeded to lock up completely. All I got was the Beachball of Death. I stared at it, tried a couple more times, but could not successfully build the project. After awhile, I noticed that it was failing to proceed past the Unit Tests. I figured, I’m not modifying the Library, and therefore, don’t really need to run the Unit Tests. So, I opened up the Unit Test target and deleted it. Kicked off the Build and it succeeded.
I was going to start up the Celery project, but decided to go ahead and modify the existing test application to communicate with FatSecret.
3. Establish a connection and call methods as needed. The first thing that I had to do was match up what MPOAuthConnection expects to what FatSecret API expects, including slightly different nomenclature. I started by plugging in the values for the Base Host URL, Shared Secret and Consumer Key and the method to call. The method to call stumped me a bit, as the FatSecret sets the actual method to a parameter (method=VALUE). Where the method for the API is server.api. That really took me awhile to figure out. Secondly, the provided example had no usage of method parameters (making it a very flawed example, in my opinion). I struggled then to figure out the API to pass parameters, finding a Unit Test in code, I was able to figure this out and successfully make calls to the API, searching for a food, and getting information for that food.
The next step will be to build my own Celery project and duplicate this functionality in what will become my own Application.