0
votes

In my AppDelegate I am creating mapping like this:

NSDictionary *basicResponseObjectMapping = @{
                                                 @"success" : @"Success",
                                                 @"error" : @"Error",
                                                 };

NSDictionary *reviewObjectMapping = @{
                                          @"text" : @"Text",
                                          };

[manager addResponseDescriptor:ratingResponseDescriptor];

RKObjectMapping *addRatingMapping = [RKObjectMapping mappingForClass:[BasicResponse class]];
[ratingMapping addAttributeMappingsFromDictionary:basicResponseObjectMapping];

RKResponseDescriptor *addRatingResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:addRatingMapping
                                                                                                 method:RKRequestMethodAny
                                                                                            pathPattern:@"/api/ratepoint"
                                                                                                keyPath:nil
                                                                                            statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[manager addResponseDescriptor:addRatingResponseDescriptor];

RKObjectMapping *addRatingRequestMapping = [RKObjectMapping mappingForClass:[Review class]];
[addRatingRequestMapping addAttributeMappingsFromDictionary:reviewObjectMapping];
RKRequestDescriptor *addRatingRequestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:[addRatingRequestMapping inverseMapping]
                                                                                        objectClass:[Review class]
                                                                                        rootKeyPath:nil
                                                                                             method:RKRequestMethodAny];
[manager addRequestDescriptor:addRatingRequestDescriptor];

These are my classes:

@interface BasicResponse : NSObject

@property(nonatomic) NSNumber *Success;
@property(nonatomic) NSString *Error;

@end

@interface Review : NSObject

@property(nonatomic) NSString *Text;

@end

And I am sending my request like this:

RKObjectManager *manager = [RKObjectManager sharedManager];
[manager setRequestSerializationMIMEType:RKMIMETypeFormURLEncoded];
Review *review = [[Review alloc]init];
[review setText:reviewTextView.text];
[manager postObject:review
               path:[NSString stringWithFormat:@"/api/ratepoint/%@?pid=%@&stars=%@", sid, actualPlace.Id,[NSString stringWithFormat:@"%d", [ratingControl rating]]]
         parameters:nil
            success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult)
 {
     NSArray* statuses = [mappingResult array];

     BasicResponse *basicResponse = statuses.firstObject;

 }
            failure:^(RKObjectRequestOperation *operation, NSError *error)
 {
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                     message:[error localizedDescription]
                                                    delegate:nil
                                           cancelButtonTitle:@"OK"
                                           otherButtonTitles:nil];
     [alert show];
 }];

When I look at logging from RESTKit then request mapping is okay. But I have problem with response mapping. I think I have everything okay but I got this in response:

{"success":0,"error":"Some error"}

and this should be mapped by my mapping but it isn't. Here is log trace in pastebin.

1

1 Answers

0
votes

Your response is looking to match against a path of @"/api/ratepoint", but what you actually have is @"/api/ratepoint/...?.... So it doesn't match. That's why you get No response descriptors match the response loaded..

So, fix the response descriptor path patter. Probably @"/api/ratepoint/:sid" will be enough.