32 NSString *location = [[response
headerFields] objectForKey:@"Location"];
37 NSRegularExpression *re = [NSRegularExpression regularExpressionWithPattern:@"\\/([^\\/]*?)(\\.\\w+)?$" options:0 error:NULL];
38 NSTextCheckingResult *match = [re firstMatchInString:location options:0 range:NSMakeRange(0, [location length])];
39 if (match == nil || [match numberOfRanges] < 2)
43 NSString *
string = [location substringWithRange:[match rangeAtIndex:1]];
44 NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
45 return [numberFormatter numberFromString:string];
50 return !((100 <= code && code <= 199) || code == 204 || code == 304);
55 - (void)updateWithCompletionHandler:(
void (^)(
ARHTTPResponse *response, NSError *error))completionHandler
61 if ([
attributes isKindOfClass:[NSDictionary class]])
64 completionHandler(response, nil);
68 completionHandler(response, [NSError errorWithDomain:ARErrorDomain code:ARUnsupportedRootObjectTypeError userInfo:nil]);
73 completionHandler(response, error);
78 - (void)createWithCompletionHandler:(
void (^)(
ARHTTPResponse *response, NSError *error))completionHandler
84 if ([
attributes isKindOfClass:[NSDictionary class]])
86 [
self setID:ARIDFromResponse(response)];
88 completionHandler(response, nil);
92 completionHandler(response, [NSError errorWithDomain:ARErrorDomain code:ARUnsupportedRootObjectTypeError userInfo:nil]);
97 completionHandler(response, error);
102 - (void)loadAttributesFromResponse:(
ARHTTPResponse *)response attributes:(NSDictionary *)attributes
104 NSDictionary *headerFields;
105 NSString *contentLength;
108 ((contentLength = [headerFields = [response
headerFields] objectForKey:@"Content-Length"]) == nil || ![contentLength isEqualToString:
@"0"]))
111 [
self setPersisted:YES];
115 - (NSString *)elementPathWithOptions:(NSDictionary *)options
121 #pragma mark Active Model Conversions
126 return [
self persisted] ? [NSArray arrayWithObject:[
self ID]] : nil;
129 - (NSString *)toParam
132 return [
self persisted] ? [[
self toKey] componentsJoinedByString:@"-"] : nil;