Skip to content

Instantly share code, notes, and snippets.

@paulmiard
Last active August 29, 2015 13:56
Show Gist options
  • Save paulmiard/8964083 to your computer and use it in GitHub Desktop.
Save paulmiard/8964083 to your computer and use it in GitHub Desktop.
Example for getting "Link" HTTP header using AFNetworking
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:@"https://api.github.com/search/code?q=addClass+user:mozilla&page=4&per_page=42" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
//NSLog(@"JSON: %@", responseObject);
NSDictionary *headers = operation.response.allHeaderFields;
//NSLog(@"Headers: %@", [headers description]);
NSLog(@"Link: %@", [headers objectForKey:@"Link"]);
//Will look like Link: <https://api.github.com/search/code?q=addClass+user%3Amozilla&page=5&per_page=42>; rel="next", <https://api.github.com/search/code?q=addClass+user%3Amozilla&page=24&per_page=42>; rel="last", <https://api.github.com/search/code?q=addClass+user%3Amozilla&page=1&per_page=42>; rel="first", <https://api.github.com/search/code?q=addClass+user%3Amozilla&page=3&per_page=42>; rel="prev"
//Below parser examples in other languages. Didn't find an Objective-C version but easy enough to port
// Java: https://github.com/eclipse/egit-github/blob/master/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/PageLinks.java#L43-75
// JS: https://gist.github.com/niallo/3109252
// Ruby (last section): http://developer.github.com/guides/traversing-with-pagination/
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment