mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-21 02:50:11 +08:00
Normalized method names for loaderWith to objectLoaderWith for alignment with the delegate method signatures. Exposed objectLoader primitive used for constructing getObject/postObject/putObject/deleteObject and documented.
This commit is contained in:
@@ -99,12 +99,6 @@ extern NSString* const RKDidEnterOnlineModeNotification;
|
||||
*/
|
||||
@property(nonatomic, retain) RKManagedObjectStore* objectStore;
|
||||
|
||||
/**
|
||||
* Return an object loader request object ready to be sent. The method defaults to GET and the URL is relative to the
|
||||
* baseURL configured on the client.
|
||||
*/
|
||||
- (RKObjectLoader*)loaderWithResourcePath:(NSString*)resourcePath objectClass:(Class<RKObjectMappable>)objectClass delegate:(NSObject<RKObjectLoaderDelegate>*)delegate;
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// Registered Object Loaders
|
||||
|
||||
@@ -172,4 +166,31 @@ extern NSString* const RKDidEnterOnlineModeNotification;
|
||||
*/
|
||||
- (RKObjectLoader*)deleteObject:(NSObject<RKObjectMappable>*)object delegate:(NSObject<RKObjectLoaderDelegate>*)delegate;
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// Object Loader Primitives
|
||||
|
||||
/**
|
||||
* These methods are provided for situations where the remote system you are working with has slightly different conventions
|
||||
* than the default methods provide. They return fully initialized object loaders that are ready for dispatch, but
|
||||
* have not yet been sent. This can be used to add one-off params to the request body or otherwise manipulate the request
|
||||
* before it is sent off to be loaded & object mapped. This can also be used to perform a synchronous object load.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Return an object loader ready to be sent. The method defaults to GET and the URL is relative to the
|
||||
* baseURL configured on the client. The loader is configured for an implicit objectClass load. This is
|
||||
* the best place to begin work if you need to create a slightly different collection loader than what is
|
||||
* provided by the loadObjects family of methods.
|
||||
*/
|
||||
- (RKObjectLoader*)objectLoaderWithResourcePath:(NSString*)resourcePath delegate:(NSObject<RKObjectLoaderDelegate>*)delegate;
|
||||
|
||||
/**
|
||||
* Returns an object loader configured for transmitting an object instance across the wire. A request will be constructed
|
||||
* for you with the resource path & object serialization configured for you by the Router. This is the best place to
|
||||
* begin work if you need a slightly different interaction with the server than what is provided for you by get/post/put/delete
|
||||
* object family of methods. Note that this should be used for one-off changes. If you need to substantially modify all your
|
||||
* object loads, you are better off subclassing or implementing your own RKRouter for dryness.
|
||||
*/
|
||||
- (RKObjectLoader*)objectLoaderForObject:(NSObject<RKObjectMappable>*)object method:(RKRequestMethod)method delegate:(NSObject<RKObjectLoaderDelegate>*)delegate;
|
||||
|
||||
@end
|
||||
|
||||
@@ -101,24 +101,21 @@ static RKObjectManager* globalManager = nil;
|
||||
[_mapper registerClass:class forElementNamed:elementName];
|
||||
}
|
||||
|
||||
- (RKObjectLoader*)loaderWithResourcePath:(NSString*)resourcePath objectClass:(Class<RKObjectMappable>)objectClass delegate:(NSObject<RKObjectLoaderDelegate>*)delegate {
|
||||
- (RKObjectLoader*)objectLoaderWithResourcePath:(NSString*)resourcePath delegate:(NSObject<RKObjectLoaderDelegate>*)delegate {
|
||||
if ([self isOffline]) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
// Grab request through client to get HTTP AUTH & Headers
|
||||
RKRequest* request = [self.client requestWithResourcePath:resourcePath delegate:nil callback:nil];
|
||||
RKObjectLoader* loader = [RKObjectLoader loaderWithMapper:self.mapper request:request delegate:delegate];
|
||||
loader.objectClass = objectClass;
|
||||
|
||||
return loader;
|
||||
RKRequest* request = [self.client requestWithResourcePath:resourcePath delegate:nil callback:nil];
|
||||
return [RKObjectLoader loaderWithMapper:self.mapper request:request delegate:delegate];
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Object Collection Loaders
|
||||
|
||||
- (RKObjectLoader*)loadObjectsAtResourcePath:(NSString*)resourcePath delegate:(NSObject<RKObjectLoaderDelegate>*)delegate {
|
||||
RKObjectLoader* loader = [self loaderWithResourcePath:resourcePath objectClass:nil delegate:delegate];
|
||||
RKObjectLoader* loader = [self objectLoaderWithResourcePath:resourcePath delegate:delegate];
|
||||
loader.method = RKRequestMethodGET;
|
||||
|
||||
[loader send];
|
||||
@@ -128,7 +125,7 @@ static RKObjectManager* globalManager = nil;
|
||||
|
||||
- (RKObjectLoader*)loadObjectsAtResourcePath:(NSString *)resourcePath queryParams:(NSDictionary*)queryParams delegate:(NSObject <RKObjectLoaderDelegate>*)delegate {
|
||||
NSString* resourcePathWithQuery = [self.client resourcePath:resourcePath withQueryParams:queryParams];
|
||||
RKObjectLoader* loader = [self loaderWithResourcePath:resourcePathWithQuery objectClass:nil delegate:delegate];
|
||||
RKObjectLoader* loader = [self objectLoaderWithResourcePath:resourcePathWithQuery delegate:delegate];
|
||||
loader.method = RKRequestMethodGET;
|
||||
|
||||
[loader send];
|
||||
@@ -137,8 +134,9 @@ static RKObjectManager* globalManager = nil;
|
||||
}
|
||||
|
||||
- (RKObjectLoader*)loadObjectsAtResourcePath:(NSString*)resourcePath objectClass:(Class<RKObjectMappable>)objectClass delegate:(NSObject<RKObjectLoaderDelegate>*)delegate {
|
||||
RKObjectLoader* loader = [self loaderWithResourcePath:resourcePath objectClass:objectClass delegate:delegate];
|
||||
RKObjectLoader* loader = [self objectLoaderWithResourcePath:resourcePath delegate:delegate];
|
||||
loader.method = RKRequestMethodGET;
|
||||
loader.objectClass = objectClass;
|
||||
|
||||
[loader send];
|
||||
|
||||
@@ -147,8 +145,9 @@ static RKObjectManager* globalManager = nil;
|
||||
|
||||
- (RKObjectLoader*)loadObjectsAtResourcePath:(NSString *)resourcePath queryParams:(NSDictionary*)queryParams objectClass:(Class<RKObjectMappable>)objectClass delegate:(NSObject <RKObjectLoaderDelegate>*)delegate {
|
||||
NSString* resourcePathWithQuery = [self.client resourcePath:resourcePath withQueryParams:queryParams];
|
||||
RKObjectLoader* loader = [self loaderWithResourcePath:resourcePathWithQuery objectClass:objectClass delegate:delegate];
|
||||
loader.method = RKRequestMethodGET;
|
||||
RKObjectLoader* loader = [self objectLoaderWithResourcePath:resourcePathWithQuery delegate:delegate];
|
||||
loader.method = RKRequestMethodGET;
|
||||
loader.objectClass = objectClass;
|
||||
|
||||
[loader send];
|
||||
|
||||
@@ -158,51 +157,51 @@ static RKObjectManager* globalManager = nil;
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Object Instance Loaders
|
||||
|
||||
- (RKObjectLoader*)loaderForObject:(NSObject<RKObjectMappable>*)object resourcePath:(NSString*)resourcePath method:(RKRequestMethod)method params:(NSObject<RKRequestSerializable>*)params delegate:(NSObject<RKObjectLoaderDelegate>*)delegate {
|
||||
// TODO: Need to factor core data stuff out of here...
|
||||
if (method != RKRequestMethodGET) {
|
||||
NSError* error = [self.objectStore save];
|
||||
if (error != nil) {
|
||||
NSLog(@"[RestKit] RKModelManager: Error saving managed object context before PUT/POST/DELETE: error=%@ userInfo=%@", error, error.userInfo);
|
||||
}
|
||||
}
|
||||
- (RKObjectLoader*)objectLoaderForObject:(NSObject<RKObjectMappable>*)object method:(RKRequestMethod)method delegate:(NSObject<RKObjectLoaderDelegate>*)delegate {
|
||||
// Get the serialization representation from the router
|
||||
NSString* resourcePath = [self.router pathForObject:object method:method];
|
||||
NSObject<RKRequestSerializable>* params = [self.router serializationForObject:object method:method];
|
||||
RKObjectLoader* loader = [self objectLoaderWithResourcePath:resourcePath delegate:delegate];
|
||||
|
||||
RKObjectLoader* loader = [self loaderWithResourcePath:resourcePath objectClass:[object class] delegate:delegate];
|
||||
loader.method = method;
|
||||
loader.params = params;
|
||||
loader.source = object;
|
||||
loader.objectClass = [object class];
|
||||
|
||||
return loader;
|
||||
}
|
||||
|
||||
// TODO: Need to factor core data stuff out of here...
|
||||
- (void)saveObjectStore {
|
||||
NSError* error = [self.objectStore save];
|
||||
if (nil == error) {
|
||||
NSLog(@"[RestKit] RKModelManager: Error saving managed object context before PUT/POST/DELETE: error=%@ userInfo=%@", error, error.userInfo);
|
||||
}
|
||||
}
|
||||
|
||||
- (RKObjectLoader*)getObject:(NSObject<RKObjectMappable>*)object delegate:(NSObject<RKObjectLoaderDelegate>*)delegate {
|
||||
NSString* resourcePath = [_router pathForObject:object method:RKRequestMethodGET];
|
||||
NSObject<RKRequestSerializable>* params = [_router serializationForObject:object method:RKRequestMethodGET];
|
||||
RKObjectLoader* loader = [self loaderForObject:object resourcePath:resourcePath method:RKRequestMethodGET params:params delegate:delegate];
|
||||
RKObjectLoader* loader = [self objectLoaderForObject:object method:RKRequestMethodGET delegate:delegate];
|
||||
[loader send];
|
||||
return loader;
|
||||
}
|
||||
|
||||
- (RKObjectLoader*)postObject:(NSObject<RKObjectMappable>*)object delegate:(NSObject<RKObjectLoaderDelegate>*)delegate {
|
||||
NSString* resourcePath = [_router pathForObject:object method:RKRequestMethodPOST];
|
||||
NSObject<RKRequestSerializable>* params = [_router serializationForObject:object method:RKRequestMethodPOST];
|
||||
RKObjectLoader* loader = [self loaderForObject:object resourcePath:resourcePath method:RKRequestMethodPOST params:params delegate:delegate];
|
||||
[self saveObjectStore];
|
||||
RKObjectLoader* loader = [self objectLoaderForObject:object method:RKRequestMethodPOST delegate:delegate];
|
||||
[loader send];
|
||||
return loader;
|
||||
}
|
||||
|
||||
- (RKObjectLoader*)putObject:(NSObject<RKObjectMappable>*)object delegate:(NSObject<RKObjectLoaderDelegate>*)delegate {
|
||||
NSString* resourcePath = [_router pathForObject:object method:RKRequestMethodPUT];
|
||||
NSObject<RKRequestSerializable>* params = [_router serializationForObject:object method:RKRequestMethodPUT];
|
||||
RKObjectLoader* loader = [self loaderForObject:object resourcePath:resourcePath method:RKRequestMethodPUT params:params delegate:delegate];
|
||||
[self saveObjectStore];
|
||||
RKObjectLoader* loader = [self objectLoaderForObject:object method:RKRequestMethodPUT delegate:delegate];
|
||||
[loader send];
|
||||
return loader;
|
||||
}
|
||||
|
||||
- (RKObjectLoader*)deleteObject:(NSObject<RKObjectMappable>*)object delegate:(NSObject<RKObjectLoaderDelegate>*)delegate {
|
||||
NSString* resourcePath = [_router pathForObject:object method:RKRequestMethodDELETE];
|
||||
NSObject<RKRequestSerializable>* params = [_router serializationForObject:object method:RKRequestMethodDELETE];
|
||||
RKObjectLoader* loader = [self loaderForObject:object resourcePath:resourcePath method:RKRequestMethodDELETE params:params delegate:delegate];
|
||||
[self saveObjectStore];
|
||||
RKObjectLoader* loader = [self objectLoaderForObject:object method:RKRequestMethodDELETE delegate:delegate];
|
||||
[loader send];
|
||||
return loader;
|
||||
}
|
||||
|
||||
@@ -249,8 +249,9 @@
|
||||
}
|
||||
|
||||
- (void)load {
|
||||
_objectLoader = [[[RKObjectManager globalManager] loaderWithResourcePath:_resourcePath objectClass:_objectClass delegate:self] retain];
|
||||
_objectLoader = [[[RKObjectManager globalManager] objectLoaderWithResourcePath:_resourcePath delegate:self] retain];
|
||||
_objectLoader.method = _method;
|
||||
_objectLoader.objectClass = _objectClass;
|
||||
_objectLoader.keyPath = _keyPath;
|
||||
_objectLoader.params = _params;
|
||||
[_objectLoader send];
|
||||
|
||||
Reference in New Issue
Block a user