Skip to content

Commit

Permalink
Add support for customizing the HTTP request operation class used by …
Browse files Browse the repository at this point in the history
…`RKPaginator`. closes RestKit#1067
  • Loading branch information
blakewatters committed Jan 2, 2013
1 parent 879ffd7 commit c06347d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions Code/Network/RKObjectManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ - (RKPaginator *)paginatorWithPathPattern:(NSString *)pathPattern
paginator.managedObjectCache = self.managedObjectStore.managedObjectCache;
paginator.fetchRequestBlocks = self.fetchRequestBlocks;
paginator.operationQueue = self.operationQueue;
if (self.HTTPOperationClass) paginator.HTTPOperationClass = self.HTTPOperationClass;
return paginator;
}

Expand Down
19 changes: 17 additions & 2 deletions Code/Network/RKPaginator.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
*/
@interface RKPaginator : NSObject

///-------------------------------------
/// @name Initializing Paginator Objects
///-------------------------------------

/**
Initializes a RKPaginator object with the a provided patternURL and mappingProvider.
Expand All @@ -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
Expand Down Expand Up @@ -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
///-----------------------------------
Expand Down
10 changes: 9 additions & 1 deletion Code/Network/RKPaginator.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ - (id)initWithRequest:(NSURLRequest *)request
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;
Expand Down Expand Up @@ -93,6 +94,12 @@ - (NSURL *)URL
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
{
Expand Down Expand Up @@ -159,7 +166,8 @@ - (void)loadPage:(NSUInteger)pageNumber
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;
Expand Down

0 comments on commit c06347d

Please sign in to comment.