Skip to content

Instantly share code, notes, and snippets.

@rodericj
Created March 12, 2014 05:42
Show Gist options
  • Save rodericj/9501501 to your computer and use it in GitHub Desktop.
Save rodericj/9501501 to your computer and use it in GitHub Desktop.
RKEntityMapping* listMapping = [RKEntityMapping mappingForEntityForName:[FOFSList entityName]
inManagedObjectStore:objectManager.managedObjectStore];
[listMapping addAttributeMappingsFromDictionary:@{
@"id": @"listID",
@"title": @"name",
@"description": @"desc",
@"user": @"user",
@"following": @"following",
@"collaborative": @"collaborative",
@"canonicalUrl": @"canonicalUrl",
@"venueCount": @"venueCount",
@"visitedCount": @"visitedCount"
}];
RKDynamicMapping *dynamicMapping = [RKDynamicMapping new];
[listMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:nil
toKeyPath:@"items"
withMapping:dynamicMapping]];
RKResponseDescriptor *listResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:listMapping
method:RKRequestMethodGET
pathPattern:nil
keyPath:@"response.lists.groups"
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[objectManager addResponseDescriptor:listResponseDescriptor];
[dynamicMapping setObjectMappingForRepresentationBlock:^RKObjectMapping *(id representation) {
if ([[representation valueForKey:@"type"] isEqualToString:@"created"]) {
return listMapping;
} else if ([[representation valueForKey:@"type"] isEqualToString:@"followed"]) {
return listMapping;
}
return nil;
}];
listMapping.identificationAttributes = @[ @"listID" ];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment