Reputation: 10759
I have a project where I am setting up all responseDescriptors (8 of them) and mappings (8 of them) when my RestEngine class is established... I set them up ahead of time rather during each call. I am not sure if this good practice or not.
The issue is that one of my descriptors seems to be mapping all results when it shouldn't.
I think the issue lies in my thingDescriptor or it could be the following route (v1/things/:thingID\.json), but this route is a GET so I wouldn't think my POST request would go through this route?
Here is the POST request I am making that is getting a result mapped to a specific CLASS which it shouldn't be or rather I don't want it to be mapped to a specific class.
[[RKObjectManager sharedManager] postObject:nil
path:@"v1/things/request.json"
parameters:@{
@"auth_token" : self.accessToken,
@"api_key" : self.api_key,
@"lat" : lat,
@"lng" : lng
}
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
RKLogInfo(@"Post request of an Thing Request start tracking request update...");
<-- the mappingResult shows its mapped to a Thing class but I want server response to mapped to an NSDictionary instead?
}
failure:^(RKObjectRequestOperation *operation, NSError *error) {
RKLogError(@"Post request of an Thing Request failed with error: %@", error);
}];
Here are my mappings that are setup:
// Routes for Things
[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[Thing class]
pathPattern:@"v1/things/:thingID\\.json"
method:RKRequestMethodGET]];
[objectManager.router.routeSet addRoute:[RKRoute routeWithName:kRouteUpdateThingLoc
pathPattern:@"v1/things/update_location.json"
method:RKRequestMethodPOST]];
[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[Thing class]
pathPattern:@"v1/things.json"
method:RKRequestMethodPOST]];
// Register our mappings with the provider
RKResponseDescriptor *thingResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:thingMapping
pathPattern:@"v1/things.json"
keyPath:nil
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
RKResponseDescriptor *thingDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:thingMapping
pathPattern:@"v1/things/:thingID.json"
keyPath:nil
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
Upvotes: 1
Views: 527
Reputation: 10759
Some typos above:
AFHTTPClient *client = [AFHTTPClient clientWithBaseURL:[[NSURL alloc] initWithString:@"http://my.herokuapp.com/"]];
NSDictionary *parameters = @{
@"api_key" : self.api_key,
@"acode" : code
};
NSMutableURLRequest *request = [client requestWithMethod:@"POST" path:@"v1/users/approve_by_code.json" parameters:parameters];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSLog(@"THIS IS A DICTIONARY (or array): %@", JSON);
object:nil];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
NSLog(@"if requestFailed");
}];
[operation start];
Upvotes: 0
Reputation: 4085
Use AFNetworking Like So:
AFHTTPClient *client = [AFHTTPClient clientWithBaseURL:@"v1/"];
NSDictionary *parameters = @{
@"auth_token" : self.accessToken,
@"api_key" : self.api_key,
@"lat" : lat,
@"lng" : lng
};
NSMutableURLRequest *request = [client requestWithMethod:@"POST" path:@"things/request.json" parameters:parameters];
AFJSONRequestOperation *opertaion = [AFJSONRequestOperation JSONRequestOperationWithRequest:responseObject success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSLog(@"THIS IS A DICTIONARY (or array): %@", JSON);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
NSLog(@"if requestFailed");
}];
Upvotes: 1