// U header fajlu definises delegate: // u didFinishLaunching inicijalizujes singletone objekat RKClient i setujes domen za service: RKClient *client = [RKClient clientWithBaseURL:@"http://taksiko.com"]; // u implementaciji ovako posaljes zahtev: userParams = [NSDictionary dictionaryWithObjectsAndKeys:[defaults objectForKey:@"login"], @"table_number", [defaults objectForKey:@"password"], @"driver_password", nil]; [RKClient sharedClient].username = @"mladjan"; [RKClient sharedClient].password = @"password"; [RKClient sharedClient].forceBasicAuthentication = YES; [[RKClient sharedClient] post:@"/api/driver_login.json" params:userParams delegate:self]; // A u delegate metodi primas sve response i ispitujes od kog je request-a (ja imam vise requesta u sigleton klasi #pragma mark - Responses - (void)request:(RKRequest*)request didLoadResponse:(RKResponse*)response { if([request params] == userParams){ if([[response bodyAsString] isEqualToString:@"ERROR"]){ logedIn = FALSE; [[NSNotificationCenter defaultCenter] postNotificationName:@"presentLoginView" object:nil]; NSLog(@"Login: %@", [response bodyAsString]); }else{ NSLog(@"Dobar je mali!"); } } else if([request params] == stateParams){ [[NSNotificationCenter defaultCenter] postNotificationName:@"removeLoading" object:nil]; if([response statusCode] != 200 || [[response bodyAsString] isEqualToString:@"ERROR"]){ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Oups" message:@"Sorry, but I can't change your state. Try again." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release]; }else if([response statusCode] == 200){ NSDictionary *responseDictionary = [[response bodyAsString] objectFromJSONString]; currentState = (int)[responseDictionary objectForKey:@"state"]; } } else if([request params] == locationParams){ if([[response bodyAsString] isEqualToString:@"OK"]){ NSLog(@"Location updated"); }else if([[response bodyAsString] isEqualToString:@"ERROR"]){ NSLog(@"Location not updated!!!!"); } } }