Rework path based response descriptor matching and expand test coverage. Eliminate path normalization. fixes #987

This commit is contained in:
Blake Watters
2012-10-14 13:46:38 -04:00
parent 4a7ed3cbd3
commit f3ece00743
13 changed files with 300 additions and 109 deletions

View File

@@ -36,11 +36,10 @@
Creates and returns a new `RKResponseDescriptor` object.
@param mapping The mapping for the response descriptor.
@param pathPattern A path pattern that matches against URLs for which the mapping should be used. The path pattern will be normalized on input via `RKPathNormalize`.
@param pathPattern A path pattern that matches against URLs for which the mapping should be used.
@param keyPath A key path specifying the subset of the parsed response for which the mapping is to be used.
@param statusCodes A set of HTTP status codes for which the mapping is to be used.
@return A new `RKResponseDescriptor` object.
@see `RKPathNormalize`
*/
+ (RKResponseDescriptor *)responseDescriptorWithMapping:(RKMapping *)mapping
pathPattern:(NSString *)pathPattern

View File

@@ -20,7 +20,7 @@
#import "RKPathMatcher.h"
#import "RKResponseDescriptor.h"
#import "RKPathUtilities.h"
#import "RKHTTPUtilities.h"
// Cloned from AFStringFromIndexSet -- method should be non-static for reuse
static NSString *RKStringFromIndexSet(NSIndexSet *indexSet) {
@@ -53,23 +53,6 @@ static NSString *RKStringFromIndexSet(NSIndexSet *indexSet) {
return string;
}
// Assumes that URL is relative to baseURL
static NSString *RKPathAndQueryStringFromURLRelativeToURL(NSURL *URL, NSURL *baseURL)
{
if (baseURL) {
NSString *pathAndQuery = [[URL absoluteString] substringFromIndex:[[baseURL absoluteString] length]];
return ([pathAndQuery characterAtIndex:0] != '/') ? [NSString stringWithFormat:@"/%@", pathAndQuery] : pathAndQuery;
} else {
NSString *query = [URL query];
return (query && [query length]) ? [NSString stringWithFormat:@"%@?%@", [URL path], query] : [URL path];
}
}
static BOOL RKURLIsRelativeToURL(NSURL *sourceURL, NSURL *baseURL)
{
return [[sourceURL absoluteString] hasPrefix:[baseURL absoluteString]];
}
@interface RKResponseDescriptor ()
@property (nonatomic, strong, readwrite) RKMapping *mapping;
@property (nonatomic, copy, readwrite) NSString *pathPattern;
@@ -87,7 +70,7 @@ static BOOL RKURLIsRelativeToURL(NSURL *sourceURL, NSURL *baseURL)
NSParameterAssert(mapping);
RKResponseDescriptor *mappingDescriptor = [self new];
mappingDescriptor.mapping = mapping;
mappingDescriptor.pathPattern = pathPattern ? RKPathNormalize(pathPattern) : nil;
mappingDescriptor.pathPattern = pathPattern;
mappingDescriptor.keyPath = keyPath;
mappingDescriptor.statusCodes = statusCodes;

View File

@@ -55,7 +55,7 @@
*/
- (id)initWithResponse:(NSHTTPURLResponse *)response
data:(NSData *)data
responseDescriptors:(NSArray *)responseDescriptors;
responseDescriptors:(NSArray *)responseDescriptors;
///------------------------------
/// @name Accessing Response Data