Permalink
Browse files

Converting tabs -> spaces.

  • Loading branch information...
1 parent 44a278e commit 10b0957189e2106d2532910359b50e271079984e @pwightman pwightman committed Feb 21, 2013
@@ -19,14 +19,14 @@ typedef void(^FSFoodSearchBlock)(NSArray *foods, NSInteger maxResults, NSInteger
- (void)searchFoods:(NSString *)foodText
- pageNumber:(NSInteger)pageNumber
- maxResults:(NSInteger)maxResults
- completion:(FSFoodSearchBlock)completionBlock;
+ pageNumber:(NSInteger)pageNumber
+ maxResults:(NSInteger)maxResults
+ completion:(FSFoodSearchBlock)completionBlock;
- (void)searchFoods:(NSString *)foodText completion:(FSFoodSearchBlock)completionBlock;
-
+
- (void)getFood:(NSInteger)foodId completion:(void (^)(FSFood *food))completionBlock;
+ (FSClient *)sharedClient;
-@end
+@end
@@ -18,105 +18,109 @@
@implementation FSClient
- (void)searchFoods:(NSString *)foodText
- pageNumber:(NSInteger)pageNumber
- maxResults:(NSInteger)maxResults
- completion:(FSFoodSearchBlock)completionBlock {
-
- NSMutableDictionary *params = [@{
- @"search_expression": foodText,
- @"page_number": @(pageNumber),
- @"max_results": @(maxResults)
- } mutableCopy];
-
- [self makeRequestWithMethod:@"foods.search" parameters:params completion:^(NSDictionary *response) {
- NSMutableArray *foods = [@[] mutableCopy];
-
- id responseFoods = [response objectForKey:@"foods"];
-
- // Hack because the API sends JSON objects, instead of arrays, when there is only
- // one result. (WTF?)
- if ([[responseFoods objectForKey:@"food"] respondsToSelector:@selector(arrayByAddingObject:)]) {
-
- for (NSDictionary *food in [responseFoods objectForKey:@"food"]) {
- [foods addObject:[FSFood foodWithJSON:food]];
- }
- } else {
- if ([[responseFoods objectForKey:@"food"] count] == 0) {
- foods = [@[] mutableCopy];
- } else {
- foods = [@[ [FSFood foodWithJSON:[responseFoods objectForKey:@"food"]] ] mutableCopy];
- }
- }
-
- NSInteger maxResults = [[[response objectForKey:@"foods"] objectForKey:@"max_results"] integerValue];
- NSInteger totalResults = [[[response objectForKey:@"foods"] objectForKey:@"total_results"] integerValue];
- NSInteger pageNumber = [[[response objectForKey:@"foods"] objectForKey:@"page_number"] integerValue];
-
- completionBlock(foods, maxResults, totalResults, pageNumber);
- }];
+ pageNumber:(NSInteger)pageNumber
+ maxResults:(NSInteger)maxResults
+ completion:(FSFoodSearchBlock)completionBlock {
+
+ NSMutableDictionary *params = [@{
+ @"search_expression" : foodText,
+ @"page_number" : @(pageNumber),
+ @"max_results" : @(maxResults)
+ } mutableCopy];
+
+ [self makeRequestWithMethod:@"foods.search" parameters:params completion:^(NSDictionary *response) {
+ NSMutableArray *foods = [@[] mutableCopy];
+
+ id responseFoods = [response objectForKey:@"foods"];
+
+ // Hack because the API sends JSON objects, instead of arrays, when there is only
+ // one result. (WTF?)
+ if ([[responseFoods objectForKey:@"food"] respondsToSelector:@selector(arrayByAddingObject:)]) {
+ for (NSDictionary *food in [responseFoods objectForKey:@"food"]) {
+ [foods addObject:[FSFood foodWithJSON:food]];
+ }
+ } else {
+ if ([[responseFoods objectForKey:@"food"] count] == 0) {
+ foods = [@[] mutableCopy];
+ } else {
+ foods = [@[ [FSFood foodWithJSON:[responseFoods objectForKey:@"food"]] ] mutableCopy];
+ }
+ }
+
+ NSInteger maxResults = [[[response objectForKey:@"foods"] objectForKey:@"max_results"] integerValue];
+ NSInteger totalResults = [[[response objectForKey:@"foods"] objectForKey:@"total_results"] integerValue];
+ NSInteger pageNumber = [[[response objectForKey:@"foods"] objectForKey:@"page_number"] integerValue];
+
+ completionBlock(foods, maxResults, totalResults, pageNumber);
+ }];
}
-- (void)searchFoods:(NSString *)foodText
- completion:(FSFoodSearchBlock)completionBlock {
- [self searchFoods:foodText
- pageNumber:0
- maxResults:20
- completion:completionBlock];
+- (void)searchFoods:(NSString *)foodText completion:(FSFoodSearchBlock)completionBlock {
+ [self searchFoods:foodText
+ pageNumber:0
+ maxResults:20
+ completion:completionBlock];
}
- (void)getFood:(NSInteger)foodId completion:(void (^)(FSFood *food))completionBlock {
- NSDictionary *params = @{@"food_id" : @(foodId)};
-
- [self makeRequestWithMethod:@"food.get"
- parameters:params
- completion:^(NSDictionary *data) {
- completionBlock([FSFood foodWithJSON:[data objectForKey:@"food"]]);
- }];
+ NSDictionary *params = @{@"food_id" : @(foodId)};
+
+ [self makeRequestWithMethod:@"food.get"
+ parameters:params
+ completion:^(NSDictionary *data) {
+ completionBlock([FSFood foodWithJSON:[data objectForKey:@"food"]]);
+ }];
}
- (void) makeRequestWithMethod:(NSString *)method
- parameters:(NSDictionary *)params
- completion:(void (^)(NSDictionary *data))completionBlock {
-
- NSMutableDictionary *parameters = [params mutableCopy];
- [parameters addEntriesFromDictionary:[self defaultParameters]];
- [parameters addEntriesFromDictionary:@{@"method" : method}];
-
- NSString *queryString = [self queryStringFromDictionary:parameters];
- NSData *data = [NSData dataWithBytes:[queryString UTF8String] length:queryString.length];
- NSString *authHeader = OAuthorizationHeader([NSURL URLWithString:FAT_SECRET_API_ENDPOINT], @"GET", data, _oauthConsumerKey, _oauthConsumerSecret, nil, @"");
-
- [SVHTTPRequest GET:[FAT_SECRET_API_ENDPOINT stringByAppendingFormat:@"?%@", authHeader]
- parameters:nil
- completion:^(id response, NSHTTPURLResponse *urlResponse, NSError *error) {
- completionBlock(response);
- }];
-
+ parameters:(NSDictionary *)params
+ completion:(void (^)(NSDictionary *data))completionBlock {
+
+ NSMutableDictionary *parameters = [params mutableCopy];
+ [parameters addEntriesFromDictionary:[self defaultParameters]];
+ [parameters addEntriesFromDictionary:@{ @"method" : method }];
+
+ NSString *queryString = [self queryStringFromDictionary:parameters];
+ NSData *data = [NSData dataWithBytes:[queryString UTF8String] length:queryString.length];
+ NSString *authHeader = OAuthorizationHeader([NSURL URLWithString:FAT_SECRET_API_ENDPOINT],
+ @"GET",
+ data,
+ _oauthConsumerKey,
+ _oauthConsumerSecret,
+ nil,
+ @"");
+
+ [SVHTTPRequest GET:[FAT_SECRET_API_ENDPOINT stringByAppendingFormat:@"?%@", authHeader]
+ parameters:nil
+ completion:^(id response, NSHTTPURLResponse *urlResponse, NSError *error) {
+ completionBlock(response);
+ }];
+
}
- (NSDictionary *) defaultParameters {
- return @{ @"format": @"json" };
+ return @{ @"format": @"json" };
}
- (NSString *) queryStringFromDictionary:(NSDictionary *)dict {
- NSMutableArray *entries = [@[] mutableCopy];
-
- for (NSString *key in dict) {
- NSString *value = [dict objectForKey:key];
- [entries addObject:[NSString stringWithFormat:@"%@=%@", key, value]];
- }
-
- return [entries componentsJoinedByString:@"&"];
+ NSMutableArray *entries = [@[] mutableCopy];
+
+ for (NSString *key in dict) {
+ NSString *value = [dict objectForKey:key];
+ [entries addObject:[NSString stringWithFormat:@"%@=%@", key, value]];
+ }
+
+ return [entries componentsJoinedByString:@"&"];
}
static FSClient *_sharedClient = nil;
+ (FSClient *)sharedClient {
- if (!_sharedClient) {
- _sharedClient = [[FSClient alloc] init];
- }
-
- return _sharedClient;
+ if (!_sharedClient) {
+ _sharedClient = [[FSClient alloc] init];
+ }
+
+ return _sharedClient;
}
-@end
+@end
@@ -12,45 +12,45 @@
@implementation FSFood
- (id) initWithJSON:(NSDictionary *)json {
- self = [super init];
- if (self) {
- _name = [json objectForKey:@"food_name"];
- _foodDescription = [json objectForKey:@"food_description"];
- _type = [json objectForKey:@"food_type"];
- _url = [json objectForKey:@"food_url"];
- _identifier = [[json objectForKey:@"food_id"] integerValue];
- _brandName = [json objectForKey:@"brand_name"];
-
- id servings = [json objectForKey:@"servings"];
-
- _servings = @[];
-
- if (servings) {
- servings = [servings objectForKey:@"serving"];
-
- // This is a hack to figure out if servings is an array or a dictionary
- // since the API returns a dictionary if there's only one serving (WTF?)
- if ([servings respondsToSelector:@selector(arrayByAddingObject:)]) {
- NSMutableArray *array = [@[] mutableCopy];
- for (NSDictionary *serving in servings) {
- [array addObject:[FSServing servingWithJSON:serving]];
- }
- _servings = array;
- } else {
- if ([servings count] == 0) {
- _servings = @[];
- } else {
- _servings = @[ [FSServing servingWithJSON:servings] ];
- }
- }
- }
- }
-
- return self;
+ self = [super init];
+ if (self) {
+ _name = [json objectForKey:@"food_name"];
+ _foodDescription = [json objectForKey:@"food_description"];
+ _type = [json objectForKey:@"food_type"];
+ _url = [json objectForKey:@"food_url"];
+ _identifier = [[json objectForKey:@"food_id"] integerValue];
+ _brandName = [json objectForKey:@"brand_name"];
+
+ id servings = [json objectForKey:@"servings"];
+
+ _servings = @[];
+
+ if (servings) {
+ servings = [servings objectForKey:@"serving"];
+
+ // This is a hack to figure out if servings is an array or a dictionary
+ // since the API returns a dictionary if there's only one serving (WTF?)
+ if ([servings respondsToSelector:@selector(arrayByAddingObject:)]) {
+ NSMutableArray *array = [@[] mutableCopy];
+ for (NSDictionary *serving in servings) {
+ [array addObject:[FSServing servingWithJSON:serving]];
+ }
+ _servings = array;
+ } else {
+ if ([servings count] == 0) {
+ _servings = @[];
+ } else {
+ _servings = @[ [FSServing servingWithJSON:servings] ];
+ }
+ }
+ }
+ }
+
+ return self;
}
+ (id) foodWithJSON:(NSDictionary *)json {
- return [[self alloc] initWithJSON:json];
+ return [[self alloc] initWithJSON:json];
}
Oops, something went wrong.

0 comments on commit 10b0957

Please sign in to comment.