Skip to content

Instantly share code, notes, and snippets.

@sumardi
Created December 26, 2012 04:13
Show Gist options
  • Save sumardi/4377790 to your computer and use it in GitHub Desktop.
Save sumardi/4377790 to your computer and use it in GitHub Desktop.
TCC Authentication API Call using RestKit
RKObjectManager *manager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:@"http://refapi.thecurrencycloud.com"]];
// Response Mapping
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[TCC class]];
[mapping addAttributeMappingsFromDictionary:@{@"status" : @"status", @"data" : @"token", @"message" : @"message"}];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:mapping pathPattern:nil keyPath:nil statusCodes:nil];
[manager addResponseDescriptor:responseDescriptor];
// Request Mapping
RKObjectMapping *requestMapping = [RKObjectMapping requestMapping];
[requestMapping addAttributeMappingsFromArray:@[@"login_id", @"api_key"]];
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:requestMapping objectClass:[TCC class] rootKeyPath:nil];
[manager addRequestDescriptor:requestDescriptor];
// Open session for further API Call
TCC *obj = [TCC new];
obj.login_id = TCCAPI_ID;
obj.api_key = TCCAPI_KEY;
[manager postObject:obj path:@"/api/en/v1.0/authentication/token/new" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
TCC *responseObj = (TCC *)[[mappingResult array] objectAtIndex:0];
NSLog(@"%@", responseObj.token); // Token string
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"%@", [error localizedDescription]);
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment