Added new pre-flight delegate callbacks for customization of RKRequest and RKObjectLoader instances before dispatch

This commit is contained in:
Blake Watters
2012-02-15 12:06:24 -05:00
parent 789b0b99eb
commit 948cc85873
5 changed files with 29 additions and 2 deletions

View File

@@ -80,6 +80,16 @@ typedef void(^RKObjectLoaderDidLoadObjectsDictionaryBlock)(NSDictionary *diction
*/
- (void)objectLoaderDidFinishLoading:(RKObjectLoader *)objectLoader;
/**
Informs the delegate that the object loader has serialized the source object into a serializable representation
for sending to the remote system. The serialization can be modified to allow customization of the request payload independent of mapping.
@param objectLoader The object loader performing the serialization.
@param sourceObject The object that was serialized.
@param serialization The serialization of sourceObject to be sent to the remote backend for processing.
*/
- (void)objectLoader:(RKObjectLoader *)objectLoader didSerializeSourceObject:(id)sourceObject toSerialization:(inout id<RKRequestSerializable> *)serialization;
/**
Sent when an object loader encounters a response status code or MIME Type that RestKit does not know how to handle.

View File

@@ -351,6 +351,10 @@
[self didFailLoadWithError:error];
return NO;
}
if ([self.delegate respondsToSelector:@selector(objectLoader:didSerializeSourceObject:toSerialization:)]) {
[self.delegate objectLoader:self didSerializeSourceObject:self.sourceObject toSerialization:&params];
}
self.params = params;
}

View File

@@ -90,7 +90,7 @@
return nil;
}
- (id<RKRequestSerializable>)serializationForMIMEType:(NSString*)MIMEType error:(NSError**)error {
- (id<RKRequestSerializable>)serializationForMIMEType:(NSString *)MIMEType error:(NSError **)error {
if ([MIMEType isEqualToString:RKMIMETypeFormURLEncoded]) {
// Dictionaries are natively RKRequestSerializable as Form Encoded
return [self serializedObject:error];