So the problem is that when I'm trying to load entity from here I'm not getting things to work. My Pathpatterns seems to be wrong. Here's my Mapping and Descriptor:
RKEntityMapping *statsMapping = [RKEntityMapping mappingForEntityForName:@"Stat" inManagedObjectStore:managedObjectStore];
[statsMapping addAttributeMappingsFromDictionary:@{
@"sort_id" : @"sortID",
@"id" : @"statID",
@"deleted" : @"deletedFlag",
@"created_at": @"createdAt",
@"updated_at": @"updatedAt"
}];
statsMapping.identificationAttributes = @[ @"statID" ];
[statsMapping addAttributeMappingsFromArray:@[ @"title"]];
RKEntityMapping *featuresMapping = [RKEntityMapping mappingForEntityForName:@"Feature" inManagedObjectStore:managedObjectStore];
[featuresMapping addAttributeMappingsFromDictionary:@{
@"sort_id" : @"sortID",
@"id" : @"featureID",
@"deleted" : @"deletedFlag",
@"created_at": @"createdAt",
@"updated_at": @"updatedAt",
}];
featuresMapping.identificationAttributes = @[ @"featureID" ];
[featuresMapping addAttributeMappingsFromArray:@[ @"title", @"value"]];
[statsMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"features" toKeyPath:@"features" withMapping:featuresMapping]];
RKResponseDescriptor *statsDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:statsMapping
pathPattern: @"/api/cars/:carID/features.json"
keyPath:nil
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[objectManager addResponseDescriptorsFromArray:@[newsDescriptor, catalogDescriptor, statsDescriptor]];
So when I use pathPattern:nil it works, but if no answer is returned by url it just tries to put another responsedescriptor to the response and gives me random data :)
The question is, if I have the car ID in the middle of the pattern, how should I declare it?
Thank you!
Edit1: This is how I do request:
- (void)getStats:(NSNumber *)carID
{
[[RKObjectManager sharedManager] getObjectsAtPath:[NSString stringWithFormat:@"api/cars/%@/features.json", carID]
parameters:@{@"auth_token" : [Constants authToken]}
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
RKLogInfo(@"Load complete: Stats loaded");
}
failure:^(RKObjectRequestOperation *operation, NSError *error) {
RKLogError(@"Load failed with error: %@", error);
[self showError:error withDelay:3];
}];
}