mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-23 12:27:52 +08:00
Ensure the stars for all pointers belong to the variable rather than the type. Refs #614
This commit is contained in:
@@ -35,7 +35,7 @@ RK_FIX_CATEGORY_BUG(NSData_RKAdditions)
|
||||
CC_MD5(self.bytes, (CC_LONG) self.length, md5Buffer);
|
||||
|
||||
// Convert unsigned char buffer to NSString of hex values
|
||||
NSMutableString* output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
|
||||
NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH *2];
|
||||
for (int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) {
|
||||
[output appendFormat:@"%02x", md5Buffer[i]];
|
||||
}
|
||||
|
||||
@@ -14,6 +14,6 @@
|
||||
*
|
||||
* @returns A UTF-8 encoded string representation of the object
|
||||
*/
|
||||
- (NSString*)URLEncodedString;
|
||||
- (NSString *)URLEncodedString;
|
||||
|
||||
@end
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
|
||||
@implementation NSObject (URLEncoding)
|
||||
|
||||
- (NSString*)URLEncodedString
|
||||
- (NSString *)URLEncodedString
|
||||
{
|
||||
NSString *string = [NSString stringWithFormat:@"%@", self];
|
||||
NSString *encodedString = (NSString*)CFURLCreateStringByAddingPercentEscapes(NULL,
|
||||
NSString *encodedString = (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL,
|
||||
(CFStringRef)string,
|
||||
NULL,
|
||||
(CFStringRef)@"!*'();:@&=+$,/?%#[]",
|
||||
|
||||
@@ -47,7 +47,7 @@ NSString *RKMakeURLPath(NSString *resourcePath) {
|
||||
return [[[RKClient sharedClient].baseURL URLByAppendingResourcePath:resourcePath] absoluteString];
|
||||
}
|
||||
|
||||
NSString *RKMakePathWithObjectAddingEscapes(NSString* pattern, id object, BOOL addEscapes) {
|
||||
NSString *RKMakePathWithObjectAddingEscapes(NSString *pattern, id object, BOOL addEscapes) {
|
||||
NSCAssert(pattern != NULL, @"Pattern string must not be empty in order to create a path from an interpolated object.");
|
||||
NSCAssert(object != NULL, @"Object provided is invalid; cannot create a path from a NULL object");
|
||||
RKPathMatcher *matcher = [RKPathMatcher matcherWithPattern:pattern];
|
||||
@@ -378,7 +378,7 @@ NSString *RKPathAppendQueryParams(NSString *resourcePath, NSDictionary *queryPar
|
||||
|
||||
- (RKRequest *)load:(NSString *)resourcePath method:(RKRequestMethod)method params:(NSObject<RKRequestSerializable> *)params delegate:(id)delegate
|
||||
{
|
||||
RKURL* resourcePathURL = nil;
|
||||
RKURL *resourcePathURL = nil;
|
||||
if (method == RKRequestMethodGET) {
|
||||
resourcePathURL = [self.baseURL URLByAppendingResourcePath:resourcePath queryParameters:(NSDictionary *)params];
|
||||
} else {
|
||||
|
||||
@@ -79,7 +79,7 @@
|
||||
|
||||
//Use the parsedBody answer in NSDictionary
|
||||
|
||||
NSDictionary* oauthResponse = (NSDictionary *) [response parsedBody:&error];
|
||||
NSDictionary *oauthResponse = (NSDictionary *) [response parsedBody:&error];
|
||||
if ([oauthResponse isKindOfClass:[NSDictionary class]]) {
|
||||
|
||||
//Check the if an access token comes in the response
|
||||
@@ -117,7 +117,7 @@
|
||||
errorCode = RKOAuthClientErrorInvalidScope;
|
||||
}
|
||||
|
||||
NSDictionary* userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
errorDescription, NSLocalizedDescriptionKey, nil];
|
||||
NSError *error = [NSError errorWithDomain:RKErrorDomain code:errorCode userInfo:userInfo];
|
||||
|
||||
@@ -169,7 +169,7 @@
|
||||
|
||||
- (void)request:(RKRequest *)request didFailLoadWithError:(NSError *)error
|
||||
{
|
||||
NSDictionary* userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
error, NSUnderlyingErrorKey, nil];
|
||||
NSError *clientError = [NSError errorWithDomain:RKErrorDomain code:RKOAuthClientErrorRequestFailure userInfo:userInfo];
|
||||
if ([self.delegate respondsToSelector:@selector(OAuthClient:didFailLoadingRequest:withError:)]) {
|
||||
|
||||
@@ -34,19 +34,19 @@
|
||||
/**
|
||||
* The boundary used used for multi-part headers
|
||||
*/
|
||||
NSString* const kRKStringBoundary = @"0xKhTmLbOuNdArY";
|
||||
NSString * const kRKStringBoundary = @"0xKhTmLbOuNdArY";
|
||||
|
||||
@implementation RKParams
|
||||
|
||||
+ (RKParams*)params
|
||||
+ (RKParams *)params
|
||||
{
|
||||
RKParams* params = [[[RKParams alloc] init] autorelease];
|
||||
RKParams *params = [[[RKParams alloc] init] autorelease];
|
||||
return params;
|
||||
}
|
||||
|
||||
+ (RKParams*)paramsWithDictionary:(NSDictionary*)dictionary
|
||||
+ (RKParams *)paramsWithDictionary:(NSDictionary *)dictionary
|
||||
{
|
||||
RKParams* params = [[[RKParams alloc] initWithDictionary:dictionary] autorelease];
|
||||
RKParams *params = [[[RKParams alloc] initWithDictionary:dictionary] autorelease];
|
||||
return params;
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ NSString* const kRKStringBoundary = @"0xKhTmLbOuNdArY";
|
||||
_length += [attachment length];
|
||||
}
|
||||
|
||||
return (NSInputStream*)self;
|
||||
return (NSInputStream *)self;
|
||||
}
|
||||
|
||||
#pragma mark NSInputStream methods
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
/**
|
||||
* The multi-part boundary. See RKParams.m
|
||||
*/
|
||||
extern NSString* const kRKStringBoundary;
|
||||
extern NSString * const kRKStringBoundary;
|
||||
|
||||
@implementation RKParamsAttachment
|
||||
|
||||
@@ -56,7 +56,7 @@ extern NSString* const kRKStringBoundary;
|
||||
{
|
||||
if ((self = [self initWithName:name])) {
|
||||
if ([value respondsToSelector:@selector(dataUsingEncoding:)]) {
|
||||
_body = [[(NSString*)value dataUsingEncoding:NSUTF8StringEncoding] retain];
|
||||
_body = [[(NSString *)value dataUsingEncoding:NSUTF8StringEncoding] retain];
|
||||
} else {
|
||||
_body = [[[NSString stringWithFormat:@"%@", value] dataUsingEncoding:NSUTF8StringEncoding] retain];
|
||||
}
|
||||
@@ -69,7 +69,7 @@ extern NSString* const kRKStringBoundary;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithName:(NSString*)name data:(NSData*)data
|
||||
- (id)initWithName:(NSString *)name data:(NSData *)data
|
||||
{
|
||||
self = [self initWithName:name];
|
||||
if (self) {
|
||||
@@ -81,7 +81,7 @@ extern NSString* const kRKStringBoundary;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithName:(NSString*)name file:(NSString*)filePath
|
||||
- (id)initWithName:(NSString *)name file:(NSString *)filePath
|
||||
{
|
||||
self = [self initWithName:name];
|
||||
if (self) {
|
||||
@@ -93,8 +93,8 @@ extern NSString* const kRKStringBoundary;
|
||||
_MIMEType = [MIMEType retain];
|
||||
_bodyStream = [[NSInputStream alloc] initWithFileAtPath:filePath];
|
||||
|
||||
NSError* error;
|
||||
NSDictionary* attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:&error];
|
||||
NSError *error;
|
||||
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:&error];
|
||||
if (attributes) {
|
||||
_bodyLength = [[attributes objectForKey:NSFileSize] unsignedIntegerValue];
|
||||
}
|
||||
@@ -125,7 +125,7 @@ extern NSString* const kRKStringBoundary;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSString*)MIMEBoundary
|
||||
- (NSString *)MIMEBoundary
|
||||
{
|
||||
return kRKStringBoundary;
|
||||
}
|
||||
|
||||
@@ -43,9 +43,9 @@
|
||||
@end
|
||||
|
||||
// Constants
|
||||
NSString* const RKReachabilityDidChangeNotification = @"RKReachabilityDidChangeNotification";
|
||||
NSString* const RKReachabilityFlagsUserInfoKey = @"RKReachabilityFlagsUserInfoKey";
|
||||
NSString* const RKReachabilityWasDeterminedNotification = @"RKReachabilityWasDeterminedNotification";
|
||||
NSString * const RKReachabilityDidChangeNotification = @"RKReachabilityDidChangeNotification";
|
||||
NSString * const RKReachabilityFlagsUserInfoKey = @"RKReachabilityFlagsUserInfoKey";
|
||||
NSString * const RKReachabilityWasDeterminedNotification = @"RKReachabilityWasDeterminedNotification";
|
||||
|
||||
static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void *info) {
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
@@ -135,12 +135,12 @@ RKRequestMethod RKRequestMethodTypeFromName(NSString *methodName) {
|
||||
@synthesize backgroundTaskIdentifier = _backgroundTaskIdentifier;
|
||||
#endif
|
||||
|
||||
+ (RKRequest*)requestWithURL:(NSURL*)URL
|
||||
+ (RKRequest *)requestWithURL:(NSURL *)URL
|
||||
{
|
||||
return [[[RKRequest alloc] initWithURL:URL] autorelease];
|
||||
}
|
||||
|
||||
- (id)initWithURL:(NSURL*)URL
|
||||
- (id)initWithURL:(NSURL *)URL
|
||||
{
|
||||
self = [self init];
|
||||
if (self) {
|
||||
@@ -198,7 +198,7 @@ RKRequestMethod RKRequestMethodTypeFromName(NSString *methodName) {
|
||||
return;
|
||||
}
|
||||
|
||||
UIApplication* app = [UIApplication sharedApplication];
|
||||
UIApplication *app = [UIApplication sharedApplication];
|
||||
if ([app respondsToSelector:@selector(beginBackgroundTaskWithExpirationHandler:)]) {
|
||||
[app endBackgroundTask:_backgroundTaskIdentifier];
|
||||
_backgroundTaskIdentifier = UIBackgroundTaskInvalid;
|
||||
@@ -286,7 +286,7 @@ RKRequestMethod RKRequestMethodTypeFromName(NSString *methodName) {
|
||||
}
|
||||
}
|
||||
|
||||
- (NSData*)HTTPBody
|
||||
- (NSData *)HTTPBody
|
||||
{
|
||||
return self.URLRequest.HTTPBody;
|
||||
}
|
||||
@@ -296,7 +296,7 @@ RKRequestMethod RKRequestMethodTypeFromName(NSString *methodName) {
|
||||
[self.URLRequest setHTTPBody:HTTPBody];
|
||||
}
|
||||
|
||||
- (NSString*)HTTPBodyString
|
||||
- (NSString *)HTTPBodyString
|
||||
{
|
||||
return [[[NSString alloc] initWithData:self.URLRequest.HTTPBody encoding:NSASCIIStringEncoding] autorelease];
|
||||
}
|
||||
@@ -392,7 +392,7 @@ RKRequestMethod RKRequestMethodTypeFromName(NSString *methodName) {
|
||||
}
|
||||
|
||||
if (self.cachePolicy & RKRequestCachePolicyEtag) {
|
||||
NSString* etag = [self.cache etagForRequest:self];
|
||||
NSString *etag = [self.cache etagForRequest:self];
|
||||
if (etag) {
|
||||
RKLogTrace(@"Setting If-None-Match header to '%@'", etag);
|
||||
[_URLRequest setValue:etag forHTTPHeaderField:@"If-None-Match"];
|
||||
@@ -412,7 +412,7 @@ RKRequestMethod RKRequestMethodTypeFromName(NSString *methodName) {
|
||||
[self setRequestBody];
|
||||
[self addHeadersToRequest];
|
||||
|
||||
NSString* body = [[NSString alloc] initWithData:[_URLRequest HTTPBody] encoding:NSUTF8StringEncoding];
|
||||
NSString *body = [[NSString alloc] initWithData:[_URLRequest HTTPBody] encoding:NSUTF8StringEncoding];
|
||||
RKLogTrace(@"Prepared %@ URLRequest '%@'. HTTP Headers: %@. HTTP Body: %@.", [self HTTPMethod], _URLRequest, [_URLRequest allHTTPHeaderFields], body);
|
||||
[body release];
|
||||
|
||||
@@ -463,7 +463,7 @@ RKRequestMethod RKRequestMethodTypeFromName(NSString *methodName) {
|
||||
[self.delegate requestDidStartLoad:self];
|
||||
}
|
||||
|
||||
RKResponse* response = [[[RKResponse alloc] initWithRequest:self] autorelease];
|
||||
RKResponse *response = [[[RKResponse alloc] initWithRequest:self] autorelease];
|
||||
|
||||
_connection = [[[[NSURLConnection alloc] initWithRequest:_URLRequest delegate:response startImmediately:NO] autorelease] retain];
|
||||
[_connection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:self.runLoopMode];
|
||||
@@ -479,7 +479,7 @@ RKRequestMethod RKRequestMethodTypeFromName(NSString *methodName) {
|
||||
if (self.cachePolicy & RKRequestCachePolicyEnabled) {
|
||||
return YES;
|
||||
} else if (self.cachePolicy & RKRequestCachePolicyTimeout) {
|
||||
NSDate* date = [self.cache cacheDateForRequest:self];
|
||||
NSDate *date = [self.cache cacheDateForRequest:self];
|
||||
NSTimeInterval interval = [[NSDate date] timeIntervalSinceDate:date];
|
||||
return interval <= self.cacheTimeoutInterval;
|
||||
}
|
||||
@@ -487,7 +487,7 @@ RKRequestMethod RKRequestMethodTypeFromName(NSString *methodName) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (RKResponse*)loadResponseFromCache
|
||||
- (RKResponse *)loadResponseFromCache
|
||||
{
|
||||
RKLogDebug(@"Found cached content, loading...");
|
||||
return [self.cache responseForRequest:self];
|
||||
@@ -507,14 +507,14 @@ RKRequestMethod RKRequestMethodTypeFromName(NSString *methodName) {
|
||||
NSAssert(NO == self.loading || NO == self.loaded, @"Cannot send a request that is loading or loaded without resetting it first.");
|
||||
_sentSynchronously = NO;
|
||||
if ([self shouldLoadFromCache]) {
|
||||
RKResponse* response = [self loadResponseFromCache];
|
||||
RKResponse *response = [self loadResponseFromCache];
|
||||
self.loading = YES;
|
||||
[self performSelector:@selector(didFinishLoad:) withObject:response afterDelay:0];
|
||||
} else if ([self shouldDispatchRequest]) {
|
||||
[self createTimeoutTimer];
|
||||
#if TARGET_OS_IPHONE
|
||||
// Background Request Policy support
|
||||
UIApplication* app = [UIApplication sharedApplication];
|
||||
UIApplication *app = [UIApplication sharedApplication];
|
||||
if (self.backgroundPolicy == RKRequestBackgroundPolicyNone ||
|
||||
NO == [app respondsToSelector:@selector(beginBackgroundTaskWithExpirationHandler:)]) {
|
||||
// No support for background (iOS 3.x) or the policy is none -- just fire the request
|
||||
@@ -530,7 +530,7 @@ RKRequestMethod RKRequestMethodTypeFromName(NSString *methodName) {
|
||||
RKLogInfo(@"Beginning background task to perform processing...");
|
||||
|
||||
// Fork a background task for continueing a long-running request
|
||||
__block RKRequest* weakSelf = self;
|
||||
__block RKRequest *weakSelf = self;
|
||||
__block id<RKRequestDelegate> weakDelegate = _delegate;
|
||||
_backgroundTaskIdentifier = [app beginBackgroundTaskWithExpirationHandler:^{
|
||||
RKLogInfo(@"Background request time expired, canceling request.");
|
||||
@@ -560,23 +560,23 @@ RKRequestMethod RKRequestMethodTypeFromName(NSString *methodName) {
|
||||
self.loading = YES;
|
||||
|
||||
RKLogError(@"Failed to send request to %@ due to unreachable network. Reachability observer = %@", [[self URL] absoluteString], self.reachabilityObserver);
|
||||
NSString* errorMessage = [NSString stringWithFormat:@"The client is unable to contact the resource at %@", [[self URL] absoluteString]];
|
||||
NSString *errorMessage = [NSString stringWithFormat:@"The client is unable to contact the resource at %@", [[self URL] absoluteString]];
|
||||
NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
errorMessage, NSLocalizedDescriptionKey,
|
||||
nil];
|
||||
NSError* error = [NSError errorWithDomain:RKErrorDomain code:RKRequestBaseURLOfflineError userInfo:userInfo];
|
||||
NSError *error = [NSError errorWithDomain:RKErrorDomain code:RKRequestBaseURLOfflineError userInfo:userInfo];
|
||||
[self performSelector:@selector(didFailLoadWithError:) withObject:error afterDelay:0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (RKResponse*)sendSynchronously
|
||||
- (RKResponse *)sendSynchronously
|
||||
{
|
||||
NSAssert(NO == self.loading || NO == self.loaded, @"Cannot send a request that is loading or loaded without resetting it first.");
|
||||
NSHTTPURLResponse* URLResponse = nil;
|
||||
NSError* error;
|
||||
NSData* payload = nil;
|
||||
RKResponse* response = nil;
|
||||
NSHTTPURLResponse *URLResponse = nil;
|
||||
NSError *error;
|
||||
NSData *payload = nil;
|
||||
RKResponse *response = nil;
|
||||
_sentSynchronously = YES;
|
||||
|
||||
if ([self shouldLoadFromCache]) {
|
||||
@@ -620,7 +620,7 @@ RKRequestMethod RKRequestMethodTypeFromName(NSString *methodName) {
|
||||
response = [self loadResponseFromCache];
|
||||
|
||||
} else {
|
||||
NSString* errorMessage = [NSString stringWithFormat:@"The client is unable to contact the resource at %@", [[self URL] absoluteString]];
|
||||
NSString *errorMessage = [NSString stringWithFormat:@"The client is unable to contact the resource at %@", [[self URL] absoluteString]];
|
||||
NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
errorMessage, NSLocalizedDescriptionKey,
|
||||
nil];
|
||||
@@ -647,11 +647,11 @@ RKRequestMethod RKRequestMethodTypeFromName(NSString *methodName) {
|
||||
{
|
||||
[self cancelAndInformDelegate:NO];
|
||||
RKLogError(@"Failed to send request to %@ due to connection timeout. Timeout interval = %f", [[self URL] absoluteString], self.timeoutInterval);
|
||||
NSString* errorMessage = [NSString stringWithFormat:@"The client timed out connecting to the resource at %@", [[self URL] absoluteString]];
|
||||
NSString *errorMessage = [NSString stringWithFormat:@"The client timed out connecting to the resource at %@", [[self URL] absoluteString]];
|
||||
NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
errorMessage, NSLocalizedDescriptionKey,
|
||||
nil];
|
||||
NSError* error = [NSError errorWithDomain:RKErrorDomain code:RKRequestConnectionTimeoutError userInfo:userInfo];
|
||||
NSError *error = [NSError errorWithDomain:RKErrorDomain code:RKRequestConnectionTimeoutError userInfo:userInfo];
|
||||
[self didFailLoadWithError:error];
|
||||
}
|
||||
|
||||
@@ -661,7 +661,7 @@ RKRequestMethod RKRequestMethodTypeFromName(NSString *methodName) {
|
||||
_timeoutTimer = nil;
|
||||
}
|
||||
|
||||
- (void)didFailLoadWithError:(NSError*)error
|
||||
- (void)didFailLoadWithError:(NSError *)error
|
||||
{
|
||||
if (_cachePolicy & RKRequestCachePolicyLoadOnError &&
|
||||
[self.cache hasResponseForRequest:self]) {
|
||||
@@ -680,7 +680,7 @@ RKRequestMethod RKRequestMethodTypeFromName(NSString *methodName) {
|
||||
}
|
||||
|
||||
|
||||
NSDictionary* userInfo = [NSDictionary dictionaryWithObject:error forKey:RKRequestDidFailWithErrorNotificationUserInfoErrorKey];
|
||||
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:error forKey:RKRequestDidFailWithErrorNotificationUserInfoErrorKey];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:RKRequestDidFailWithErrorNotification
|
||||
object:self
|
||||
userInfo:userInfo];
|
||||
@@ -693,7 +693,7 @@ RKRequestMethod RKRequestMethodTypeFromName(NSString *methodName) {
|
||||
|
||||
- (void)updateInternalCacheDate
|
||||
{
|
||||
NSDate* date = [NSDate date];
|
||||
NSDate *date = [NSDate date];
|
||||
RKLogInfo(@"Updating cache date for request %@ to %@", self, date);
|
||||
[self.cache setCacheDate:date forRequest:self];
|
||||
}
|
||||
@@ -729,7 +729,7 @@ RKRequestMethod RKRequestMethodTypeFromName(NSString *methodName) {
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:RKServiceDidBecomeUnavailableNotification object:self];
|
||||
}
|
||||
|
||||
NSDictionary* userInfo = [NSDictionary dictionaryWithObject:self.response
|
||||
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:self.response
|
||||
forKey:RKRequestDidLoadResponseNotificationUserInfoResponseKey];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:RKRequestDidLoadResponseNotification
|
||||
object:self
|
||||
@@ -770,11 +770,11 @@ RKRequestMethod RKRequestMethodTypeFromName(NSString *methodName) {
|
||||
return self.loading == NO && self.loaded == NO;
|
||||
}
|
||||
|
||||
- (NSString*)resourcePath
|
||||
- (NSString *)resourcePath
|
||||
{
|
||||
NSString* resourcePath = nil;
|
||||
NSString *resourcePath = nil;
|
||||
if ([self.URL isKindOfClass:[RKURL class]]) {
|
||||
RKURL* url = (RKURL*)self.URL;
|
||||
RKURL *url = (RKURL *)self.URL;
|
||||
resourcePath = url.resourcePath;
|
||||
}
|
||||
return resourcePath;
|
||||
@@ -797,7 +797,7 @@ RKRequestMethod RKRequestMethodTypeFromName(NSString *methodName) {
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)wasSentToResourcePath:(NSString*)resourcePath
|
||||
- (BOOL)wasSentToResourcePath:(NSString *)resourcePath
|
||||
{
|
||||
return [[self resourcePath] isEqualToString:resourcePath];
|
||||
}
|
||||
@@ -807,7 +807,7 @@ RKRequestMethod RKRequestMethodTypeFromName(NSString *methodName) {
|
||||
return (self.method == method && [self wasSentToResourcePath:resourcePath]);
|
||||
}
|
||||
|
||||
- (void)appDidEnterBackgroundNotification:(NSNotification*)notification
|
||||
- (void)appDidEnterBackgroundNotification:(NSNotification *)notification
|
||||
{
|
||||
#if TARGET_OS_IPHONE
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil];
|
||||
@@ -826,14 +826,14 @@ RKRequestMethod RKRequestMethodTypeFromName(NSString *methodName) {
|
||||
return _method == RKRequestMethodGET;
|
||||
}
|
||||
|
||||
- (NSString*)cacheKey
|
||||
- (NSString *)cacheKey
|
||||
{
|
||||
if (! [self isCacheable]) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
// Use [_params HTTPBody] because the URLRequest body may not have been set up yet.
|
||||
NSString* compositeCacheKey = nil;
|
||||
NSString *compositeCacheKey = nil;
|
||||
if (_params) {
|
||||
if ([_params respondsToSelector:@selector(HTTPBody)]) {
|
||||
compositeCacheKey = [NSString stringWithFormat:@"%@-%d-%@", self.URL, _method, [_params HTTPBody]];
|
||||
@@ -852,7 +852,7 @@ RKRequestMethod RKRequestMethodTypeFromName(NSString *methodName) {
|
||||
id<RKParser> parser = [[RKParserRegistry sharedRegistry] parserForMIMEType:MIMEType];
|
||||
|
||||
NSError *error = nil;
|
||||
NSString* parsedValue = [parser stringFromObject:body error:&error];
|
||||
NSString *parsedValue = [parser stringFromObject:body error:&error];
|
||||
|
||||
RKLogTrace(@"parser=%@, error=%@, parsedValue=%@", parser, error, parsedValue);
|
||||
|
||||
@@ -863,12 +863,12 @@ RKRequestMethod RKRequestMethodTypeFromName(NSString *methodName) {
|
||||
}
|
||||
|
||||
// Deprecations
|
||||
+ (RKRequest*)requestWithURL:(NSURL*)URL delegate:(id)delegate
|
||||
+ (RKRequest *)requestWithURL:(NSURL *)URL delegate:(id)delegate
|
||||
{
|
||||
return [[[RKRequest alloc] initWithURL:URL delegate:delegate] autorelease];
|
||||
}
|
||||
|
||||
- (id)initWithURL:(NSURL*)URL delegate:(id)delegate
|
||||
- (id)initWithURL:(NSURL *)URL delegate:(id)delegate
|
||||
{
|
||||
self = [self initWithURL:URL];
|
||||
if (self) {
|
||||
|
||||
@@ -33,13 +33,13 @@ NSString * const RKRequestCacheStatusCodeHeadersKey = @"X-RESTKIT-CACHED-RESPONS
|
||||
NSString * const RKRequestCacheMIMETypeHeadersKey = @"X-RESTKIT-CACHED-MIME-TYPE";
|
||||
NSString * const RKRequestCacheURLHeadersKey = @"X-RESTKIT-CACHED-URL";
|
||||
|
||||
static NSDateFormatter* __rfc1123DateFormatter;
|
||||
static NSDateFormatter *__rfc1123DateFormatter;
|
||||
|
||||
@implementation RKRequestCache
|
||||
|
||||
@synthesize storagePolicy = _storagePolicy;
|
||||
|
||||
+ (NSDateFormatter*)rfc1123DateFormatter
|
||||
+ (NSDateFormatter *)rfc1123DateFormatter
|
||||
{
|
||||
if (__rfc1123DateFormatter == nil) {
|
||||
__rfc1123DateFormatter = [[NSDateFormatter alloc] init];
|
||||
@@ -49,7 +49,7 @@ static NSDateFormatter* __rfc1123DateFormatter;
|
||||
return __rfc1123DateFormatter;
|
||||
}
|
||||
|
||||
- (id)initWithPath:(NSString*)cachePath storagePolicy:(RKRequestCacheStoragePolicy)storagePolicy
|
||||
- (id)initWithPath:(NSString *)cachePath storagePolicy:(RKRequestCacheStoragePolicy)storagePolicy
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
@@ -70,15 +70,15 @@ static NSDateFormatter* __rfc1123DateFormatter;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSString*)path
|
||||
- (NSString *)path
|
||||
{
|
||||
return _cache.cachePath;
|
||||
}
|
||||
|
||||
- (NSString*)pathForRequest:(RKRequest*)request
|
||||
- (NSString *)pathForRequest:(RKRequest *)request
|
||||
{
|
||||
NSString* pathForRequest = nil;
|
||||
NSString* requestCacheKey = [request cacheKey];
|
||||
NSString *pathForRequest = nil;
|
||||
NSString *requestCacheKey = [request cacheKey];
|
||||
if (requestCacheKey) {
|
||||
if (_storagePolicy == RKRequestCacheStoragePolicyForDurationOfSession) {
|
||||
pathForRequest = [RKRequestCacheSessionCacheDirectory stringByAppendingPathComponent:requestCacheKey];
|
||||
@@ -93,10 +93,10 @@ static NSDateFormatter* __rfc1123DateFormatter;
|
||||
return pathForRequest;
|
||||
}
|
||||
|
||||
- (BOOL)hasResponseForRequest:(RKRequest*)request
|
||||
- (BOOL)hasResponseForRequest:(RKRequest *)request
|
||||
{
|
||||
BOOL hasEntryForRequest = NO;
|
||||
NSString* cacheKey = [self pathForRequest:request];
|
||||
NSString *cacheKey = [self pathForRequest:request];
|
||||
if (cacheKey) {
|
||||
hasEntryForRequest = ([_cache hasEntry:cacheKey] &&
|
||||
[_cache hasEntry:[cacheKey stringByAppendingPathExtension:RKRequestCacheHeadersExtension]]);
|
||||
@@ -105,21 +105,21 @@ static NSDateFormatter* __rfc1123DateFormatter;
|
||||
return hasEntryForRequest;
|
||||
}
|
||||
|
||||
- (void)storeResponse:(RKResponse*)response forRequest:(RKRequest*)request
|
||||
- (void)storeResponse:(RKResponse *)response forRequest:(RKRequest *)request
|
||||
{
|
||||
if ([self hasResponseForRequest:request]) {
|
||||
[self invalidateRequest:request];
|
||||
}
|
||||
|
||||
if (_storagePolicy != RKRequestCacheStoragePolicyDisabled) {
|
||||
NSString* cacheKey = [self pathForRequest:request];
|
||||
NSString *cacheKey = [self pathForRequest:request];
|
||||
if (cacheKey) {
|
||||
[_cache writeData:response.body withCacheKey:cacheKey];
|
||||
|
||||
NSMutableDictionary* headers = [response.allHeaderFields mutableCopy];
|
||||
NSMutableDictionary *headers = [response.allHeaderFields mutableCopy];
|
||||
if (headers) {
|
||||
// TODO: expose this?
|
||||
NSHTTPURLResponse* urlResponse = [response valueForKey:@"_httpURLResponse"];
|
||||
NSHTTPURLResponse *urlResponse = [response valueForKey:@"_httpURLResponse"];
|
||||
// Cache Loaded Time
|
||||
[headers setObject:[[RKRequestCache rfc1123DateFormatter] stringFromDate:[NSDate date]]
|
||||
forKey:RKRequestCacheDateHeaderKey];
|
||||
@@ -140,25 +140,25 @@ static NSDateFormatter* __rfc1123DateFormatter;
|
||||
}
|
||||
}
|
||||
|
||||
- (RKResponse*)responseForRequest:(RKRequest*)request
|
||||
- (RKResponse *)responseForRequest:(RKRequest *)request
|
||||
{
|
||||
RKResponse* response = nil;
|
||||
NSString* cacheKey = [self pathForRequest:request];
|
||||
RKResponse *response = nil;
|
||||
NSString *cacheKey = [self pathForRequest:request];
|
||||
if (cacheKey) {
|
||||
NSData* responseData = [_cache dataForCacheKey:cacheKey];
|
||||
NSDictionary* responseHeaders = [_cache dictionaryForCacheKey:[cacheKey stringByAppendingPathExtension:RKRequestCacheHeadersExtension]];
|
||||
NSData *responseData = [_cache dataForCacheKey:cacheKey];
|
||||
NSDictionary *responseHeaders = [_cache dictionaryForCacheKey:[cacheKey stringByAppendingPathExtension:RKRequestCacheHeadersExtension]];
|
||||
response = [[[RKResponse alloc] initWithRequest:request body:responseData headers:responseHeaders] autorelease];
|
||||
}
|
||||
RKLogDebug(@"Found cached RKResponse '%@' for '%@'", response, request);
|
||||
return response;
|
||||
}
|
||||
|
||||
- (NSDictionary*)headersForRequest:(RKRequest*)request
|
||||
- (NSDictionary *)headersForRequest:(RKRequest *)request
|
||||
{
|
||||
NSDictionary* headers = nil;
|
||||
NSString* cacheKey = [self pathForRequest:request];
|
||||
NSDictionary *headers = nil;
|
||||
NSString *cacheKey = [self pathForRequest:request];
|
||||
if (cacheKey) {
|
||||
NSString* headersCacheKey = [cacheKey stringByAppendingPathExtension:RKRequestCacheHeadersExtension];
|
||||
NSString *headersCacheKey = [cacheKey stringByAppendingPathExtension:RKRequestCacheHeadersExtension];
|
||||
headers = [_cache dictionaryForCacheKey:headersCacheKey];
|
||||
if (headers) {
|
||||
RKLogDebug(@"Read cached headers '%@' from headersCacheKey '%@' for '%@'", headers, headersCacheKey, request);
|
||||
@@ -171,13 +171,13 @@ static NSDateFormatter* __rfc1123DateFormatter;
|
||||
return headers;
|
||||
}
|
||||
|
||||
- (NSString*)etagForRequest:(RKRequest*)request
|
||||
- (NSString *)etagForRequest:(RKRequest *)request
|
||||
{
|
||||
NSString* etag = nil;
|
||||
NSString *etag = nil;
|
||||
|
||||
NSDictionary* responseHeaders = [self headersForRequest:request];
|
||||
NSDictionary *responseHeaders = [self headersForRequest:request];
|
||||
if (responseHeaders) {
|
||||
for (NSString* responseHeader in responseHeaders) {
|
||||
for (NSString *responseHeader in responseHeaders) {
|
||||
if ([[responseHeader uppercaseString] isEqualToString:[@"ETag" uppercaseString]]) {
|
||||
etag = [responseHeaders objectForKey:responseHeader];
|
||||
}
|
||||
@@ -187,11 +187,11 @@ static NSDateFormatter* __rfc1123DateFormatter;
|
||||
return etag;
|
||||
}
|
||||
|
||||
- (void)setCacheDate:(NSDate*)date forRequest:(RKRequest*)request
|
||||
- (void)setCacheDate:(NSDate *)date forRequest:(RKRequest *)request
|
||||
{
|
||||
NSString* cacheKey = [self pathForRequest:request];
|
||||
NSString *cacheKey = [self pathForRequest:request];
|
||||
if (cacheKey) {
|
||||
NSMutableDictionary* responseHeaders = [[self headersForRequest:request] mutableCopy];
|
||||
NSMutableDictionary *responseHeaders = [[self headersForRequest:request] mutableCopy];
|
||||
|
||||
[responseHeaders setObject:[[RKRequestCache rfc1123DateFormatter] stringFromDate:date]
|
||||
forKey:RKRequestCacheDateHeaderKey];
|
||||
@@ -201,14 +201,14 @@ static NSDateFormatter* __rfc1123DateFormatter;
|
||||
}
|
||||
}
|
||||
|
||||
- (NSDate*)cacheDateForRequest:(RKRequest*)request
|
||||
- (NSDate *)cacheDateForRequest:(RKRequest *)request
|
||||
{
|
||||
NSDate* date = nil;
|
||||
NSString* dateString = nil;
|
||||
NSDate *date = nil;
|
||||
NSString *dateString = nil;
|
||||
|
||||
NSDictionary* responseHeaders = [self headersForRequest:request];
|
||||
NSDictionary *responseHeaders = [self headersForRequest:request];
|
||||
if (responseHeaders) {
|
||||
for (NSString* responseHeader in responseHeaders) {
|
||||
for (NSString *responseHeader in responseHeaders) {
|
||||
if ([[responseHeader uppercaseString] isEqualToString:[RKRequestCacheDateHeaderKey uppercaseString]]) {
|
||||
dateString = [responseHeaders objectForKey:responseHeader];
|
||||
}
|
||||
@@ -219,10 +219,10 @@ static NSDateFormatter* __rfc1123DateFormatter;
|
||||
return date;
|
||||
}
|
||||
|
||||
- (void)invalidateRequest:(RKRequest*)request
|
||||
- (void)invalidateRequest:(RKRequest *)request
|
||||
{
|
||||
RKLogDebug(@"Invalidating cache entry for '%@'", request);
|
||||
NSString* cacheKey = [self pathForRequest:request];
|
||||
NSString *cacheKey = [self pathForRequest:request];
|
||||
if (cacheKey) {
|
||||
[_cache invalidateEntry:cacheKey];
|
||||
[_cache invalidateEntry:[cacheKey stringByAppendingPathExtension:RKRequestCacheHeadersExtension]];
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
RK_FIX_CATEGORY_BUG(UIApplication_RKNetworkActivity)
|
||||
|
||||
// Constants
|
||||
static NSMutableArray* RKRequestQueueInstances = nil;
|
||||
static NSMutableArray *RKRequestQueueInstances = nil;
|
||||
|
||||
static const NSTimeInterval kFlushDelay = 0.3;
|
||||
|
||||
@@ -41,7 +41,7 @@ static const NSTimeInterval kFlushDelay = 0.3;
|
||||
#define RKLogComponent lcl_cRestKitNetworkQueue
|
||||
|
||||
@interface RKRequestQueue ()
|
||||
@property (nonatomic, retain, readwrite) NSString* name;
|
||||
@property (nonatomic, retain, readwrite) NSString *name;
|
||||
@end
|
||||
|
||||
@implementation RKRequestQueue
|
||||
@@ -56,13 +56,13 @@ static const NSTimeInterval kFlushDelay = 0.3;
|
||||
@synthesize showsNetworkActivityIndicatorWhenBusy = _showsNetworkActivityIndicatorWhenBusy;
|
||||
#endif
|
||||
|
||||
+ (RKRequestQueue*)sharedQueue
|
||||
+ (RKRequestQueue *)sharedQueue
|
||||
{
|
||||
RKLogWarning(@"Deprecated invocation of [RKRequestQueue sharedQueue]. Returning [RKClient sharedClient].requestQueue. Update your code to reference the queue you want explicitly.");
|
||||
return [RKClient sharedClient].requestQueue;
|
||||
}
|
||||
|
||||
+ (void)setSharedQueue:(RKRequestQueue*)requestQueue
|
||||
+ (void)setSharedQueue:(RKRequestQueue *)requestQueue
|
||||
{
|
||||
RKLogWarning(@"Deprecated access to [RKRequestQueue setSharedQueue:]. Invoking [[RKClient sharedClient] setRequestQueue:]. Update your code to reference the specific queue instance you want.");
|
||||
[RKClient sharedClient].requestQueue = requestQueue;
|
||||
@@ -73,7 +73,7 @@ static const NSTimeInterval kFlushDelay = 0.3;
|
||||
return [[self new] autorelease];
|
||||
}
|
||||
|
||||
+ (id)newRequestQueueWithName:(NSString*)name
|
||||
+ (id)newRequestQueueWithName:(NSString *)name
|
||||
{
|
||||
if (RKRequestQueueInstances == nil) {
|
||||
RKRequestQueueInstances = [NSMutableArray new];
|
||||
@@ -83,7 +83,7 @@ static const NSTimeInterval kFlushDelay = 0.3;
|
||||
return nil;
|
||||
}
|
||||
|
||||
RKRequestQueue* queue = [self new];
|
||||
RKRequestQueue *queue = [self new];
|
||||
queue.name = name;
|
||||
[RKRequestQueueInstances addObject:[NSValue valueWithNonretainedObject:queue]];
|
||||
|
||||
@@ -99,8 +99,8 @@ static const NSTimeInterval kFlushDelay = 0.3;
|
||||
// Find existing reference
|
||||
NSArray *requestQueueInstances = [RKRequestQueueInstances copy];
|
||||
RKRequestQueue *namedQueue = nil;
|
||||
for (NSValue* value in requestQueueInstances) {
|
||||
RKRequestQueue* queue = (RKRequestQueue*) [value nonretainedObjectValue];
|
||||
for (NSValue *value in requestQueueInstances) {
|
||||
RKRequestQueue *queue = (RKRequestQueue *) [value nonretainedObjectValue];
|
||||
if ([queue.name isEqualToString:name]) {
|
||||
namedQueue = queue;
|
||||
break;
|
||||
@@ -117,13 +117,13 @@ static const NSTimeInterval kFlushDelay = 0.3;
|
||||
return namedQueue;
|
||||
}
|
||||
|
||||
+ (BOOL)requestQueueExistsWithName:(NSString*)name
|
||||
+ (BOOL)requestQueueExistsWithName:(NSString *)name
|
||||
{
|
||||
BOOL queueExists = NO;
|
||||
if (RKRequestQueueInstances) {
|
||||
NSArray *requestQueueInstances = [RKRequestQueueInstances copy];
|
||||
for (NSValue* value in requestQueueInstances) {
|
||||
RKRequestQueue* queue = (RKRequestQueue*) [value nonretainedObjectValue];
|
||||
for (NSValue *value in requestQueueInstances) {
|
||||
RKRequestQueue *queue = (RKRequestQueue *) [value nonretainedObjectValue];
|
||||
if ([queue.name isEqualToString:name]) {
|
||||
queueExists = YES;
|
||||
break;
|
||||
@@ -165,8 +165,8 @@ static const NSTimeInterval kFlushDelay = 0.3;
|
||||
- (void)removeFromNamedQueues
|
||||
{
|
||||
if (self.name) {
|
||||
for (NSValue* value in RKRequestQueueInstances) {
|
||||
RKRequestQueue* queue = (RKRequestQueue*) [value nonretainedObjectValue];
|
||||
for (NSValue *value in RKRequestQueueInstances) {
|
||||
RKRequestQueue *queue = (RKRequestQueue *) [value nonretainedObjectValue];
|
||||
if ([queue.name isEqualToString:self.name]) {
|
||||
[RKRequestQueueInstances removeObject:value];
|
||||
return;
|
||||
@@ -196,7 +196,7 @@ static const NSTimeInterval kFlushDelay = 0.3;
|
||||
return [_requests count];
|
||||
}
|
||||
|
||||
- (NSString*)description
|
||||
- (NSString *)description
|
||||
{
|
||||
return [NSString stringWithFormat:@"<%@: %p name=%@ suspended=%@ requestCount=%d loadingCount=%d/%d>",
|
||||
NSStringFromClass([self class]), self, self.name, self.suspended ? @"YES" : @"NO",
|
||||
@@ -208,7 +208,7 @@ static const NSTimeInterval kFlushDelay = 0.3;
|
||||
return [_loadingRequests count];
|
||||
}
|
||||
|
||||
- (void)addLoadingRequest:(RKRequest*)request
|
||||
- (void)addLoadingRequest:(RKRequest *)request
|
||||
{
|
||||
if (self.loadingCount == 0) {
|
||||
RKLogTrace(@"Loading count increasing from 0 to 1. Firing requestQueueDidBeginLoading");
|
||||
@@ -230,7 +230,7 @@ static const NSTimeInterval kFlushDelay = 0.3;
|
||||
RKLogTrace(@"Loading count now %ld for queue %@", (long) self.loadingCount, self);
|
||||
}
|
||||
|
||||
- (void)removeLoadingRequest:(RKRequest*)request
|
||||
- (void)removeLoadingRequest:(RKRequest *)request
|
||||
{
|
||||
if (self.loadingCount == 1 && [_loadingRequests containsObject:request]) {
|
||||
RKLogTrace(@"Loading count decreasing from 1 to 0. Firing requestQueueDidFinishLoading");
|
||||
@@ -264,10 +264,10 @@ static const NSTimeInterval kFlushDelay = 0.3;
|
||||
}
|
||||
}
|
||||
|
||||
- (RKRequest*)nextRequest
|
||||
- (RKRequest *)nextRequest
|
||||
{
|
||||
for (NSUInteger i = 0; i < [_requests count]; i++) {
|
||||
RKRequest* request = [_requests objectAtIndex:i];
|
||||
RKRequest *request = [_requests objectAtIndex:i];
|
||||
if ([request isUnsent]) {
|
||||
return request;
|
||||
}
|
||||
@@ -294,11 +294,11 @@ static const NSTimeInterval kFlushDelay = 0.3;
|
||||
return;
|
||||
}
|
||||
|
||||
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
_queueTimer = nil;
|
||||
|
||||
@synchronized(self) {
|
||||
RKRequest* request = [self nextRequest];
|
||||
RKRequest *request = [self nextRequest];
|
||||
while (request && self.loadingCount < _concurrentRequestsLimit) {
|
||||
RKLogTrace(@"Processing request %@ in queue %@", request, self);
|
||||
if ([_delegate respondsToSelector:@selector(requestQueue:willSendRequest:)]) {
|
||||
@@ -354,7 +354,7 @@ static const NSTimeInterval kFlushDelay = 0.3;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)addRequest:(RKRequest*)request
|
||||
- (void)addRequest:(RKRequest *)request
|
||||
{
|
||||
RKLogTrace(@"Request %@ added to queue %@", request, self);
|
||||
NSAssert(![self containsRequest:request], @"Attempting to add the same request multiple times");
|
||||
@@ -380,7 +380,7 @@ static const NSTimeInterval kFlushDelay = 0.3;
|
||||
[self loadNextInQueue];
|
||||
}
|
||||
|
||||
- (BOOL)removeRequest:(RKRequest*)request
|
||||
- (BOOL)removeRequest:(RKRequest *)request
|
||||
{
|
||||
if ([self containsRequest:request]) {
|
||||
RKLogTrace(@"Removing request %@ from queue %@", request, self);
|
||||
@@ -401,14 +401,14 @@ static const NSTimeInterval kFlushDelay = 0.3;
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)containsRequest:(RKRequest*)request
|
||||
- (BOOL)containsRequest:(RKRequest *)request
|
||||
{
|
||||
@synchronized(self) {
|
||||
return [_requests containsObject:request];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)cancelRequest:(RKRequest*)request loadNext:(BOOL)loadNext
|
||||
- (void)cancelRequest:(RKRequest *)request loadNext:(BOOL)loadNext
|
||||
{
|
||||
if ([request isUnsent]) {
|
||||
RKLogDebug(@"Cancelled undispatched request %@ and removed from queue %@", request, self);
|
||||
@@ -437,18 +437,18 @@ static const NSTimeInterval kFlushDelay = 0.3;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)cancelRequest:(RKRequest*)request
|
||||
- (void)cancelRequest:(RKRequest *)request
|
||||
{
|
||||
[self cancelRequest:request loadNext:YES];
|
||||
}
|
||||
|
||||
- (void)cancelRequestsWithDelegate:(NSObject<RKRequestDelegate>*)delegate
|
||||
- (void)cancelRequestsWithDelegate:(NSObject<RKRequestDelegate> *)delegate
|
||||
{
|
||||
RKLogDebug(@"Cancelling all request in queue %@ with delegate %p", self, delegate);
|
||||
|
||||
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
||||
NSArray* requestsCopy = [NSArray arrayWithArray:_requests];
|
||||
for (RKRequest* request in requestsCopy) {
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
NSArray *requestsCopy = [NSArray arrayWithArray:_requests];
|
||||
for (RKRequest *request in requestsCopy) {
|
||||
if (request.delegate && request.delegate == delegate) {
|
||||
[self cancelRequest:request];
|
||||
}
|
||||
@@ -456,13 +456,13 @@ static const NSTimeInterval kFlushDelay = 0.3;
|
||||
[pool drain];
|
||||
}
|
||||
|
||||
- (void)abortRequestsWithDelegate:(NSObject<RKRequestDelegate>*)delegate
|
||||
- (void)abortRequestsWithDelegate:(NSObject<RKRequestDelegate> *)delegate
|
||||
{
|
||||
RKLogDebug(@"Aborting all request in queue %@ with delegate %p", self, delegate);
|
||||
|
||||
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
||||
NSArray* requestsCopy = [NSArray arrayWithArray:_requests];
|
||||
for (RKRequest* request in requestsCopy) {
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
NSArray *requestsCopy = [NSArray arrayWithArray:_requests];
|
||||
for (RKRequest *request in requestsCopy) {
|
||||
if (request.delegate && request.delegate == delegate) {
|
||||
request.delegate = nil;
|
||||
[self cancelRequest:request];
|
||||
@@ -475,9 +475,9 @@ static const NSTimeInterval kFlushDelay = 0.3;
|
||||
{
|
||||
RKLogDebug(@"Cancelling all request in queue %@", self);
|
||||
|
||||
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
||||
NSArray* requestsCopy = [NSArray arrayWithArray:_requests];
|
||||
for (RKRequest* request in requestsCopy) {
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
NSArray *requestsCopy = [NSArray arrayWithArray:_requests];
|
||||
for (RKRequest *request in requestsCopy) {
|
||||
[self cancelRequest:request loadNext:NO];
|
||||
}
|
||||
[pool drain];
|
||||
@@ -494,13 +494,13 @@ static const NSTimeInterval kFlushDelay = 0.3;
|
||||
NSAssert([notification.object isKindOfClass:[RKRequest class]], @"Notification expected to contain an RKRequest, got a %@", NSStringFromClass([notification.object class]));
|
||||
RKLogTrace(@"Received notification: %@", notification);
|
||||
|
||||
RKRequest* request = (RKRequest*)notification.object;
|
||||
NSDictionary* userInfo = [notification userInfo];
|
||||
RKRequest *request = (RKRequest *)notification.object;
|
||||
NSDictionary *userInfo = [notification userInfo];
|
||||
|
||||
// We successfully loaded a response
|
||||
RKLogDebug(@"Received response for request %@, removing from queue. (Now loading %ld of %ld)", request, (long) self.loadingCount, (long) _concurrentRequestsLimit);
|
||||
|
||||
RKResponse* response = [userInfo objectForKey:RKRequestDidLoadResponseNotificationUserInfoResponseKey];
|
||||
RKResponse *response = [userInfo objectForKey:RKRequestDidLoadResponseNotificationUserInfoResponseKey];
|
||||
if ([_delegate respondsToSelector:@selector(requestQueue:didLoadResponse:)]) {
|
||||
[_delegate requestQueue:self didLoadResponse:response];
|
||||
}
|
||||
@@ -514,11 +514,11 @@ static const NSTimeInterval kFlushDelay = 0.3;
|
||||
NSAssert([notification.object isKindOfClass:[RKRequest class]], @"Notification expected to contain an RKRequest, got a %@", NSStringFromClass([notification.object class]));
|
||||
RKLogTrace(@"Received notification: %@", notification);
|
||||
|
||||
RKRequest* request = (RKRequest*)notification.object;
|
||||
NSDictionary* userInfo = [notification userInfo];
|
||||
RKRequest *request = (RKRequest *)notification.object;
|
||||
NSDictionary *userInfo = [notification userInfo];
|
||||
|
||||
// We failed with an error
|
||||
NSError* error = nil;
|
||||
NSError *error = nil;
|
||||
if (userInfo) {
|
||||
error = [userInfo objectForKey:RKRequestDidFailWithErrorNotificationUserInfoErrorKey];
|
||||
RKLogDebug(@"Request %@ failed loading in queue %@ with error: %@.(Now loading %ld of %ld)", request, self,
|
||||
@@ -544,7 +544,7 @@ static const NSTimeInterval kFlushDelay = 0.3;
|
||||
NSAssert([notification.object isKindOfClass:[RKRequest class]], @"Notification expected to contain an RKRequest, got a %@", NSStringFromClass([notification.object class]));
|
||||
RKLogTrace(@"Received notification: %@", notification);
|
||||
|
||||
RKRequest* request = (RKRequest*)notification.object;
|
||||
RKRequest *request = (RKRequest *)notification.object;
|
||||
if ([self containsRequest:request]) {
|
||||
[self removeRequest:request];
|
||||
|
||||
|
||||
@@ -20,6 +20,6 @@
|
||||
|
||||
@interface RKRequest (Internals)
|
||||
- (BOOL)prepareURLRequest;
|
||||
- (void)didFailLoadWithError:(NSError*)error;
|
||||
- (void)didFailLoadWithError:(NSError *)error;
|
||||
- (void)finalizeLoad:(BOOL)successful;
|
||||
@end
|
||||
|
||||
@@ -65,7 +65,7 @@ return __VA_ARGS__;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithRequest:(RKRequest*)request body:(NSData*)body headers:(NSDictionary*)headers
|
||||
- (id)initWithRequest:(RKRequest *)request body:(NSData *)body headers:(NSDictionary *)headers
|
||||
{
|
||||
self = [self initWithRequest:request];
|
||||
if (self) {
|
||||
@@ -77,7 +77,7 @@ return __VA_ARGS__;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithSynchronousRequest:(RKRequest*)request URLResponse:(NSHTTPURLResponse*)URLResponse body:(NSData*)body error:(NSError*)error
|
||||
- (id)initWithSynchronousRequest:(RKRequest *)request URLResponse:(NSHTTPURLResponse *)URLResponse body:(NSData *)body error:(NSError *)error
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
@@ -263,7 +263,7 @@ return __VA_ARGS__;
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString*)localizedStatusCodeString
|
||||
- (NSString *)localizedStatusCodeString
|
||||
{
|
||||
return [NSHTTPURLResponse localizedStringForStatusCode:[self statusCode]];
|
||||
}
|
||||
@@ -299,7 +299,7 @@ return __VA_ARGS__;
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (id)parsedBody:(NSError**)error
|
||||
- (id)parsedBody:(NSError **)error
|
||||
{
|
||||
id<RKParser> parser = [[RKParserRegistry sharedRegistry] parserForMIMEType:[self MIMEType]];
|
||||
if (! parser) {
|
||||
@@ -316,7 +316,7 @@ return __VA_ARGS__;
|
||||
return object;
|
||||
}
|
||||
|
||||
- (NSString*)failureErrorDescription
|
||||
- (NSString *)failureErrorDescription
|
||||
{
|
||||
if ([self isFailure]) {
|
||||
return [_failureError localizedDescription];
|
||||
@@ -330,7 +330,7 @@ return __VA_ARGS__;
|
||||
return (_responseHeaders != nil);
|
||||
}
|
||||
|
||||
- (NSURL*)URL
|
||||
- (NSURL *)URL
|
||||
{
|
||||
if ([self wasLoadedFromCache]) {
|
||||
return [NSURL URLWithString:[_responseHeaders valueForKey:RKRequestCacheURLHeadersKey]];
|
||||
@@ -338,7 +338,7 @@ return __VA_ARGS__;
|
||||
return [_httpURLResponse URL];
|
||||
}
|
||||
|
||||
- (NSString*)MIMEType
|
||||
- (NSString *)MIMEType
|
||||
{
|
||||
if ([self wasLoadedFromCache]) {
|
||||
return [_responseHeaders valueForKey:RKRequestCacheMIMETypeHeadersKey];
|
||||
@@ -354,7 +354,7 @@ return __VA_ARGS__;
|
||||
return ([_httpURLResponse respondsToSelector:@selector(statusCode)] ? [_httpURLResponse statusCode] : 200);
|
||||
}
|
||||
|
||||
- (NSDictionary*)allHeaderFields
|
||||
- (NSDictionary *)allHeaderFields
|
||||
{
|
||||
if ([self wasLoadedFromCache]) {
|
||||
return _responseHeaders;
|
||||
@@ -362,7 +362,7 @@ return __VA_ARGS__;
|
||||
return ([_httpURLResponse respondsToSelector:@selector(allHeaderFields)] ? [_httpURLResponse allHeaderFields] : nil);
|
||||
}
|
||||
|
||||
- (NSArray*)cookies
|
||||
- (NSArray *)cookies
|
||||
{
|
||||
return [NSHTTPCookie cookiesWithResponseHeaderFields:self.allHeaderFields forURL:self.URL];
|
||||
}
|
||||
@@ -472,24 +472,24 @@ return __VA_ARGS__;
|
||||
return ([self statusCode] == 503);
|
||||
}
|
||||
|
||||
- (NSString*)contentType
|
||||
- (NSString *)contentType
|
||||
{
|
||||
return ([[self allHeaderFields] objectForKey:@"Content-Type"]);
|
||||
}
|
||||
|
||||
- (NSString*)contentLength
|
||||
- (NSString *)contentLength
|
||||
{
|
||||
return ([[self allHeaderFields] objectForKey:@"Content-Length"]);
|
||||
}
|
||||
|
||||
- (NSString*)location
|
||||
- (NSString *)location
|
||||
{
|
||||
return ([[self allHeaderFields] objectForKey:@"Location"]);
|
||||
}
|
||||
|
||||
- (BOOL)isHTML
|
||||
{
|
||||
NSString* contentType = [self contentType];
|
||||
NSString *contentType = [self contentType];
|
||||
return (contentType && ([contentType rangeOfString:@"text/html"
|
||||
options:NSCaseInsensitiveSearch|NSAnchoredSearch].length > 0 ||
|
||||
[self isXHTML]));
|
||||
@@ -497,7 +497,7 @@ return __VA_ARGS__;
|
||||
|
||||
- (BOOL)isXHTML
|
||||
{
|
||||
NSString* contentType = [self contentType];
|
||||
NSString *contentType = [self contentType];
|
||||
return (contentType &&
|
||||
[contentType rangeOfString:@"application/xhtml+xml"
|
||||
options:NSCaseInsensitiveSearch|NSAnchoredSearch].length > 0);
|
||||
@@ -505,7 +505,7 @@ return __VA_ARGS__;
|
||||
|
||||
- (BOOL)isXML
|
||||
{
|
||||
NSString* contentType = [self contentType];
|
||||
NSString *contentType = [self contentType];
|
||||
return (contentType &&
|
||||
[contentType rangeOfString:@"application/xml"
|
||||
options:NSCaseInsensitiveSearch|NSAnchoredSearch].length > 0);
|
||||
@@ -513,7 +513,7 @@ return __VA_ARGS__;
|
||||
|
||||
- (BOOL)isJSON
|
||||
{
|
||||
NSString* contentType = [self contentType];
|
||||
NSString *contentType = [self contentType];
|
||||
return (contentType &&
|
||||
[contentType rangeOfString:@"application/json"
|
||||
options:NSCaseInsensitiveSearch|NSAnchoredSearch].length > 0);
|
||||
|
||||
@@ -80,11 +80,11 @@
|
||||
NSString *resourcePathWithoutQueryString = (queryCharacterRange.location == NSNotFound) ? theResourcePath : [theResourcePath substringToIndex:queryCharacterRange.location];
|
||||
NSString *baseURLPath = [[theBaseURL path] isEqualToString:@"/"] ? @"" : [[theBaseURL path] stringByStandardizingPath];
|
||||
NSString *completePath = resourcePathWithoutQueryString ? [baseURLPath stringByAppendingString:resourcePathWithoutQueryString] : baseURLPath;
|
||||
NSString* completePathWithQuery = [completePath stringByAppendingQueryParameters:mergedQueryParameters];
|
||||
NSString *completePathWithQuery = [completePath stringByAppendingQueryParameters:mergedQueryParameters];
|
||||
|
||||
// NOTE: You can't safely use initWithString:relativeToURL: in a NSURL subclass, see http://www.openradar.me/9729706
|
||||
// So we unfortunately convert into an NSURL before going back into an NSString -> RKURL
|
||||
NSURL* completeURL = [NSURL URLWithString:completePathWithQuery relativeToURL:theBaseURL];
|
||||
NSURL *completeURL = [NSURL URLWithString:completePathWithQuery relativeToURL:theBaseURL];
|
||||
if (!completeURL) {
|
||||
RKLogError(@"Failed to build RKURL by appending resourcePath and query parameters '%@' to baseURL '%@'", theResourcePath, theBaseURL);
|
||||
[self release];
|
||||
|
||||
Reference in New Issue
Block a user