mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-06-16 21:21:47 +08:00
Support for reading error messages out of JSON payload. Expanded commenting.
This commit is contained in:
@@ -40,7 +40,7 @@
|
||||
if ([response isXML]) {
|
||||
errorMessage = [[(Element*)[response payloadXMLDocument] selectElement:@"error"] contentsText];
|
||||
} else if ([response isJSON]) {
|
||||
errorMessage = [[response payloadJSONDictionary] objectForKey:@"error"];
|
||||
errorMessage = [[[response payloadJSONDictionary] valueForKey:@"errors"] componentsJoinedByString:@", "];
|
||||
}
|
||||
if (nil == errorMessage) {
|
||||
errorMessage = [response payloadString];
|
||||
@@ -71,9 +71,9 @@
|
||||
|
||||
- (void)processLoadModelsInBackground:(RKResponse *)response {
|
||||
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
||||
NSLog(@"Processing response %@", [response payloadString]);
|
||||
NSLog(@"RKModelLoader -> processLoadModelsInBackground: Processing response %@", [response payloadString]);
|
||||
NSArray* models = [_mapper buildModelsFromString:[response payloadString]];
|
||||
NSLog(@"Loaded models %@", models);
|
||||
NSLog(@"RKModelLoader -> processLoadModelsInBackground: Loaded models %@", models);
|
||||
[_delegate performSelectorOnMainThread:self.callback withObject:models waitUntilDone:NO];
|
||||
[pool release];
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ static RKModelManager* sharedManager = nil;
|
||||
loader.delegate = delegate;
|
||||
loader.callback = callback;
|
||||
|
||||
return [_client get:resourcePath params:params delegate:loader callback:loader.collectionCallback];
|
||||
return [_client post:resourcePath params:params delegate:loader callback:loader.collectionCallback];
|
||||
}
|
||||
|
||||
- (RKRequest*)getModel:(id<RKModelMappable>)model delegate:(NSObject<RKModelLoaderDelegate>*)delegate callback:(SEL)callback {
|
||||
|
||||
@@ -22,9 +22,25 @@ extern NSString* const RKDidEnterOnlineModeNotification;
|
||||
BOOL _isOnline;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the shared instance of the model manager
|
||||
*/
|
||||
+ (RKModelManager*)manager;
|
||||
|
||||
/**
|
||||
* Set the shared instance of the model manager
|
||||
*/
|
||||
+ (void)setManager:(RKModelManager*)manager;
|
||||
|
||||
/**
|
||||
* Create and initialize a new model manager. If this is the first instance created
|
||||
* it will be set as the shared instance
|
||||
*/
|
||||
+ (RKModelManager*)managerWithBaseURL:(NSString*)baseURL;
|
||||
|
||||
/**
|
||||
* Initialize a new model manager instance
|
||||
*/
|
||||
- (id)initWithBaseURL:(NSString*)baseURL;
|
||||
|
||||
/**
|
||||
@@ -78,11 +94,34 @@ extern NSString* const RKDidEnterOnlineModeNotification;
|
||||
* Fetch a resource via an HTTP GET and invoke a callback with the model for the resulting payload
|
||||
*/
|
||||
- (RKRequest*)loadModels:(NSString*)resourcePath delegate:(NSObject<RKModelLoaderDelegate>*)delegate callback:(SEL)callback;
|
||||
|
||||
/**
|
||||
* Fetch a resource via an HTTP POST with a dictionary of parameters and invoke a callback with the models mapped from the payload
|
||||
*
|
||||
* TODO: This may not be right... may want to allow specification of the HTTP verb. The use case is to support
|
||||
* loading a remote resource where the amount of data exceeds what is encodeable in URL parameters. This comes up
|
||||
* in GateGuru when loading HighFlyer's from Facebook friends, as the payload gets big fast.
|
||||
*/
|
||||
- (RKRequest*)loadModels:(NSString*)resourcePath params:(NSDictionary*)params delegate:(NSObject<RKModelLoaderDelegate>*)delegate callback:(SEL)callback;
|
||||
|
||||
/**
|
||||
* Update a mappable model by loading its attributes from the web
|
||||
*/
|
||||
- (RKRequest*)getModel:(id<RKModelMappable>)model delegate:(NSObject<RKModelLoaderDelegate>*)delegate callback:(SEL)callback;
|
||||
|
||||
/**
|
||||
* Create a remote mappable model by POSTing the attributes to the remote resource and loading the resulting model from the payload
|
||||
*/
|
||||
- (RKRequest*)postModel:(id<RKModelMappable>)model delegate:(NSObject<RKModelLoaderDelegate>*)delegate callback:(SEL)callback;
|
||||
|
||||
/**
|
||||
* Update a remote mappable model by PUTing the attributes to the remote resource and loading the resulting model from the payload
|
||||
*/
|
||||
- (RKRequest*)putModel:(id<RKModelMappable>)model delegate:(NSObject<RKModelLoaderDelegate>*)delegate callback:(SEL)callback;
|
||||
|
||||
/**
|
||||
* Delete the remote instance of a mappable model by performing an HTTP DELETE on the remote resource
|
||||
*/
|
||||
- (RKRequest*)deleteModel:(id<RKModelMappable>)model delegate:(NSObject<RKModelLoaderDelegate>*)delegate callback:(SEL)callback;
|
||||
|
||||
@end
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user