Skip to content

Instantly share code, notes, and snippets.

@blakewatters
Created November 16, 2011 00:00
Show Gist options
  • Save blakewatters/1368819 to your computer and use it in GitHub Desktop.
Save blakewatters/1368819 to your computer and use it in GitHub Desktop.
sendData:toResourcePath:usingBlock
// Encode some arbitrary data and send it to the remote server. Object mapping will be performed on the results
- (RKObjectLoader *)sendData:(id)data toResourcePath:(NSString *)resourcePath usingBlock:(void (^)(RKObjectLoader *objectLoader))block {
RKObjectLoader* loader = [self objectLoaderWithResourcePath:resourcePath delegate:nil];
id<RKParser> parser = [[RKParserRegistry sharedRegistry] parserForMIMEType:self.serializationMIMEType];
NSString* string = [parser stringFromObject:serializedObject error:error];
NSData* data = [string dataUsingEncoding:NSUTF8StringEncoding];
loader.params = [RKRequestSerialization serializationWithData:data MIMEType:self.serializationMIMEType];
loader.method = RKRequestMethodPOST;
// Yield to the block for setup
block(loader);
[loader send];
return loader;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment