loader.params for sendObject:toResourcePath:usingBlock - How to append extra params?

191 views
Skip to first unread message

Damon Aw

unread,
Jun 26, 2012, 8:41:52 AM6/26/12
to res...@googlegroups.com
Hi, 

I'm doing a POST and I'm not using the RKRouter class. 

So I've setup a simple call, 

RKParams *params = [RKParams paramsWithDictionary:optionValues];

[RKObjectManager sharedManager] sendObject:objectToBeSent toResourcePath:@"some_path" usingBlock:^(RKObjectLoader *loader) {
  loader.method = RKRequestMethodPOST;
  loader.params = additionalParams; // Problematic line for me
}

The problem for me is the moment I set loader.params = addtionalParams, the only data that gets sent to the server is the additionalParams. The previous send object part is totally ignored. Is there any method to just insert additional Params only or can I map my object's params onto the RKParams object? 

Thanks in advance.

Sebastian-Andrei Gherman

unread,
Jun 26, 2012, 10:07:45 AM6/26/12
to res...@googlegroups.com
Hi,

You can map your object's params onto the RKParams by doing:

RKObjectMapping *serializationMapping = [[[RKObjectManager sharedManager] mappingProvider] serializationMappingForClass:[ClassToSend class]];
NSError* error = nil;
NSDictionary* dictionary = [[RKObjectSerializer serializerWithObject:objectToBeSent mapping:serializationMapping] serializedObject:&error];
 RKParams* params = [RKParams paramsWithDictionary:dictionary];
// add the optional param values here
loader.params = params;

Hope this helps,
Sebastian

Damon Aw

unread,
Jun 26, 2012, 12:56:49 PM6/26/12
to res...@googlegroups.com
Hey Sebastian, 

Thanks man! It helps a LOT =) 

I was just hoping there's a quick and easy way to append in some extra params not relevant to the object mapping before the post. 

Cheers,
Damon
Reply all
Reply to author
Forward
0 new messages