Skip to content

Instantly share code, notes, and snippets.

@andreortiz82
Created June 14, 2012 19:17
Show Gist options
  • Save andreortiz82/2932325 to your computer and use it in GitHub Desktop.
Save andreortiz82/2932325 to your computer and use it in GitHub Desktop.
Callback block method with success:fail params
/*
=====================================================
GetPlayer:Dribbble
=====================================================
*/
- (void)getPlayer:(NSString*)playername success:(void (^)(NSMutableDictionary *deals))success failure:(void (^)(NSError *error))failure
{
NSLog(@"Dribbble test");
NSURL *url = [NSURL URLWithString:@"http://api.dribbble.com/players/"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
NSURLRequest *request = [httpClient requestWithMethod:@"GET" path:playername parameters:nil];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
if (success) {
success(JSON);
}
} failure:^(NSURLRequest *request , NSURLResponse *response , NSError *error , id JSON) {
if (failure) {
failure(error);
}
}];
[operation start];
}
/*
=====================================================
GetPlayer:Dribbble Implementation
=====================================================
*/
[self.service getPlayer:@"andreortiz" success:^(NSMutableDictionary *deals) {
NSLog(@"viewDidLoad:success %@", deals);
} failure:^(NSError *error) {
NSLog(@"viewDidLoad:failure %@", error);
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment