// // RKResponseDescriptor.m // RestKit // // Created by Blake Watters on 8/16/12. // Copyright (c) 2009-2012 RestKit. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import #import "RKResponseDescriptor.h" // Cloned from AFStringFromIndexSet -- method should be non-static for reuse static NSString * RKStringFromIndexSet(NSIndexSet *indexSet) { NSMutableString *string = [NSMutableString string]; NSRange range = NSMakeRange([indexSet firstIndex], 1); while (range.location != NSNotFound) { NSUInteger nextIndex = [indexSet indexGreaterThanIndex:range.location]; while (nextIndex == range.location + range.length) { range.length++; nextIndex = [indexSet indexGreaterThanIndex:nextIndex]; } if (string.length) { [string appendString:@","]; } if (range.length == 1) { [string appendFormat:@"%u", range.location]; } else { NSUInteger firstIndex = range.location; NSUInteger lastIndex = firstIndex + range.length - 1; [string appendFormat:@"%u-%u", firstIndex, lastIndex]; } range.location = nextIndex; range.length = 1; } return string; } @interface RKResponseDescriptor () @property (nonatomic, strong, readwrite) RKMapping *mapping; @property (nonatomic, copy, readwrite) NSString *pathPattern; @property (nonatomic, copy, readwrite) NSString *keyPath; @property (nonatomic, copy, readwrite) NSIndexSet *statusCodes; @end @implementation RKResponseDescriptor + (RKResponseDescriptor *)responseDescriptorWithMapping:(RKMapping *)mapping pathPattern:(NSString *)pathPattern keyPath:(NSString *)keyPath statusCodes:(NSIndexSet *)statusCodes { RKResponseDescriptor *mappingDescriptor = [self new]; mappingDescriptor.mapping = mapping; mappingDescriptor.pathPattern = pathPattern; mappingDescriptor.keyPath = keyPath; mappingDescriptor.statusCodes = statusCodes; return mappingDescriptor; } - (NSString *)description { return [NSString stringWithFormat:@"<%@: %p pathPattern=%@ keyPath=%@ statusCodes=%@ : %@>", NSStringFromClass([self class]), self, self.pathPattern, self.keyPath, RKStringFromIndexSet(self.statusCodes), self.mapping]; } @end