Permalink
Browse files

Migrate RKResponse property from RKObjectLoader to RKRequest. refs #527

  • Loading branch information...
1 parent 489bb04 commit ada95e0281518011a8840a11f0c9023bb80d6b56 @blakewatters blakewatters committed May 19, 2012
View
@@ -247,6 +247,11 @@ typedef void(^RKRequestDidFailLoadWithErrorBlock)(NSError *error);
*/
@property (nonatomic, readonly) NSString *HTTPMethod;
+/**
+ The response returned when the receiver was sent.
+ */
+@property (nonatomic, retain, readonly) RKResponse *response;
+
/**
A serializable collection of parameters sent as the HTTP body of the request
*/
View
@@ -89,6 +89,7 @@ @interface RKRequest ()
@property (nonatomic, assign, readwrite, getter = isLoaded) BOOL loaded;
@property (nonatomic, assign, readwrite, getter = isLoading) BOOL loading;
@property (nonatomic, assign, readwrite) BOOL canceled;
+@property (nonatomic, retain, readwrite) RKResponse *response;
@end
@implementation RKRequest
@@ -128,6 +129,7 @@ @implementation RKRequest
@synthesize loaded = _loaded;
@synthesize loading = _loading;
@synthesize canceled = _canceled;
+@synthesize response = _response;
#if TARGET_OS_IPHONE
@synthesize backgroundPolicy = _backgroundPolicy;
@@ -207,27 +209,29 @@ - (void)dealloc {
if (_onDidLoadResponse) Block_release(_onDidLoadResponse);
if (_onDidFailLoadWithError) Block_release(_onDidFailLoadWithError);
- _delegate = nil;
+ _delegate = nil;
_configurationDelegate = nil;
[_reachabilityObserver release];
_reachabilityObserver = nil;
- [_connection cancel];
- [_connection release];
- _connection = nil;
- [_userData release];
- _userData = nil;
- [_URL release];
- _URL = nil;
- [_URLRequest release];
- _URLRequest = nil;
- [_params release];
+ [_connection cancel];
+ [_connection release];
+ _connection = nil;
+ [_response release];
+ _response = nil;
+ [_userData release];
+ _userData = nil;
+ [_URL release];
+ _URL = nil;
+ [_URLRequest release];
+ _URLRequest = nil;
+ [_params release];
_params = nil;
- [_additionalHTTPHeaders release];
- _additionalHTTPHeaders = nil;
- [_username release];
- _username = nil;
- [_password release];
- _password = nil;
+ [_additionalHTTPHeaders release];
+ _additionalHTTPHeaders = nil;
+ [_username release];
+ _username = nil;
+ [_password release];
+ _password = nil;
[_cache release];
_cache = nil;
[_OAuth1ConsumerKey release];
@@ -325,7 +329,7 @@ - (void)addHeadersToRequest {
}
}
- // Add OAuth headers if is need it
+ // Add OAuth headers if necessary
// OAuth 1
if(self.authenticationType == RKRequestAuthenticationTypeOAuth1){
NSURLRequest *echo = nil;
@@ -685,17 +689,17 @@ - (void)updateInternalCacheDate {
[self.cache setCacheDate:date forRequest:self];
}
-- (void)didFinishLoad:(RKResponse*)response {
- self.loading = NO;
- self.loaded = YES;
+- (void)didFinishLoad:(RKResponse *)response {
+ self.loading = NO;
+ self.loaded = YES;
RKLogInfo(@"Status Code: %ld", (long) [response statusCode]);
RKLogDebug(@"Body: %@", [response bodyAsString]);
- RKResponse* finalResponse = response;
+ self.response = response;
if ((_cachePolicy & RKRequestCachePolicyEtag) && [response isNotModified]) {
- finalResponse = [self loadResponseFromCache];
+ self.response = [self loadResponseFromCache];
[self updateInternalCacheDate];
}
@@ -704,19 +708,18 @@ - (void)didFinishLoad:(RKResponse*)response {
}
if ([_delegate respondsToSelector:@selector(request:didLoadResponse:)]) {
- [_delegate request:self didLoadResponse:finalResponse];
+ [_delegate request:self didLoadResponse:self.response];
}
if (self.onDidLoadResponse) {
- self.onDidLoadResponse(finalResponse);
+ self.onDidLoadResponse(self.response);
}
-
if ([response isServiceUnavailable]) {
[[NSNotificationCenter defaultCenter] postNotificationName:RKServiceDidBecomeUnavailableNotification object:self];
}
- NSDictionary* userInfo = [NSDictionary dictionaryWithObject:finalResponse
+ NSDictionary* userInfo = [NSDictionary dictionaryWithObject:self.response
forKey:RKRequestDidLoadResponseNotificationUserInfoResponseKey];
[[NSNotificationCenter defaultCenter] postNotificationName:RKRequestDidLoadResponseNotification
object:self
@@ -77,7 +77,7 @@
/**
The request that generated this response.
*/
-@property (nonatomic, readonly) RKRequest *request;
+@property (nonatomic, assign, readonly) RKRequest *request;
/**
The URL the response was loaded from.
@@ -36,7 +36,9 @@
@implementation RKResponse
-@synthesize body = _body, request = _request, failureError = _failureError;
+@synthesize body = _body;
+@synthesize request = _request;
+@synthesize failureError = _failureError;
- (id)init {
self = [super init];
@@ -50,7 +52,7 @@ - (id)init {
return self;
}
-- (id)initWithRequest:(RKRequest*)request {
+- (id)initWithRequest:(RKRequest *)request {
self = [self init];
if (self) {
// We don't retain here as we're letting RKRequestQueue manage
@@ -136,14 +136,8 @@ typedef void(^RKObjectLoaderDidLoadObjectsDictionaryBlock)(NSDictionary *diction
* includes Core Data specific mapping logic.
*/
@interface RKObjectLoader : RKRequest {
- RKObjectMappingProvider *_mappingProvider;
- RKResponse* _response;
- RKObjectMapping* _objectMapping;
- RKObjectMappingResult* _result;
- RKObjectMapping* _serializationMapping;
- NSString* _serializationMIMEType;
- NSObject* _sourceObject;
- NSObject* _targetObject;
+ id _sourceObject;
+ id _targetObject;
dispatch_queue_t _mappingQueue;
}
@@ -213,7 +207,7 @@ typedef void(^RKObjectLoaderDidLoadObjectsDictionaryBlock)(NSDictionary *diction
/**
* The underlying response object for this loader
*/
-@property (nonatomic, readonly) RKResponse *response;
+@property (nonatomic, retain, readonly) RKResponse *response;
/**
* The mapping result that was produced after the request finished loading and
@@ -40,12 +40,12 @@ - (void)postRequestDidFailWithErrorNotification:(NSError *)error;
@interface RKObjectLoader ()
@property (nonatomic, assign, readwrite, getter = isLoaded) BOOL loaded;
@property (nonatomic, assign, readwrite, getter = isLoading) BOOL loading;
+@property (nonatomic, retain, readwrite) RKResponse *response;
@end
@implementation RKObjectLoader
@synthesize mappingProvider = _mappingProvider;
-@synthesize response = _response;
@synthesize targetObject = _targetObject;
@synthesize objectMapping = _objectMapping;
@synthesize result = _result;
@@ -59,6 +59,7 @@ @implementation RKObjectLoader
@synthesize onDidLoadObjectsDictionary = _onDidLoadObjectsDictionary;
@dynamic loaded;
@dynamic loading;
+@dynamic response;
+ (id)loaderWithURL:(RKURL *)URL mappingProvider:(RKObjectMappingProvider *)mappingProvider {
return [[[self alloc] initWithURL:URL mappingProvider:mappingProvider] autorelease];
@@ -80,9 +81,7 @@ - (void)dealloc {
[_sourceObject release];
_sourceObject = nil;
[_targetObject release];
- _targetObject = nil;
- [_response release];
- _response = nil;
+ _targetObject = nil;
[_objectMapping release];
_objectMapping = nil;
[_result release];
@@ -105,8 +104,6 @@ - (void)dealloc {
- (void)reset {
[super reset];
- [_response release];
- _response = nil;
[_result release];
_result = nil;
}
@@ -421,30 +418,28 @@ - (void)didFailLoadWithError:(NSError *)error {
// NOTE: We do NOT call super here. We are overloading the default behavior from RKRequest
- (void)didFinishLoad:(RKResponse*)response {
NSAssert([NSThread isMainThread], @"RKObjectLoaderDelegate callbacks must occur on the main thread");
- _response = [response retain];
+ self.response = response;
if ((_cachePolicy & RKRequestCachePolicyEtag) && [response isNotModified]) {
- [_response release];
- _response = nil;
- _response = [[self.cache responseForRequest:self] retain];
- NSAssert(_response, @"Unexpectedly loaded nil response from cache");
+ self.response = [self.cache responseForRequest:self];
+ NSAssert(self.response, @"Unexpectedly loaded nil response from cache");
[self updateInternalCacheDate];
}
- if (![_response wasLoadedFromCache] && [_response isSuccessful] && (_cachePolicy != RKRequestCachePolicyNone)) {
- [self.cache storeResponse:_response forRequest:self];
+ if (![self.response wasLoadedFromCache] && [self.response isSuccessful] && (_cachePolicy != RKRequestCachePolicyNone)) {
+ [self.cache storeResponse:self.response forRequest:self];
}
if ([_delegate respondsToSelector:@selector(request:didLoadResponse:)]) {
- [_delegate request:self didLoadResponse:_response];
+ [_delegate request:self didLoadResponse:self.response];
}
if (self.onDidLoadResponse) {
- self.onDidLoadResponse(_response);
+ self.onDidLoadResponse(self.response);
}
// Post the notification
- NSDictionary* userInfo = [NSDictionary dictionaryWithObject:_response
+ NSDictionary* userInfo = [NSDictionary dictionaryWithObject:self.response
forKey:RKRequestDidLoadResponseNotificationUserInfoResponseKey];
[[NSNotificationCenter defaultCenter] postNotificationName:RKRequestDidLoadResponseNotification
object:self

0 comments on commit ada95e0

Please sign in to comment.