TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | BSD |
ReleasedLast Release | Mar 2016 |
Maintained by Adam Kirk, Parker Wightman.
iOS Client for the FatSecret API.
Install via CocoaPods by adding this to your Podfile
:
pod 'FatSecretKit'
Then import
it as necessary
#import <FatSecretKit/FSClient.h>
The toughest part of making your own client is the OAuth negotiation, so this should save you some precious hours. All you need is your OAuth consumer key and secret. Preferred usage is through the sharedClient
:
[FSClient sharedClient].oauthConsumerKey = @"12345";
[FSClient sharedClient].oauthConsumerSecret = @"67890";
You should put that in your AppDelegate.m
or similar, where it will only run once. You can always create your own clients with the usual [[FSClient alloc] init]
.
You're all set to use the APIs.
[[FSClient sharedClient] searchFoods:term
completion:^(NSArray *foods, NSInteger maxResults, NSInteger totalResults, NSInteger pageNumber) {
// Use data as you will.
self.foods = foods;
[self.tableView reloadData];
}];
// A more verbose version of the above, if you want to utilize the full paramters of the API
[[FSClient sharedClient] searchFoods:term
pageNumber:0
maxResults:50
completion:^(NSArray *foods, NSInteger maxResults, NSInteger totalResults, NSInteger pageNumber) {
// Use data as you will.
self.foods = foods;
[self.tableView reloadData];
}];
[[FSClient sharedClient] getFood:item.identifier
completion:^(FSFood *food) {
NSLog(@"Name: %@", food.name)
}];
There are also native objects to represent resources returned by the API, including FSFood
, which represents a food resource, and FSServing
, which represents the servings for each food, returned by the food.get
API method (among others).
New methods for fetching resources should be added to the FSClient
class, and new native objects can be created as necessary. Naming conventions for client methods should follow the same convention:
API: foods.search
, iOS: searchFoods
API: food.get
, iOS: getFood
etc.
New methods/properties on native objects should follow a similar convention
API: trans_fat
, iOS: transFat
API: saturated_fat
, iOS: saturatedFat
etc.
Adding support for new API methods requires creating an appropriately named method inside FSClient
, and it should support all required and optional parameters, though convenience methods are also welcome (see searchFoods
methods as a reference.) You can always questions on Twitter or through issues, we're nice guys.
git checkout -b my-new-feature
)git commit -am 'Added some feature'
)git push origin my-new-feature
)Parker Wightman (@parkerwightman)
Thanks to atebits for his OAuthCore library that made this much simpler. Thanks also to Sam Vermette for his execellent SVHTTPRequest library.