異なるクエリ文字列を持つ同じリソースについて話している。リクエストを送信するときにクエリ文字列パラメーターを追加するだけです..つまり
NSDictionary *params = @{@"res":@"people"};
[[RKObjectManager sharedManager] getObjectsAtPath:@"api/"
parameters:params
success:^(RKObjectRequestOperation *operation,
RKMappingResult *mappingResult) {
// blah blah
ここに私自身のコードからのより包括的な例があります..「ドキュメントの方が良いかもしれない」全体を完全に理解しています..2つのエンティティマッピングがあることに注意してください(2つの異なるエンティティに対して)..イベントと出席者:
// Configure the object manager
_objectManager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:@"http://mydomain.com/api/v1"]];
_objectManager.managedObjectStore = _managedObjectStore;
[RKObjectManager setSharedManager:_objectManager];
_objectManager.requestSerializationMIMEType=RKMIMETypeJSON;
RKEntityMapping *eventEntityMapping = [RKEntityMapping mappingForEntityForName:@"Event" inManagedObjectStore:_managedObjectStore];
[eventEntityMapping addAttributeMappingsFromDictionary:@{
@"id": @"id",
@"resource_uri": @"resource_uri",
@"title": @"title",
@"city": @"city",
@"from_date": @"from_date",
@"user": @"user_id"}];
eventEntityMapping.identificationAttributes = @[ @"id" ];
RKResponseDescriptor *eventResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:eventEntityMapping pathPattern:@"event/" keyPath:@"objects" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[_objectManager addResponseDescriptor:eventResponseDescriptor];
RKEntityMapping *attendeeEntityMapping = [RKEntityMapping mappingForEntityForName:@"Attendee" inManagedObjectStore:_managedObjectStore];
[attendeeEntityMapping addAttributeMappingsFromDictionary:@{
@"id": @"id",
@"order.first_name": @"first_name",
@"order.last_name": @"last_name",
@"unique": @"order_ticket_unique_code",
@"ticket.event": @"event_id",
@"ticket.description": @"ticket_description",
@"ticket.perk": @"ticket_perk",
@"ticket.price": @"ticket_price"}];
attendeeEntityMapping.identificationAttributes = @[ @"id" ];
RKResponseDescriptor *attendeeResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:attendeeEntityMapping pathPattern:@"orderticket/search/" keyPath:@"objects" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
_objectManager.requestSerializationMIMEType=RKMIMETypeJSON;
[_objectManager addResponseDescriptor:attendeeResponseDescriptor];
後で、出席者のリソースを取得するだけです (API では orderticket と呼ばれます。何でも)
- (void)downloadAttendees
{
NSDictionary *params = @{@"q":_eventId};
[[RKObjectManager sharedManager] getObjectsAtPath:@"orderticket/search/" parameters:params success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
[self.tableView reloadData];
[self.refreshControl endRefreshing];
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
[self.refreshControl endRefreshing];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"An Error Has Occurred" message:[error localizedDescription] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}];
}
また、イベント リソースもフェッチします (イベント リソースはクエリ文字列を取りません)。
- (void)downloadEvents
{
[[RKObjectManager sharedManager] getObjectsAtPath:@"event/" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
[self.tableView reloadData];
[self.refreshControl endRefreshing];
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
[self.refreshControl endRefreshing];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"An Error Has Occurred" message:[error localizedDescription] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}];
}