Reworked error handling substantially. Decoupled OTRestResponse from Rails-isms. All the Rails dependent code is now in the modeling classes. Added numerous helpers on the response class and introduced OCMock to the project

This commit is contained in:
Blake Watters
2010-01-18 14:47:59 -05:00
parent e8d267c0f0
commit a74272b123
48 changed files with 439 additions and 108 deletions

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Blake Watters on 7/28/09.
// Copyright 2009 Objective 3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//
#import <Foundation/Foundation.h>

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Blake Watters on 7/28/09.
// Copyright 2009 Objective 3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//
#import "NSDictionary+OTRestRequestSerialization.h"

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Blake Watters on 7/28/09.
// Copyright 2009 Objective 3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//
#import "OTRestRequest.h"

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Blake Watters on 7/28/09.
// Copyright 2009 Objective 3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//
#import "OTRestClient.h"

View File

@@ -35,6 +35,12 @@
255DE0F410FFAC0A00A85891 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 255DE0F310FFAC0A00A85891 /* SystemConfiguration.framework */; };
255DE1B110FFB16800A85891 /* OTRestSpecResponseLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = 255DE1B010FFB16800A85891 /* OTRestSpecResponseLoader.m */; };
255DE37810FFC26900A85891 /* OTRestClientSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 255DE37710FFC26900A85891 /* OTRestClientSpec.m */; };
255DE43211010EE700A85891 /* OTRestRequestSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 255DE43111010EE700A85891 /* OTRestRequestSpec.m */; };
255DE43B11010F8400A85891 /* OTRestResponseSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 255DE43A11010F8400A85891 /* OTRestResponseSpec.m */; };
255DE453110112DB00A85891 /* OCMock.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 255DE449110112DB00A85891 /* OCMock.framework */; };
255DE4931101134300A85891 /* OCMock.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 255DE449110112DB00A85891 /* OCMock.framework */; };
255DE62B1104BA2B00A85891 /* OTRestModelMapperSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 3F6C3AD010FE76C1008F47C5 /* OTRestModelMapperSpec.m */; };
255DE62C1104BA2D00A85891 /* OTRestManagedModelSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 255DE03010FF9BDF00A85891 /* OTRestManagedModelSpec.m */; };
2580B068102E0F1000832D07 /* OTRestModelLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 2580B066102E0F1000832D07 /* OTRestModelLoader.h */; };
2580B069102E0F1000832D07 /* OTRestModelLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = 2580B067102E0F1000832D07 /* OTRestModelLoader.m */; };
2580B0C7102E1EBC00832D07 /* libElementParser.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3F4E18DB102DD31E00320118 /* libElementParser.a */; };
@@ -127,6 +133,13 @@
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
255DE3C210FFC86D00A85891 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 3F4E18D6102DD31E00320118 /* ElementParser.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 25FCE09E10360372005418A7;
remoteInfo = Tests;
};
3F4E18DA102DD31E00320118 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 3F4E18D6102DD31E00320118 /* ElementParser.xcodeproj */;
@@ -178,6 +191,19 @@
};
/* End PBXContainerItemProxy section */
/* Begin PBXCopyFilesBuildPhase section */
255DE48A110112F500A85891 /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "$(BUILT_PRODUCTS_DIR)";
dstSubfolderSpec = 0;
files = (
255DE4931101134300A85891 /* OCMock.framework in CopyFiles */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
2525EBE9106961DD0069EBED /* OTRestManagedObjectStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OTRestManagedObjectStore.h; sourceTree = "<group>"; };
2525EBEA106961DD0069EBED /* OTRestManagedObjectStore.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OTRestManagedObjectStore.m; sourceTree = "<group>"; };
@@ -189,12 +215,16 @@
255DE05910FF9DA500A85891 /* OTRestModelManagerSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OTRestModelManagerSpec.m; sourceTree = "<group>"; };
255DE05C10FFA05800A85891 /* OTHuman.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OTHuman.h; sourceTree = "<group>"; };
255DE05D10FFA05800A85891 /* OTHuman.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OTHuman.m; sourceTree = "<group>"; };
255DE0B610FFA52E00A85891 /* Data Model.xcdatamodel */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = wrapper.xcdatamodel; name = "Data Model.xcdatamodel"; path = "Models/Data Model.xcdatamodel"; sourceTree = "<group>"; };
255DE0B610FFA52E00A85891 /* Data Model.xcdatamodel */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = folder; path = "Data Model.xcdatamodel"; sourceTree = "<group>"; };
255DE0E110FFABA500A85891 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
255DE0F310FFAC0A00A85891 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; };
255DE1AF10FFB16800A85891 /* OTRestSpecResponseLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OTRestSpecResponseLoader.h; sourceTree = "<group>"; };
255DE1B010FFB16800A85891 /* OTRestSpecResponseLoader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OTRestSpecResponseLoader.m; sourceTree = "<group>"; };
255DE37710FFC26900A85891 /* OTRestClientSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OTRestClientSpec.m; sourceTree = "<group>"; };
255DE43111010EE700A85891 /* OTRestRequestSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OTRestRequestSpec.m; sourceTree = "<group>"; };
255DE43A11010F8400A85891 /* OTRestResponseSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OTRestResponseSpec.m; sourceTree = "<group>"; };
255DE449110112DB00A85891 /* OCMock.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OCMock.framework; path = Support/OCMock.framework; sourceTree = "<group>"; };
255DE4A4110113B700A85891 /* OTRestSpecEnvironment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OTRestSpecEnvironment.h; sourceTree = "<group>"; };
2580B066102E0F1000832D07 /* OTRestModelLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OTRestModelLoader.h; sourceTree = "<group>"; };
2580B067102E0F1000832D07 /* OTRestModelLoader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OTRestModelLoader.m; sourceTree = "<group>"; };
25FCDDD91035BC85005418A7 /* OTRestManagedModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OTRestManagedModel.h; sourceTree = "<group>"; };
@@ -298,6 +328,7 @@
3F6C3A9610FE7524008F47C5 /* UIKit.framework in Frameworks */,
255DE0E210FFABA500A85891 /* CoreData.framework in Frameworks */,
255DE0F410FFAC0A00A85891 /* SystemConfiguration.framework in Frameworks */,
255DE453110112DB00A85891 /* OCMock.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -356,6 +387,7 @@
255DE05B10FFA04200A85891 /* Models */ = {
isa = PBXGroup;
children = (
255DE0B610FFA52E00A85891 /* Data Model.xcdatamodel */,
255DE05C10FFA05800A85891 /* OTHuman.h */,
255DE05D10FFA05800A85891 /* OTHuman.m */,
3F032A7710FFB89100F35142 /* OTCat.h */,
@@ -373,10 +405,20 @@
children = (
255DE1AF10FFB16800A85891 /* OTRestSpecResponseLoader.h */,
255DE1B010FFB16800A85891 /* OTRestSpecResponseLoader.m */,
255DE4A4110113B700A85891 /* OTRestSpecEnvironment.h */,
);
path = Support;
sourceTree = "<group>";
};
255DE43011010ED400A85891 /* Core */ = {
isa = PBXGroup;
children = (
255DE43111010EE700A85891 /* OTRestRequestSpec.m */,
255DE43A11010F8400A85891 /* OTRestResponseSpec.m */,
);
name = Core;
sourceTree = "<group>";
};
2580B1AA102F72D700832D07 /* Dependencies */ = {
isa = PBXGroup;
children = (
@@ -457,6 +499,7 @@
isa = PBXGroup;
children = (
3F4E18DB102DD31E00320118 /* libElementParser.a */,
255DE3C310FFC86D00A85891 /* Tests.octest */,
);
name = Products;
sourceTree = "<group>";
@@ -498,14 +541,15 @@
3F6C3A9210FE750E008F47C5 /* Specs */ = {
isa = PBXGroup;
children = (
255DE43011010ED400A85891 /* Core */,
255DE0A110FFA43A00A85891 /* Support */,
255DE05B10FFA04200A85891 /* Models */,
3F6C3AD010FE76C1008F47C5 /* OTRestModelMapperSpec.m */,
255DE03010FF9BDF00A85891 /* OTRestManagedModelSpec.m */,
255DE05910FF9DA500A85891 /* OTRestModelManagerSpec.m */,
3F6C3A9310FE7519008F47C5 /* main.m */,
255DE0B610FFA52E00A85891 /* Data Model.xcdatamodel */,
255DE37710FFC26900A85891 /* OTRestClientSpec.m */,
255DE449110112DB00A85891 /* OCMock.framework */,
);
path = Specs;
sourceTree = "<group>";
@@ -623,6 +667,7 @@
3F6C39A210FE5C95008F47C5 /* Sources */,
3F6C39A310FE5C95008F47C5 /* Frameworks */,
255DE2B810FFBFBF00A85891 /* ShellScript */,
255DE48A110112F500A85891 /* CopyFiles */,
);
buildRules = (
);
@@ -684,6 +729,13 @@
/* End PBXProject section */
/* Begin PBXReferenceProxy section */
255DE3C310FFC86D00A85891 /* Tests.octest */ = {
isa = PBXReferenceProxy;
fileType = wrapper.cfbundle;
path = Tests.octest;
remoteRef = 255DE3C210FFC86D00A85891 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
3F4E18DB102DD31E00320118 /* libElementParser.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
@@ -815,6 +867,10 @@
3F032AA810FFBBCD00F35142 /* OTHouse.m in Sources */,
3F032AAB10FFBC1F00F35142 /* OTResident.m in Sources */,
255DE37810FFC26900A85891 /* OTRestClientSpec.m in Sources */,
255DE43211010EE700A85891 /* OTRestRequestSpec.m in Sources */,
255DE43B11010F8400A85891 /* OTRestResponseSpec.m in Sources */,
255DE62B1104BA2B00A85891 /* OTRestModelMapperSpec.m in Sources */,
255DE62C1104BA2D00A85891 /* OTRestManagedModelSpec.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1008,6 +1064,10 @@
BUILD_STYLE = Debug;
CODE_SIGN_IDENTITY = "iPhone Developer";
COPY_PHASE_STRIP = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/Specs/Support\"",
);
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
@@ -1035,6 +1095,10 @@
CODE_SIGN_IDENTITY = "iPhone Developer";
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/Specs/Support\"",
);
GCC_ENABLE_FIX_AND_CONTINUE = NO;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/UIKit.framework/Headers/UIKit.h";

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Blake Watters on 8/14/09.
// Copyright 2009 Objective 3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//
#import <Foundation/Foundation.h>

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Blake Watters on 8/14/09.
// Copyright 2009 Objective 3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//
#import "OTRestManagedModel.h"

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Blake Watters on 9/22/09.
// Copyright 2009 Objective 3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//
#import <CoreData/CoreData.h>

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Blake Watters on 9/22/09.
// Copyright 2009 Objective 3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//
#import "OTRestManagedObjectStore.h"

View File

@@ -3,15 +3,33 @@
// OTRestFramework
//
// Created by Blake Watters on 8/8/09.
// Copyright 2009 Objective 3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "OTRestModelMapper.h"
@class OTRestRequest;
@class OTRestResponse;
@protocol OTRestModelLoaderDelegate
/**
* Invoked when a request sent through the model manager encounters an error. The model will be nil if the request was
* not dispatched with a model object instance
*/
- (void)modelLoaderRequest:(OTRestRequest*)request didFailWithError:(NSError*)error response:(OTRestResponse*)response model:(id<OTRestModelMappable>)model;
/**
* Invoked when a request sent through the model manager returns an error message from the server.
*/
- (void)modelLoaderRequest:(OTRestRequest*)request didReturnErrorMessage:(NSString*)errorMessage response:(OTRestResponse*)response model:(id<OTRestModelMappable>)model;
@end
@interface OTRestModelLoader : NSObject {
OTRestModelMapper* _mapper;
id _delegate;
NSObject<OTRestModelLoaderDelegate>* _delegate;
SEL _callback;
}

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Blake Watters on 8/8/09.
// Copyright 2009 Objective 3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//
#import "OTRestModelLoader.h"
@@ -29,16 +29,46 @@
return @selector(loadModelsFromResponse:);
}
- (BOOL)processResponse:(OTRestResponse*)response {
NSString* errorMessage;
OTRestRequest* request = response.request;
if ([response isFailure]) {
[_delegate modelLoaderRequest:response.request didFailWithError:response.failureError response:response model:(id<OTRestModelMappable>)request.userData];
return YES;
} else if ([response isClientError]) {
if ([response isXML]) {
errorMessage = [[(Element*)[response payloadXMLDocument] selectElement:@"error"] contentsText];
} else if ([response isJSON]) {
// TODO - Need to test!!!
errorMessage = [[response payloadJSONDictionary] objectForKey:@"error"];
}
if (nil == errorMessage) {
errorMessage = [response payloadString];
}
[_delegate modelLoaderRequest:response.request didReturnErrorMessage:errorMessage response:response model:(id<OTRestModelMappable>)request.userData];
return YES;
} else if ([response isServerError]) {
errorMessage = [response payloadString];
[_delegate modelLoaderRequest:response.request didReturnErrorMessage:errorMessage response:response model:(id<OTRestModelMappable>)request.userData];
return YES;
}
return NO;
}
- (void)loadModelFromResponse:(OTRestResponse*)response {
NSLog(@"Attempting to build model from response: %@", [response payloadString]);
// TODO: This needs to handle errors!!!
id model = [_mapper buildModelFromString:[response payloadString]];
[_delegate performSelector:self.callback withObject:model];
if (NO == [self processResponse:response] && [response isSuccessful]) {
id model = [_mapper buildModelFromString:[response payloadString]];
[_delegate performSelector:self.callback withObject:model];
}
// TODO - What do we do???
}
- (void)loadModelsFromResponse:(OTRestResponse*)response {
NSArray* models = [_mapper buildModelsFromString:[response payloadString]];
[_delegate performSelector:self.callback withObject:models];
if (NO == [self processResponse:response] && [response isSuccessful]) {
NSArray* models = [_mapper buildModelsFromString:[response payloadString]];
[_delegate performSelector:self.callback withObject:models];
}
}
@end

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Jeremy Ellison on 8/14/09.
// Copyright 2009 Objective3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//
#import "OTRestModelMapper.h"

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Jeremy Ellison on 8/14/09.
// Copyright 2009 Objective3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//
#import "OTRestModelManager.h"
@@ -69,7 +69,7 @@ static OTRestModelManager* sharedManager = nil;
- (void)registerModel:(Class<OTRestModelMappable>)class forElementNamed:(NSString*)elementName {
[_mapper registerModel:class forElementNamed:elementName];
}
/**
* Load a model from a restful resource and invoke the callback
*/

View File

@@ -3,7 +3,7 @@
* OTRestFramework
*
* Created by Blake Watters on 8/14/09.
* Copyright 2009 Objective 3. All rights reserved.
* Copyright 2009 Two Toasters. All rights reserved.
*
*/
@@ -46,6 +46,16 @@
*/
- (NSString*)resourcePath;
/**
* The path to the RESTful resource collection this object belongs to. i.e. /books
*/
- (NSString*)collectionPath;
/**
* The path to the RESTful resource this object represents. i.e. /books/1
*/
- (NSString*)memberPath;
/**
* Must return the put/post params for the instance
*/

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Blake Watters on 8/14/09.
// Copyright 2009 Objective 3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//
#import <Foundation/Foundation.h>

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Blake Watters on 8/14/09.
// Copyright 2009 Objective 3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//
// #import <objc/objc-runtime.h>

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Jeremy Ellison on 8/17/09.
// Copyright 2009 Objective3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//
// See Also: http://developer.apple.com/iphone/library/documentation/Xcode/Conceptual/iphone_development/135-Unit_Testing_Applications/unit_testing_applications.html

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Jeremy Ellison on 8/17/09.
// Copyright 2009 Objective3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//
#import "OTRestModelMapperTest.h"

View File

@@ -3,7 +3,7 @@
* OTRestFramework
*
* Created by Jeremy Ellison on 8/18/09.
* Copyright 2009 Objective3. All rights reserved.
* Copyright 2009 Two Toasters. All rights reserved.
*
*/

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Blake Watters on 9/24/09.
// Copyright 2009 Objective 3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//
#import <Foundation/Foundation.h>

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Blake Watters on 9/24/09.
// Copyright 2009 Objective 3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//
#import "OTRestNotifications.h"

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Blake Watters on 8/3/09.
// Copyright 2009 Objective 3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//
#import <Foundation/Foundation.h>

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Blake Watters on 8/3/09.
// Copyright 2009 Objective 3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//
#import "OTRestParams.h"

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Blake Watters on 8/6/09.
// Copyright 2009 Objective 3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//
#import <Foundation/Foundation.h>

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Blake Watters on 8/6/09.
// Copyright 2009 Objective 3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//
#import "OTRestParamsAttachment.h"

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Blake Watters on 8/6/09.
// Copyright 2009 Objective 3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//
#import "OTRestParamsAttachment.h"

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Blake Watters on 8/6/09.
// Copyright 2009 Objective 3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//
#import "OTRestParamsDataAttachment.h"

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Blake Watters on 8/6/09.
// Copyright 2009 Objective 3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//
#import "OTRestParamsAttachment.h"

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Blake Watters on 8/6/09.
// Copyright 2009 Objective 3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//
#import "OTRestParamsFileAttachment.h"

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Jeremy Ellison on 7/27/09.
// Copyright 2009 Objective3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//
#import <Foundation/Foundation.h>
@@ -17,6 +17,7 @@
NSObject<OTRestRequestSerializable>* _params;
id _delegate;
SEL _callback;
id _userData;
}
@property(nonatomic, readonly) NSURL* URL;
@@ -41,6 +42,11 @@
*/
@property(nonatomic, assign) SEL callback;
/**
* An opaque pointer to associate user defined data with the request.
*/
@property(nonatomic, assign) id userData;
/**
* A Dictionary of additional HTTP Headers to send with the request
*/

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Jeremy Ellison on 7/27/09.
// Copyright 2009 Objective3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//
#import "OTRestRequest.h"
@@ -14,7 +14,7 @@
@implementation OTRestRequest
@synthesize URL = _URL, URLRequest = _URLRequest, delegate = _delegate, callback = _callback, additionalHTTPHeaders = _additionalHTTPHeaders,
params = _params;
params = _params, userData = _userData;
+ (OTRestRequest*)requestWithURL:(NSURL*)URL delegate:(id)delegate callback:(SEL)callback {
OTRestRequest* request = [[OTRestRequest alloc] initWithURL:URL delegate:delegate callback:callback];

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Blake Watters on 8/3/09.
// Copyright 2009 Objective 3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//
/*

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Blake Watters on 7/28/09.
// Copyright 2009 Objective 3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//
#import <Foundation/Foundation.h>
@@ -14,7 +14,7 @@
OTRestRequest* _request;
NSHTTPURLResponse* _httpURLResponse;
NSMutableData* _payload;
NSError* _error;
NSError* _failureError;
}
/**
@@ -48,9 +48,9 @@
@property(nonatomic, readonly) NSData* payload;
/**
* The error returned if the url connection fails
* The error returned if the URL connection fails
*/
@property(nonatomic, readonly) NSError* error;
@property(nonatomic, readonly) NSError* failureError;
/**
@@ -74,10 +74,109 @@
- (DocumentRoot*)payloadXMLDocument;
/**
* Will determine if there is an error object and use it's localized message
* or
* take the first <error> element out of the returned document.
* Parse the response into a dictionary from JSON
*/
- (NSString*)errorDescription;
- (NSDictionary*)payloadJSONDictionary;
/**
* Will determine if there is an error object and use it's localized message
*/
- (NSString*)failureErrorDescription;
/**
* Indicates that the connection failed to reach the remote server. The details of the failure
* are available on the failureError reader.
*/
- (BOOL)isFailure;
/**
* Indicates an invalid HTTP response code less than 100 or greater than 600
*/
- (BOOL)isInvalid;
/**
* Indicates an HTTP response code between 100 and 199
*/
- (BOOL)isInformational;
/**
* Indicates an HTTP response code between 200 and 299
*/
- (BOOL)isSuccessful;
/**
* Indicates an HTTP response code between 300 and 399
*/
- (BOOL)isRedirection;
/**
* Indicates an HTTP response code between 400 and 499
*/
- (BOOL)isClientError;
/**
* Indicates an HTTP response code between 500 and 599
*/
- (BOOL)isServerError;
/**
* Indicates that the response is either a server or a client error
*/
- (BOOL)isError;
/**
* Indicates an HTTP response code of 200
*/
- (BOOL)isOK;
/**
* Indicates an HTTP response code of 201
*/
- (BOOL)isCreated;
/**
* Indicates an HTTP response code of 403
*/
- (BOOL)isForbidden;
/**
* Indicates an HTTP response code of 404
*/
- (BOOL)isNotFound;
/**
* Indicates an HTTP response code of 301, 302, 303 or 307
*/
- (BOOL)isRedirect;
/**
* Indicates an empty HTTP response code of 201, 204, or 304
*/
- (BOOL)isEmpty;
/**
* Returns the value of 'Content-Type' HTTP header
*/
- (NSString*)contentType;
/**
* Returns the value of the 'Content-Length' HTTP header
*/
- (NSString*)contentLength;
/**
* Returns the value of the 'Location' HTTP Header
*/
- (NSString*)location;
/**
* True when the server turned an XML response (MIME type is application/xml)
*/
- (BOOL)isXML;
/**
* True when the server turned an XML response (MIME type is application/json)
*/
- (BOOL)isJSON;
@end

View File

@@ -3,20 +3,21 @@
// OTRestFramework
//
// Created by Blake Watters on 7/28/09.
// Copyright 2009 Objective 3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//
#import "OTRestResponse.h"
#import "OTRestNotifications.h"
#import "SBJSON.h"
@implementation OTRestResponse
@synthesize payload = _payload, request = _request, error = _error;
@synthesize payload = _payload, request = _request, failureError = _failureError;
- (id)init {
if (self = [super init]) {
_payload = [[NSMutableData alloc] init];
_error = nil;
_failureError = nil;
}
return self;
@@ -33,7 +34,7 @@
[_httpURLResponse release];
[_payload release];
[_request release];
[_error release];
[_failureError release];
[super dealloc];
}
@@ -54,7 +55,7 @@
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
_error = [error retain];
_failureError = [error retain];
[[_request delegate] performSelector:[_request callback] withObject:self];
}
@@ -70,18 +71,16 @@
return [DocumentRoot parseXML:[self payloadString]];
}
- (NSString*)errorDescription {
NSString* desc;
if (_error != nil) {
desc = [_error localizedDescription];
- (NSDictionary*)payloadJSONDictionary {
return [[[[SBJSON alloc] init] autorelease] objectWithString:[self payloadString]];
}
- (NSString*)failureErrorDescription {
if ([self isFailure]) {
return [_failureError localizedDescription];
} else {
NSString* contentsText = [[(Element*)[self payloadXMLDocument] selectElement:@"error"] contentsText];
if (contentsText == nil) {
contentsText = @"";
}
desc = [NSString stringWithFormat:@"#%d %@", [self statusCode], contentsText];
return nil;
}
return desc;
}
- (NSURL*)URL {
@@ -100,4 +99,80 @@
return [_httpURLResponse allHeaderFields];
}
- (BOOL)isFailure {
return (nil != _failureError);
}
- (BOOL)isInvalid {
return ([self statusCode] < 100 || [self statusCode] > 600);
}
- (BOOL)isInformational {
return ([self statusCode] >= 100 && [self statusCode] < 200);
}
- (BOOL)isSuccessful {
return ([self statusCode] >= 200 && [self statusCode] < 300);
}
- (BOOL)isRedirection {
return ([self statusCode] >= 300 && [self statusCode] < 400);
}
- (BOOL)isClientError {
return ([self statusCode] >= 400 && [self statusCode] < 500);
}
- (BOOL)isServerError {
return ([self statusCode] >= 500 && [self statusCode] < 600);
}
- (BOOL)isError {
return ([self isClientError] || [self isServerError]);
}
- (BOOL)isOK {
return ([self statusCode] == 200);
}
- (BOOL)isCreated {
return ([self statusCode] == 201);
}
- (BOOL)isForbidden {
return ([self statusCode] == 403);
}
- (BOOL)isNotFound {
return ([self statusCode] == 404);
}
- (BOOL)isRedirect {
return ([self statusCode] == 301 || [self statusCode] == 302 || [self statusCode] == 303 || [self statusCode] == 307);
}
- (BOOL)isEmpty {
return ([self statusCode] == 201 || [self statusCode] == 204 || [self statusCode] == 304);
}
- (NSString*)contentType {
return ([[self allHeaderFields] objectForKey:@"Content-Type"]);
}
- (NSString*)contentLength {
return ([[self allHeaderFields] objectForKey:@"Content-Length"]);
}
- (NSString*)location {
return ([[self allHeaderFields] objectForKey:@"Location"]);
}
- (BOOL)isXML {
return [[self contentType] isEqualToString:@"application/xml"];
}
- (BOOL)isJSON {
return [[self contentType] isEqualToString:@"application/json"];
}
@end

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Blake Watters on 1/14/10.
// Copyright 2010 Objective 3. All rights reserved.
// Copyright 2010 Two Toasters. All rights reserved.
//
#import "OTRestManagedModel.h"

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Blake Watters on 1/14/10.
// Copyright 2010 Objective 3. All rights reserved.
// Copyright 2010 Two Toasters. All rights reserved.
//
#import "OTHuman.h"

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Blake Watters on 1/14/10.
// Copyright 2010 Objective 3. All rights reserved.
// Copyright 2010 Two Toasters. All rights reserved.
//

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Blake Watters on 1/14/10.
// Copyright 2010 Objective 3. All rights reserved.
// Copyright 2010 Two Toasters. All rights reserved.
//
@@ -11,7 +11,7 @@
#import "dsl/UIExpectation.h"
#import "OTRestModelManager.h"
#import "Human.h"
#import "OTHuman.h"
@interface OTRestManagedModelSpec : NSObject <UISpec> {

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Blake Watters on 1/14/10.
// Copyright 2010 Objective 3. All rights reserved.
// Copyright 2010 Two Toasters. All rights reserved.
//
#import "UISpec.h"
@@ -28,36 +28,9 @@
_modelManager = [OTRestModelManager managerWithBaseURL:localBaseURL];
_modelManager.objectStore = [[OTRestManagedObjectStore alloc] initWithStoreFilename:@"OTRest_Specs.sqlite"];
[_modelManager registerModel:[OTHuman class] forElementNamed:@"human"];
// TODO: Set the accept header...
_responseLoader = [[OTRestSpecResponseLoader alloc] init];
}
- (void)itShouldLoadAHuman {
NSLog(@"Model Manager: %@", _modelManager);
NSLog(@"Response Loader: %@", _responseLoader);
OTRestRequest* request = [_modelManager loadModel:@"/humans/1" delegate:_responseLoader callback:@selector(loadResponse:)];
NSLog(@"Request: %@", request);
[_responseLoader waitForResponse];
OTHuman* blake = (OTHuman*) _responseLoader.response;
[expectThat(blake.name) should:be(@"Blake Watters")];
}
- (void)itShouldLoadAllHumans {
OTRestRequest* request = [_modelManager loadModels:@"/humans" delegate:_responseLoader callback:@selector(loadResponse:)];
NSLog(@"Request: %@", request);
[_responseLoader waitForResponse];
NSArray* humans = (NSArray*) _responseLoader.response;
[expectThat([humans count]) should:be(4)];
[expectThat([[humans objectAtIndex:0] class]) should:be([OTHuman class])];
}
- (void)itShouldLoadHumansInPages {
}
- (void)itShouldHandleConnectionFailures {
}
- (void)itShouldDefaultToAnXMLMappingFormat {
[expectThat(_modelManager.format) should:be(OTRestMappingFormatXML)];
}
@@ -69,4 +42,30 @@
[expectThat([_modelManager.client.HTTPHeaders valueForKey:@"Accept"]) should:be(@"application/json")];
}
- (void)itShouldHandleConnectionFailures {
NSString* localBaseURL = [NSString stringWithFormat:@"http://%s:3001", getenv("OTREST_IP_ADDRESS")];
OTRestModelManager* modelManager = [OTRestModelManager managerWithBaseURL:localBaseURL];
[modelManager loadModel:@"/humans/1" delegate:_responseLoader callback:@selector(loadResponse:)];
[_responseLoader waitForResponse];
[expectThat(_responseLoader.success) should:be(NO)];
}
- (void)itShouldLoadAHuman {
[_modelManager loadModel:@"/humans/1" delegate:_responseLoader callback:@selector(loadResponse:)];
[_responseLoader waitForResponse];
OTHuman* blake = (OTHuman*) _responseLoader.response;
[expectThat(blake.name) should:be(@"Blake Watters")];
}
- (void)itShouldLoadAllHumans {
[_modelManager loadModels:@"/humans" delegate:_responseLoader callback:@selector(loadResponse:)];
[_responseLoader waitForResponse];
NSArray* humans = (NSArray*) _responseLoader.response;
[expectThat([humans count]) should:be(4)];
[expectThat([[humans objectAtIndex:0] class]) should:be([OTHuman class])];
}
- (void)itShouldLoadHumansInPages {
}
@end

View File

@@ -3,7 +3,7 @@
// Cash Register
//
// Created by Jeremy Ellison on 12/8/09.
// Copyright 2009 Objective3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//

View File

@@ -3,20 +3,32 @@
// OTRestFramework
//
// Created by Blake Watters on 1/14/10.
// Copyright 2010 Objective 3. All rights reserved.
// Copyright 2010 Two Toasters. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "OTRestModelLoader.h"
@interface OTRestSpecResponseLoader : NSObject {
@interface OTRestSpecResponseLoader : NSObject <OTRestModelLoaderDelegate> {
BOOL _awaitingResponse;
BOOL _success;
id _response;
NSError* _failureError;
NSString* _errorMessage;
}
// The object that was loaded from the web request
@property (nonatomic, readonly) id response;
// True when the response is success
@property (nonatomic, readonly) BOOL success;
// The error that was returned from a failure to connect
@property (nonatomic, readonly) NSError* failureError;
// The error message returned by the server
@property (nonatomic, readonly) NSString* errorMessage;
// Wait for a response to load
- (void)waitForResponse;
- (void)loadResponse:(id)response;

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Blake Watters on 1/14/10.
// Copyright 2010 Objective 3. All rights reserved.
// Copyright 2010 Two Toasters. All rights reserved.
//
#import "OTRestSpecResponseLoader.h"
@@ -12,9 +12,14 @@
@implementation OTRestSpecResponseLoader
@synthesize response = _response;
@synthesize failureError = _failureError;
@synthesize errorMessage = _errorMessage;
@synthesize success = _success;
- (void)dealloc {
[_response release];
[_failureError release];
[_errorMessage release];
[super dealloc];
}
@@ -30,6 +35,19 @@
NSLog(@"The response: %@", response);
_response = [response retain];
_awaitingResponse = NO;
_success = YES;
}
- (void)modelLoaderRequest:(OTRestRequest*)request didFailWithError:(NSError*)error response:(OTRestResponse*)response model:(id<OTRestModelMappable>)model {
_awaitingResponse = NO;
_success = NO;
_failureError = [error retain];
}
- (void)modelLoaderRequest:(OTRestRequest*)request didReturnErrorMessage:(NSString*)errorMessage response:(OTRestResponse*)response model:(id<OTRestModelMappable>)model {
_awaitingResponse = NO;
_success = NO;
_errorMessage = [errorMessage retain];
}
@end

Binary file not shown.

View File

@@ -3,7 +3,7 @@
// Cash Register
//
// Created by Jeremy Ellison on 12/7/09.
// Copyright Objective3 2009. All rights reserved.
// Copyright Two Toasters 2009. All rights reserved.
//
#import <UIKit/UIKit.h>

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Jeremy Ellison on 8/17/09.
// Copyright 2009 Objective3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//
#import <Foundation/Foundation.h>

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Jeremy Ellison on 8/17/09.
// Copyright 2009 Objective3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//
#import "TestSerialization.h"

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Jeremy Ellison on 8/17/09.
// Copyright 2009 Objective3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//
#import <Foundation/Foundation.h>

View File

@@ -3,7 +3,7 @@
// OTRestFramework
//
// Created by Jeremy Ellison on 8/17/09.
// Copyright 2009 Objective3. All rights reserved.
// Copyright 2009 Two Toasters. All rights reserved.
//
#import "TestSerializationAssociation.h"