Created
March 12, 2014 05:42
-
-
Save rodericj/9501501 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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