Skip to content

Instantly share code, notes, and snippets.

@qiscus
Last active December 19, 2015 00:09
Show Gist options
  • Save qiscus/5866610 to your computer and use it in GitHub Desktop.
Save qiscus/5866610 to your computer and use it in GitHub Desktop.
NSURL *url = [NSURL URLWithString:@"http://localhost:3000/users/sign_in.json"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
NSString *postString = @"user[email][email protected]&user[password]=halo123123";
[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSString *status = [JSON valueForKeyPath:@"success"];
NSLog(@"status = %@", status);
if(status){
token = [JSON valueForKeyPath:@"token"];
NSLog(@"%@", token);
NSString *stringurl = (@"http://localhost:3000/user/getroomlist?token=%@", token);
NSURL *url2 = [NSURL URLWithString:stringurl];
NSURLRequest *request2 = [NSURLRequest requestWithURL:url2];
AFJSONRequestOperation *operation2 = [AFJSONRequestOperation JSONRequestOperationWithRequest:request2 success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSString *success = nil;
NSArray *rooms = nil;
rooms = [JSON objectForKey:@"rooms"];
NSLog(@"%@", rooms);
//yang sini udah ga kepanggil
} failure:nil];
[operation2 start];
}
} failure:nil];
[operation start];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment