Merge branch 'master' of github.com:twotoasters/RestKit

Conflicts:
	Code/RKModelLoader.m
This commit is contained in:
Blake Watters
2010-03-11 12:24:19 -05:00
5 changed files with 43 additions and 14 deletions

View File

@@ -68,7 +68,11 @@
- (void)processLoadModelInBackground:(RKResponse*)response {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
id model = response.request.userData;
[_mapper mapModel:model fromString:[response payloadString]];
if (model) {
[_mapper mapModel:model fromString:[response payloadString]];
} else {
model = [_mapper mapFromString:[response payloadString]];
}
[_delegate performSelectorOnMainThread:self.callback withObject:model waitUntilDone:NO];
[pool release];
}

View File

@@ -274,12 +274,15 @@ static const NSString* kRKModelMapperRailsDateFormatString = @"MM/dd/yyyy";
NSMutableSet* children = [NSMutableSet setWithCapacity:[relationshipElements count]];
for (NSDictionary* childElements in relationshipElements) {
id child = [self createOrUpdateInstanceOfModelClass:class fromElements:childElements];
[children addObject:child];
if (child) {
[children addObject:child];
}
}
[object setValue:children forKey:propertyName];
} else {
Class class = [_elementToClassMappings objectForKey:elementKeyPath];
} else if ([relationshipElements isKindOfClass:[NSDictionary class]]) {
NSArray* componentsOfKeyPath = [elementKeyPath componentsSeparatedByString:@"."];
Class class = [_elementToClassMappings objectForKey:[componentsOfKeyPath objectAtIndex:[componentsOfKeyPath count] - 1]];
id child = [self createOrUpdateInstanceOfModelClass:class fromElements:relationshipElements];
[object setValue:child forKey:propertyName];
}

View File

@@ -94,14 +94,33 @@ static NSString* kRKStringBoundary = @"0xKhTmLbOuNdArY";
int i = 0;
for (id key in _valueData) {
id value = [_valueData valueForKey:key];
NSLog(@"Attempting to add HTTP param named %@ with type %@ and value %@", key, [value class], value);
[HTTPBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n", key] dataUsingEncoding:NSUTF8StringEncoding]];
// TODO: Can get _PFCachedNumber objects back from valueForKey: from Core Data. Need to figure this out...
if ([value respondsToSelector:@selector(dataUsingEncoding:)]) {
[HTTPBody appendData:[value dataUsingEncoding:NSUTF8StringEncoding]];
if ([value isKindOfClass:[NSArray class]]) {
int j = 0;
for (id object in (NSArray*)value) {
NSString* arrayKey = [NSString stringWithFormat:@"%@[]", key];
NSLog(@"Attempting to add HTTP param named %@ with type %@ and value %@", arrayKey, [object class], object);
[HTTPBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n", arrayKey] dataUsingEncoding:NSUTF8StringEncoding]];
// TODO: Can get _PFCachedNumber objects back from valueForKey: from Core Data. Need to figure this out...
if ([object respondsToSelector:@selector(dataUsingEncoding:)]) {
[HTTPBody appendData:[object dataUsingEncoding:NSUTF8StringEncoding]];
} else {
[HTTPBody appendData:[[NSString stringWithFormat:@"%@", object] dataUsingEncoding:NSUTF8StringEncoding]];
}
j++;
if (j != [value count]) {
[HTTPBody appendData:[self endItemBoundary]];
}
}
} else {
[HTTPBody appendData:[[NSString stringWithFormat:@"%@", value] dataUsingEncoding:NSUTF8StringEncoding]];
}
NSLog(@"Attempting to add HTTP param named %@ with type %@ and value %@", key, [value class], value);
[HTTPBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n", key] dataUsingEncoding:NSUTF8StringEncoding]];
// TODO: Can get _PFCachedNumber objects back from valueForKey: from Core Data. Need to figure this out...
if ([value respondsToSelector:@selector(dataUsingEncoding:)]) {
[HTTPBody appendData:[value dataUsingEncoding:NSUTF8StringEncoding]];
} else {
[HTTPBody appendData:[[NSString stringWithFormat:@"%@", value] dataUsingEncoding:NSUTF8StringEncoding]];
}
}
i++;
// Only add the boundary if this is not the last item in the post body

View File

@@ -43,6 +43,7 @@
}
- (void)dealloc {
[_userData release];
[_URL release];
[_URLRequest release];
[_delegate release];
@@ -153,7 +154,9 @@
[_connection cancel];
[_connection release];
_connection = nil;
if ([_delegate respondsToSelector:@selector(requestDidCancelLoad:)]) {
[_delegate requestDidCancelLoad:self];
}
}
@end

View File

@@ -56,7 +56,7 @@
/**
* An opaque pointer to associate user defined data with the request.
*/
@property(nonatomic, assign) id userData;
@property(nonatomic, retain) id userData;
/**
* A Dictionary of additional HTTP Headers to send with the request
@@ -148,5 +148,5 @@
- (void)requestDidStartLoad:(RKRequest*)request;
- (void)requestDidFinishLoad:(RKRequest*)request;
- (void)request:(RKRequest*)request didFailLoadWithError:(NSError*)error;
- (void)requestDidCancelLoad:(RKRequest*)request; // not yet implemented
- (void)requestDidCancelLoad:(RKRequest*)request;
@end