Add a decent description method to the object request operations

This commit is contained in:
Blake Watters
2012-10-22 19:29:58 -04:00
parent ae52a10955
commit f96fee87b6
2 changed files with 33 additions and 1 deletions

View File

@@ -67,6 +67,31 @@ static NSIndexSet *RKObjectRequestOperationAcceptableMIMETypes()
return statusCodes;
}
static NSString *RKStringForStateOfObjectRequestOperation(RKObjectRequestOperation *operation)
{
if ([operation isExecuting]) {
return @"Executing";
} else if ([operation isFinished]) {
if (operation.error) {
return @"Failed";
} else {
return @"Successful";
}
} else {
return @"Ready";
}
}
static NSString *RKStringDescribingURLResponseWithData(NSURLResponse *response, NSData *data)
{
if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
NSHTTPURLResponse *HTTPResponse = (NSHTTPURLResponse *)response;
return [NSString stringWithFormat:@"<%@: %p statusCode=%ld MIMEType=%@ length=%ld>", [response class], response, (long) [HTTPResponse statusCode], [HTTPResponse MIMEType], (long) [data length]];
} else {
return [response description];
}
}
@interface RKObjectRequestOperation ()
@property (nonatomic, strong, readwrite) RKHTTPRequestOperation *HTTPRequestOperation;
@property (nonatomic, strong, readwrite) NSArray *responseDescriptors;
@@ -257,4 +282,11 @@ static NSIndexSet *RKObjectRequestOperationAcceptableMIMETypes()
[[NSNotificationCenter defaultCenter] postNotificationName:RKObjectRequestOperationDidFinishNotification object:self];
}
- (NSString *)description {
return [NSString stringWithFormat:@"<%@: %p, state: %@, isCancelled=%@, request: %@, response: %@>",
NSStringFromClass([self class]), self, RKStringForStateOfObjectRequestOperation(self), [self isCancelled] ? @"YES" : @"NO",
self.HTTPRequestOperation.request, RKStringDescribingURLResponseWithData(self.HTTPRequestOperation.response, self.HTTPRequestOperation.responseData)];
}
@end

View File

@@ -46,7 +46,7 @@
- (NSString *)description
{
return [NSString stringWithFormat:@"<%@:%p %@ => %@>", self.class, self, self.sourceKeyPath, self.destinationKeyPath];
return [NSString stringWithFormat:@"<%@: %p %@ => %@>", self.class, self, self.sourceKeyPath, self.destinationKeyPath];
}
@end