psst... it's a FatSecret
We’re working on a new app, as some of you may know, and it’s required we find some sort of database to get food data from. Calories, protein, serving sizes, etc. We started with the USDA food database. This thing is a piece of garbage. Naming conventions are inconsistent and absurdly long, sometimes in ALL CAPS even. It was also missing several fairly common foods (coconut oil, anyone?). Not to mention it’s distributed as either a Microsoft Access database, an Excel sheet, or a custom file format. Really? Access or Excel? Those were immediately unusable to us, so we were left with the custom file format. This thing is a real piece of work, let me give you a taste:
~06075~^~SOUP,BF BROTH OR BOUILLON,PDR,DRY~^3.27^213
^3.616^0.332^10^3.6^~1 cube~^6.0^~1 packet~^0
I spent a good many hours writing a custom parser for that beauty. Why in the world can’t they just do JSON, or I’d even get my big-boy pants on and suffer through some XML. We no longer live in an age when your best option is custom file formats! At the VERY least provide some sort of parser I can use. I… just… how…
So we decided to pivot. We did some searching and found FatSecret. It’s paid for the Premier tier (which we’ll probably end up having to get) but it also has a free plan. Hallelujah.
After determining that it was our best option, I unknowingly dove into the pits of OAuth hell. It authenticates with OAuth, which is fine, except there’s not fantastic iOS library support for OAuth. I did some searching and the best I could find was OAuthCore, which generates a signed header, but I needed it as a query string in a GET request. Wasn’t too tough, just switched a few lines of code, debugged it a good while, scratched my head, and suddenly it worked. I was moments away from giving up when light shown through the heavens and I was Enlightened. I got back some JSON of food. And it was very desirable. Consistent naming, hundreds of results, it was beautiful. I cried. Not really, I drank some Pomegranate 7-up and kissed my wife.
All there was left to do was abstract my code into an open source library. I’d give you a song-and-dance about MT’s commitment (read: burning passion) for open source (which is true) but it really, in this case, came down to how cool CocoaPods is that there’s really no reason not to open source something like this. Here it is, if you ever need it. I pray even my worst enemy won’t find that USDA database.
And that’s the Tale of FatSecretKit.