Add support for customizing the HTTP request operation class used by RKPaginator. closes #1067

This commit is contained in:
Blake Watters
2013-01-02 00:27:40 -05:00
parent 879ffd73e6
commit c06347d5c5
3 changed files with 27 additions and 3 deletions

View File

@@ -555,6 +555,7 @@ static NSString *RKMIMETypeFromAFHTTPClientParameterEncoding(AFHTTPClientParamet
paginator.managedObjectCache = self.managedObjectStore.managedObjectCache;
paginator.fetchRequestBlocks = self.fetchRequestBlocks;
paginator.operationQueue = self.operationQueue;
if (self.HTTPOperationClass) paginator.HTTPOperationClass = self.HTTPOperationClass;
return paginator;
}

View File

@@ -48,6 +48,10 @@
*/
@interface RKPaginator : NSObject
///-------------------------------------
/// @name Initializing Paginator Objects
///-------------------------------------
/**
Initializes a RKPaginator object with the a provided patternURL and mappingProvider.
@@ -57,8 +61,12 @@
@return The receiver, initialized with the request, pagination mapping, and response descriptors.
*/
- (id)initWithRequest:(NSURLRequest *)request
paginationMapping:(RKObjectMapping *)paginationMapping
responseDescriptors:(NSArray *)responseDescriptors;
paginationMapping:(RKObjectMapping *)paginationMapping
responseDescriptors:(NSArray *)responseDescriptors;
///-----------------------------
/// @name Configuring Networking
///-----------------------------
/**
A URL with a path pattern for building a complete URL from
@@ -89,6 +97,13 @@
*/
@property (nonatomic, strong) NSOperationQueue *operationQueue;
/**
The `RKHTTPRequestOperation` subclass to be used for HTTP request operations made by the paginator.
**Default**: `[RKHTTPRequestOperation class]`
*/
@property (nonatomic, strong) Class HTTPOperationClass;
///-----------------------------------
/// @name Setting the Completion Block
///-----------------------------------

View File

@@ -63,6 +63,7 @@ static NSUInteger RKPaginatorDefaultPerPage = 25;
NSAssert([paginationMapping.objectClass isSubclassOfClass:[RKPaginator class]], @"The paginationMapping must have a target object class of `RKPaginator`");
self = [super init];
if (self) {
self.HTTPOperationClass = [RKHTTPRequestOperation class];
self.request = request;
self.paginationMapping = paginationMapping;
self.responseDescriptors = responseDescriptors;
@@ -93,6 +94,12 @@ static NSUInteger RKPaginatorDefaultPerPage = 25;
return [NSURL URLWithString:interpolatedString relativeToURL:self.request.URL];
}
- (void)setHTTPOperationClass:(Class)operationClass
{
NSAssert(operationClass == nil || [operationClass isSubclassOfClass:[RKHTTPRequestOperation class]], @"The HTTP operation class must be a subclass of `RKHTTPRequestOperation`");
_HTTPOperationClass = operationClass;
}
- (void)setCompletionBlockWithSuccess:(void (^)(RKPaginator *paginator, NSArray *objects, NSUInteger page))success
failure:(void (^)(RKPaginator *paginator, NSError *error))failure
{
@@ -159,7 +166,8 @@ static NSUInteger RKPaginatorDefaultPerPage = 25;
mutableRequest.URL = self.URL;
if (self.managedObjectContext) {
RKManagedObjectRequestOperation *managedObjectRequestOperation = [[RKManagedObjectRequestOperation alloc] initWithRequest:mutableRequest responseDescriptors:self.responseDescriptors];
RKHTTPRequestOperation *requestOperation = [[self.HTTPOperationClass alloc] initWithRequest:mutableRequest];
RKManagedObjectRequestOperation *managedObjectRequestOperation = [[RKManagedObjectRequestOperation alloc] initWithHTTPRequestOperation:requestOperation responseDescriptors:self.responseDescriptors];
managedObjectRequestOperation.managedObjectContext = self.managedObjectContext;
managedObjectRequestOperation.managedObjectCache = self.managedObjectCache;
managedObjectRequestOperation.fetchRequestBlocks = self.fetchRequestBlocks;