Created
January 12, 2013 00:12
-
-
Save PaulWoodIII/4515120 to your computer and use it in GitHub Desktop.
Trivial case Login function for usergrid, using RestKit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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