Skip to content

Instantly share code, notes, and snippets.

@PaulWoodIII
Created January 12, 2013 00:12
Show Gist options
  • Save PaulWoodIII/4515120 to your computer and use it in GitHub Desktop.
Save PaulWoodIII/4515120 to your computer and use it in GitHub Desktop.
Trivial case Login function for usergrid, using RestKit.
- (void)login{
NSURL *baseURL = [NSURL URLWithString:@"https://api.usergrid.com/[org]/[app]"];
AFHTTPClient* client = [[AFHTTPClient alloc] initWithBaseURL:baseURL];
[client setDefaultHeader:@"Accept" value:RKMIMETypeJSON];
[client registerHTTPOperationClass:[AFJSONRequestOperation class]];
NSDictionary *params = [[NSDictionary alloc] initWithObjectsAndKeys:
@"password",@"grant_type",
@"john.doe",@"username",
@"password",@"password",
nil];
[client getPath:@"token"
parameters:params
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSString *access_token = [responseObject objectForKey:@"access_token"];
[[[RKObjectManager sharedManager] HTTPClient] setDefaultHeader:@"Authorization" value:[NSString stringWithFormat:@"Bearer %@", access_token]];
[self postActivity];
[self getFeed];
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"%@",error);
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment