├── Source ├── HTTPRiot │ ├── HTTPRiot_Prefix.pch │ ├── Vendor │ │ ├── KissXML │ │ │ ├── DDXML.h │ │ │ ├── NSStringAdditions.h │ │ │ ├── NSStringAdditions.m │ │ │ ├── DDXMLElementAdditions.h │ │ │ ├── DDXMLElement.h │ │ │ ├── DDXMLDocument.h │ │ │ ├── DDXMLPrivate.h │ │ │ ├── DDXMLElementAdditions.m │ │ │ ├── DDXMLDocument.m │ │ │ └── DDXMLNode.h │ │ ├── gh-unit-iphone │ │ │ ├── libGHUnitIPhone4_0.a │ │ │ ├── Makefile │ │ │ ├── GHTestGroup+JUnitXML.h │ │ │ ├── GHUnitIPhoneAppDelegate.h │ │ │ ├── GHTest+JUnitXML.h │ │ │ ├── GHTestOperation.h │ │ │ ├── GHUnit.h │ │ │ ├── NSValue+GHValueFormatter.h │ │ │ ├── GHUnitIPhoneTestMain.m │ │ │ ├── NSException+GHTestFailureExceptions.h │ │ │ ├── GHTestSuite.h │ │ │ ├── GHTesting.h │ │ │ ├── GHAsyncTestCase.h │ │ │ ├── GHTestCase.h │ │ │ ├── GHTestGroup.h │ │ │ ├── GHTestRunner.h │ │ │ └── GHTest.h │ │ ├── AIXMLSerialization │ │ │ ├── AIXMLDocumentSerialize.h │ │ │ ├── AIXMLDocumentSerialize.m │ │ │ ├── AIXMLSerialization.h │ │ │ └── AIXMLElementSerialize.m │ │ └── JSON │ │ │ ├── CREDITS │ │ │ ├── NSString+SBJSON.m │ │ │ ├── NSObject+SBJSON.m │ │ │ ├── JSON.h │ │ │ ├── NSString+SBJSON.h │ │ │ ├── NSObject+SBJSON.h │ │ │ ├── SBJsonBase.m │ │ │ ├── SBJSON.h │ │ │ ├── SBJsonBase.h │ │ │ ├── SBJsonParser.h │ │ │ └── SBJsonWriter.h │ ├── Extensions │ │ ├── NSDictionary+ParamUtils.h │ │ ├── NSString+EscapingUtils.h │ │ ├── NSObject+InvocationUtils.h │ │ ├── NSString+EscapingUtils.m │ │ ├── NSDictionary+ParamUtils.m │ │ └── NSObject+InvocationUtils.m │ ├── Formatters │ │ ├── HRFormatXML.h │ │ ├── HRFormatJSON.h │ │ ├── HRFormatterFactory.h │ │ ├── HRFormatXML.m │ │ ├── HRFormatJSON.m │ │ ├── HRFormatterProtocol.h │ │ └── HRFormatterFactory.m │ ├── Utilities │ │ ├── HRBase64.h │ │ └── HRBase64.m │ ├── HROperationQueue.h │ ├── HROperationQueue.m │ ├── HRGlobal.m │ ├── HRGlobal.h │ ├── HRResponseDelegate.h │ ├── HRRequestOperation.h │ ├── HRRestModel.m │ └── HTTPRiot.h ├── iPhoneSampleApp │ ├── ISAAlertHelper.h │ ├── iPhoneSampleApp_Prefix.pch │ ├── main.m │ ├── ISAEditableTextFieldCell.h │ ├── ISAPeopleTableViewController.h │ ├── iPhoneSampleAppDelegate.h │ ├── ISAAlertHelper.m │ ├── ISAPeopleDetailController.h │ ├── iPhoneSampleAppDelegate.m │ ├── ISAEditableTextFieldCell.m │ ├── ISAPeopleTableViewController.m │ └── ISAPeopleDetailController.m └── Tests │ ├── Server │ ├── README │ ├── views │ │ ├── people.erb │ │ └── layout.erb │ ├── lib │ │ └── authorization.rb │ └── testserver.rb │ ├── README │ ├── HRUtilitiesTest.m │ ├── HTTPRiotTestHelper.h │ ├── HTTPRiotTestHelper.m │ ├── HRFormatterFactoryTest.m │ ├── HRExtensionsTest.m │ ├── GHUnitTestMain.m │ ├── HTTPRiotRestModelTest.m │ └── HTTPRiotRequestTest.m ├── .gitattributes ├── Documentation ├── images │ ├── httpriot.png │ ├── copy-files.png │ ├── additional-sdks.png │ ├── httpriot-framework.png │ └── other-linker-flags.png ├── slate │ ├── images │ │ ├── nav-bg.gif │ │ └── nav-bg.png │ └── index.html └── Samples │ └── Tweet.m ├── HTTPRiot.xcodeproj └── TemplateIcon.icns ├── Gemfile ├── Resources ├── TODO ├── iPhoneUnitTestsRunner-Info.plist ├── Info.plist ├── iPhoneSampleApp-Info.plist └── LICENSE ├── .gitignore ├── Gemfile.lock ├── CHANGELOG └── README.md /Source/HTTPRiot/HTTPRiot_Prefix.pch: -------------------------------------------------------------------------------- 1 | #import "HRGlobal.h" -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.xib -diff -merge 2 | *.pbxproj -diff -merge 3 | -------------------------------------------------------------------------------- /Source/iPhoneSampleApp/ISAAlertHelper.h: -------------------------------------------------------------------------------- 1 | void ISAAlertWithMessage(NSString *message); 2 | -------------------------------------------------------------------------------- /Documentation/images/httpriot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ognen/httpriot/HEAD/Documentation/images/httpriot.png -------------------------------------------------------------------------------- /Documentation/images/copy-files.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ognen/httpriot/HEAD/Documentation/images/copy-files.png -------------------------------------------------------------------------------- /HTTPRiot.xcodeproj/TemplateIcon.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ognen/httpriot/HEAD/HTTPRiot.xcodeproj/TemplateIcon.icns -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/KissXML/DDXML.h: -------------------------------------------------------------------------------- 1 | #import "DDXMLNode.h" 2 | #import "DDXMLElement.h" 3 | #import "DDXMLDocument.h" 4 | -------------------------------------------------------------------------------- /Documentation/slate/images/nav-bg.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ognen/httpriot/HEAD/Documentation/slate/images/nav-bg.gif -------------------------------------------------------------------------------- /Documentation/slate/images/nav-bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ognen/httpriot/HEAD/Documentation/slate/images/nav-bg.png -------------------------------------------------------------------------------- /Documentation/images/additional-sdks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ognen/httpriot/HEAD/Documentation/images/additional-sdks.png -------------------------------------------------------------------------------- /Documentation/images/httpriot-framework.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ognen/httpriot/HEAD/Documentation/images/httpriot-framework.png -------------------------------------------------------------------------------- /Documentation/images/other-linker-flags.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ognen/httpriot/HEAD/Documentation/images/other-linker-flags.png -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/gh-unit-iphone/libGHUnitIPhone4_0.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ognen/httpriot/HEAD/Source/HTTPRiot/Vendor/gh-unit-iphone/libGHUnitIPhone4_0.a -------------------------------------------------------------------------------- /Source/HTTPRiot/Extensions/NSDictionary+ParamUtils.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface NSDictionary (ParamUtils) 4 | - (NSString*) toQueryString; 5 | @end 6 | 7 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Extensions/NSString+EscapingUtils.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface NSString (EscapingUtils) 4 | - (NSString *) stringByPreparingForURL; 5 | @end 6 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'http://rubygems.org' 2 | 3 | gem 'rake' 4 | gem 'plist' 5 | gem 'versionomy' 6 | gem 'sinatra' 7 | gem 'sequel' 8 | gem 'json' 9 | gem 'faker' 10 | gem 'builder' 11 | gem 'sqlite3' 12 | -------------------------------------------------------------------------------- /Resources/TODO: -------------------------------------------------------------------------------- 1 | * [DONE]Update documentation to match new api 2 | * Use strings for specifying formats 3 | * Add plist encode/decode support 4 | * XML encode support - conversion from NSDictionary/NSArray to NSXMLDocument -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | pkg/* 2 | build/* 3 | .svn 4 | .DS_Store 5 | *.pbxuser 6 | *.mode1v3 7 | *.mode2v3 8 | .rake_tasks 9 | .classes.* 10 | .methods.* 11 | build 12 | *.psd 13 | *.perspectivev3 14 | *.tm_build_errors 15 | *.json 16 | .rvmrc 17 | -------------------------------------------------------------------------------- /Source/Tests/Server/README: -------------------------------------------------------------------------------- 1 | Runs a local test server on port 4567. 2 | 3 | Requirements 4 | * sinatra - sudo gem install sinatra 5 | * sequel - sudo gem install sequel 6 | * faker - sudo gem install faker 7 | * json - sudo gem install json 8 | * xml-simple - sudo gem install xml-simple -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/KissXML/NSStringAdditions.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | 5 | @interface NSString (NSStringAdditions) 6 | 7 | /** 8 | * xmlChar - A basic replacement for char, a byte in a UTF-8 encoded string. 9 | **/ 10 | - (const xmlChar *)xmlChar; 11 | 12 | - (NSString *)stringByTrimming; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Formatters/HRFormatXML.h: -------------------------------------------------------------------------------- 1 | // 2 | // HRFormatXML.h 3 | // HTTPRiot 4 | // 5 | // Created by Justin Palmer on 2/8/09. 6 | // Copyright 2009 Alternateidea. All rights reserved. 7 | // 8 | #import 9 | #import "HRFormatterProtocol.h" 10 | @interface HRFormatXML : NSObject { 11 | 12 | } 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Formatters/HRFormatJSON.h: -------------------------------------------------------------------------------- 1 | // 2 | // HRFormatJSON.h 3 | // HTTPRiot 4 | // 5 | // Created by Justin Palmer on 2/8/09. 6 | // Copyright 2009 Alternateidea. All rights reserved. 7 | // 8 | #import 9 | #import "HRFormatterProtocol.h" 10 | 11 | @interface HRFormatJSON : NSObject { 12 | 13 | } 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Source/Tests/README: -------------------------------------------------------------------------------- 1 | ## Running the Unit Tests 2 | 3 | ### Install Prerequisites 4 | * sudo gem install sinatra 5 | * sudo gem install sequel 6 | * sudo gem install faker 7 | * sudo gem install json 8 | 9 | ### Run them 10 | 1. From the command line start the test server `ruby testserver.rb` 11 | 2. Set the Active Executable to 'otest' 12 | 3. Set the Active Target to 'UnitTests' 13 | 4. ⌘B to Build then ⌘ ⌥Y to Debug -------------------------------------------------------------------------------- /Documentation/slate/index.html: -------------------------------------------------------------------------------- 1 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/AIXMLSerialization/AIXMLDocumentSerialize.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSXMLDocument+Serialize.h 3 | // AIXMLSerialize 4 | // 5 | // Created by Justin Palmer on 2/24/09. 6 | // Copyright 2009 LabratRevenge LLC.. All rights reserved. 7 | // 8 | #import 9 | #import "AIXMLSerialization.h" 10 | 11 | 12 | @interface NSXMLDocument (Serialize) 13 | - (NSMutableDictionary *)toDictionary; 14 | @end 15 | -------------------------------------------------------------------------------- /Source/iPhoneSampleApp/iPhoneSampleApp_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'iPhoneSampleApp' target in the 'iPhoneSampleApp' project 3 | // 4 | #import 5 | 6 | #ifndef __IPHONE_3_0 7 | #warning "This project uses features only available in iPhone SDK 3.0 and later." 8 | #endif 9 | 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #endif 15 | -------------------------------------------------------------------------------- /Source/iPhoneSampleApp/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // iPhoneSampleApp 4 | // 5 | // Created by Justin Palmer on 6/24/09. 6 | // Copyright LabratRevenge LLC. 2009. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) { 12 | 13 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 14 | int retVal = UIApplicationMain(argc, argv, nil, nil); 15 | [pool release]; 16 | return retVal; 17 | } 18 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Utilities/HRBase64.h: -------------------------------------------------------------------------------- 1 | // 2 | // HRBase64.h 3 | // HTTPRiot 4 | // 5 | // Created by Justin Palmer on 7/2/09. 6 | // Copyright 2009 LabratRevenge LLC.. All rights reserved. 7 | // 8 | // This was taken from Cyrus' Public Domain implementation on the bottom of 9 | // http://www.cocoadev.com/index.pl?BaseSixtyFour. 10 | // 11 | #import 12 | 13 | 14 | @interface HRBase64 : NSObject { 15 | 16 | } 17 | + (NSString*) encode:(NSData*)rawBytes; 18 | @end 19 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Extensions/NSObject+InvocationUtils.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+InvocationUtils.h 3 | // HTTPRiot 4 | // 5 | // Created by Justin Palmer on 6/25/09. 6 | // Copyright 2009 LabratRevenge LLC.. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface NSObject (InvocationUtils) 13 | - (void)performSelectorOnMainThread:(SEL)selector withObjects:(id)obj1, ...; 14 | - (void)performSelectorOnMainThread:(SEL)selector withObjectArray:(NSArray *)objects; 15 | @end 16 | -------------------------------------------------------------------------------- /Source/iPhoneSampleApp/ISAEditableTextFieldCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // ISAEditableTextFieldCell.h 3 | // HTTPRiot 4 | // 5 | // Created by Justin Palmer on 6/24/09. 6 | // Copyright 2009 LabratRevenge LLC.. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface ISAEditableTextFieldCell : UITableViewCell { 13 | UILabel *_labelField; 14 | UITextField *_valueField; 15 | } 16 | @property (nonatomic, retain) UILabel *labelField; 17 | @property (nonatomic, retain) UITextField *valueField; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /Source/HTTPRiot/HROperationQueue.h: -------------------------------------------------------------------------------- 1 | // 2 | // HROperationQueue.h 3 | // HTTPRiot 4 | // 5 | // Created by Justin Palmer on 7/2/09. 6 | // Copyright 2009 LabratRevenge LLC.. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | /** 13 | * Gives you access to the shared operation queue used to manage all connections. 14 | */ 15 | @interface HROperationQueue : NSOperationQueue { 16 | 17 | } 18 | 19 | /** 20 | * Shared operation queue. 21 | */ 22 | + (HROperationQueue *)sharedOperationQueue; 23 | @end 24 | -------------------------------------------------------------------------------- /Source/iPhoneSampleApp/ISAPeopleTableViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ISAPeopleTableViewController.h 3 | // HTTPRiot 4 | // 5 | // Created by Justin Palmer on 6/24/09. 6 | // Copyright 2009 LabratRevenge LLC.. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface ISAPeopleTableViewController : UITableViewController { 13 | NSMutableArray *_people; 14 | NSIndexPath *_indexPathOfItemToDelete; 15 | BOOL _isDeleting; 16 | } 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Extensions/NSString+EscapingUtils.m: -------------------------------------------------------------------------------- 1 | #import "NSString+EscapingUtils.h" 2 | 3 | @implementation NSString (EscapingUtils) 4 | - (NSString *)stringByPreparingForURL { 5 | NSString *escapedString = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, 6 | (CFStringRef)self, 7 | NULL, 8 | (CFStringRef)@":/?=,!$&'()*+;[]@#", 9 | CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding)); 10 | 11 | return [escapedString autorelease]; 12 | } 13 | @end 14 | -------------------------------------------------------------------------------- /Source/iPhoneSampleApp/iPhoneSampleAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // iPhoneSampleAppDelegate.h 3 | // iPhoneSampleApp 4 | // 5 | // Created by Justin Palmer on 6/24/09. 6 | // Copyright LabratRevenge LLC. 2009. All rights reserved. 7 | // 8 | 9 | @interface iPhoneSampleAppDelegate : NSObject { 10 | 11 | UIWindow *window; 12 | UINavigationController *navigationController; 13 | } 14 | 15 | @property (nonatomic, retain) IBOutlet UIWindow *window; 16 | @property (nonatomic, retain) IBOutlet UINavigationController *navigationController; 17 | 18 | @end 19 | 20 | -------------------------------------------------------------------------------- /Source/iPhoneSampleApp/ISAAlertHelper.m: -------------------------------------------------------------------------------- 1 | // 2 | // ISAAlertHelper.m 3 | // HTTPRiot 4 | // 5 | // Created by Justin Palmer on 6/25/09. 6 | // Copyright 2009 LabratRevenge LLC.. All rights reserved. 7 | // 8 | 9 | 10 | void ISAAlertWithMessage(NSString *message) 11 | { 12 | /* open an alert with an OK button */ 13 | UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"iPhone Sample App" 14 | message:message 15 | delegate:nil 16 | cancelButtonTitle:@"OK" 17 | otherButtonTitles: nil]; 18 | [alert show]; 19 | [alert release]; 20 | } -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/AIXMLSerialization/AIXMLDocumentSerialize.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSXMLDocument+Serialize.m 3 | // AIXMLSerialize 4 | // 5 | // Created by Justin Palmer on 2/24/09. 6 | // Copyright 2009 LabratRevenge LLC.. All rights reserved. 7 | // 8 | 9 | #import "AIXMLDocumentSerialize.h" 10 | #import "AIXMLElementSerialize.h" 11 | 12 | @implementation NSXMLDocument (Serialize) 13 | /** 14 | * Convert NSXMLDocument to an NSDictionary 15 | * @see NSXMLElement#toDictionary 16 | */ 17 | - (NSMutableDictionary *)toDictionary 18 | { 19 | return [[self rootElement] toDictionary]; 20 | } 21 | @end 22 | -------------------------------------------------------------------------------- /Source/Tests/HRUtilitiesTest.m: -------------------------------------------------------------------------------- 1 | // 2 | // HRUtilitiesTest.m 3 | // HTTPRiot 4 | // 5 | // Created by Justin Palmer on 7/22/09. 6 | // Copyright 2009 LabratRevenge LLC.. All rights reserved. 7 | // 8 | 9 | #import "HTTPRiotTestHelper.h" 10 | #import 11 | 12 | @interface HRUtilitiesTest : GHTestCase {} @end 13 | 14 | @implementation HRUtilitiesTest 15 | - (void)testShouldProperlyEncodeWithBase64 { 16 | NSData *data = [@"encytemedia@gmail.com:foobar" dataUsingEncoding:NSUTF8StringEncoding]; 17 | GHAssertEqualStrings([HRBase64 encode:data], @"ZW5jeXRlbWVkaWFAZ21haWwuY29tOmZvb2Jhcg==", nil); 18 | } 19 | @end 20 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/KissXML/NSStringAdditions.m: -------------------------------------------------------------------------------- 1 | #import "NSStringAdditions.h" 2 | 3 | 4 | @implementation NSString (NSStringAdditions) 5 | 6 | - (const xmlChar *)xmlChar 7 | { 8 | return (const xmlChar *)[self UTF8String]; 9 | } 10 | 11 | #ifdef GNUSTEP 12 | - (NSString *)stringByTrimming 13 | { 14 | return [self stringByTrimmingSpaces]; 15 | } 16 | #else 17 | - (NSString *)stringByTrimming 18 | { 19 | NSMutableString *mStr = [self mutableCopy]; 20 | CFStringTrimWhitespace((CFMutableStringRef)mStr); 21 | 22 | NSString *result = [mStr copy]; 23 | 24 | [mStr release]; 25 | return [result autorelease]; 26 | } 27 | #endif 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: http://rubygems.org/ 3 | specs: 4 | blockenspiel (0.4.1) 5 | builder (3.0.0) 6 | faker (0.9.5) 7 | i18n (~> 0.4) 8 | i18n (0.5.0) 9 | json (1.5.1) 10 | plist (3.1.0) 11 | rack (1.2.1) 12 | rake (0.8.7) 13 | sequel (3.20.0) 14 | sinatra (1.1.2) 15 | rack (~> 1.1) 16 | tilt (~> 1.2) 17 | sqlite3 (1.3.3) 18 | tilt (1.2.2) 19 | versionomy (0.4.0) 20 | blockenspiel (>= 0.3.1) 21 | 22 | PLATFORMS 23 | ruby 24 | 25 | DEPENDENCIES 26 | builder 27 | faker 28 | json 29 | plist 30 | rake 31 | sequel 32 | sinatra 33 | sqlite3 34 | versionomy 35 | -------------------------------------------------------------------------------- /Source/iPhoneSampleApp/ISAPeopleDetailController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ISAPeopleDetailController.h 3 | // HTTPRiot 4 | // 5 | // Created by Justin Palmer on 6/24/09. 6 | // Copyright 2009 LabratRevenge LLC.. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface ISAPeopleDetailController : UITableViewController { 13 | NSDictionary *_person; 14 | UIBarButtonItem *_saveButton; 15 | } 16 | 17 | @property (nonatomic, retain) NSDictionary *person; 18 | 19 | - (void)prepareCell:(UITableViewCell *)cell forIndexPath:(NSIndexPath *)ipath; 20 | @end 21 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/gh-unit-iphone/Makefile: -------------------------------------------------------------------------------- 1 | 2 | 3 | default: 4 | xcodebuild -target "CombineLibs (3.0)" -configuration Release build 5 | 6 | 4_0: 7 | xcodebuild -target "GHUnitIPhone (Simulator-4.0)" -configuration Release build 8 | xcodebuild -target "GHUnitIPhone (Device-4.0)" -configuration Release build 9 | BUILD_DIR="build" BUILD_STYLE="Release" FLAVOR="4_0" GHUNIT_VERSION="0.4.22" sh ../Scripts/CombineLibs.sh 10 | 11 | # If you need to clean a specific target/configuration: $(COMMAND) -target $(TARGET) -configuration DebugOrRelease -sdk $(SDK) clean 12 | clean: 13 | -rm -rf build/* 14 | 15 | test: 16 | GHUNIT_CLI=1 xcodebuild -target Tests -configuration Debug -sdk iphonesimulator3.0 build 17 | -------------------------------------------------------------------------------- /Source/HTTPRiot/HROperationQueue.m: -------------------------------------------------------------------------------- 1 | // 2 | // HROperationQueue.m 3 | // HTTPRiot 4 | // 5 | // Created by Justin Palmer on 7/2/09. 6 | // Copyright 2009 LabratRevenge LLC.. All rights reserved. 7 | // 8 | 9 | #import "HROperationQueue.h" 10 | #import "HRGlobal.h" 11 | 12 | static HROperationQueue *sharedOperationQueue = nil; 13 | 14 | 15 | @implementation HROperationQueue 16 | + (HROperationQueue *)sharedOperationQueue { 17 | @synchronized(self) { 18 | if (sharedOperationQueue == nil) { 19 | sharedOperationQueue = [[HROperationQueue alloc] init]; 20 | sharedOperationQueue.maxConcurrentOperationCount = 3; 21 | } 22 | } 23 | 24 | return sharedOperationQueue; 25 | } 26 | @end 27 | -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | = v0.6.8 2010-01-09 2 | * Updates KissXML. Fixes possible app store rejection due to isa-swizzling. 3 | * XML parsing speedups (side effect of KissXML upgrade) 4 | 5 | = v0.6.7 2009-12-22 6 | * Support for 3.1.2 7 | * Fix documentation errors 8 | * Fix error domain 9 | * Update GHUnit to latest 10 | * Optimize response handling to use built in status code strings 11 | 12 | = v0.6.6 2009-09-30 13 | * Fix NSXML compilation errors on some 3.1 devices 14 | 15 | = v0.6.5 2009-09-27 16 | * Support for iPhone OS 3.1 17 | * Support for array parameters 18 | * Attempt to use ASCII encoding if UTF8 fails 19 | * Upgrade to the latest json-framework 20 | * Fixes a typo which caused a crash when setting http headers -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/KissXML/DDXMLElementAdditions.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import "DDXML.h" 3 | 4 | // These methods are not part of the standard NSXML API. 5 | // But any developer working extensively with XML will likely appreciate them. 6 | 7 | @interface DDXMLElement (DDAdditions) 8 | 9 | + (DDXMLElement *)elementWithName:(NSString *)name xmlns:(NSString *)ns; 10 | 11 | - (DDXMLElement *)elementForName:(NSString *)name; 12 | - (DDXMLElement *)elementForName:(NSString *)name xmlns:(NSString *)xmlns; 13 | 14 | - (NSString *)xmlns; 15 | - (void)setXmlns:(NSString *)ns; 16 | 17 | - (void)addAttributeWithName:(NSString *)name stringValue:(NSString *)string; 18 | 19 | - (NSDictionary *)attributesAsDictionary; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /Resources/iPhoneUnitTestsRunner-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | com.yourcompany.${PRODUCT_NAME:identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | APPL 15 | CFBundleSignature 16 | ???? 17 | CFBundleVersion 18 | 1 19 | 20 | 21 | -------------------------------------------------------------------------------- /Source/HTTPRiot/HRGlobal.m: -------------------------------------------------------------------------------- 1 | // 2 | // HRGlobal.m 3 | // HTTPRiot 4 | // 5 | // Created by Justin Palmer on 8/11/09. 6 | // Copyright 2009 LabratRevenge LLC.. All rights reserved. 7 | // 8 | 9 | #import "HRGlobal.h" 10 | 11 | NSString *kHRClassAttributesDelegateKey = @"delegate"; 12 | NSString *kHRClassAttributesBaseURLKey = @"baseURL"; 13 | NSString *kHRClassAttributesHeadersKey = @"headers"; 14 | NSString *kHRClassAttributesBasicAuthKey = @"basicAuth"; 15 | NSString *kHRClassAttributesUsernameKey = @"username"; 16 | NSString *kHRClassAttributesPasswordKey = @"password"; 17 | NSString *kHRClassAttributesFormatKey = @"format"; 18 | NSString *kHRClassAttributesDefaultParamsKey = @"defaultParams"; 19 | NSString *kHRClassAttributesParamsKey = @"params"; 20 | NSString *kHRClassAttributesBodyKey = @"body"; -------------------------------------------------------------------------------- /Source/HTTPRiot/Formatters/HRFormatterFactory.h: -------------------------------------------------------------------------------- 1 | // 2 | // HRFormatterFactory.h 3 | // HTTPRiot 4 | // 5 | // Created by Ognen Ivanovski on 10-12-27. 6 | // Copyright 2010 Netcetera Skopje. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "HRFormatterProtocol.h" 11 | /** 12 | * A class in charge of registering formatters and returning them when necessary 13 | */ 14 | @interface HRFormatterFactory : NSObject { 15 | 16 | } 17 | 18 | /** 19 | * Registers a new formatter for the provided format identifier 20 | * @param formatter the formatter 21 | * @param format format code 22 | */ 23 | + (void)registerFormatter:(id )formatter forFormat:(NSUInteger)format; 24 | 25 | /** 26 | * Returns the formatter for the specified format 27 | */ 28 | + (id ) formatterForFormat:(NSUInteger)format; 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /Resources/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleName 10 | ${PRODUCT_NAME} 11 | CFBundleIconFile 12 | 13 | CFBundleIdentifier 14 | com.labratrevenge.${PRODUCT_NAME:identifier} 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundlePackageType 18 | FMWK 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 0.6.0 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/JSON/CREDITS: -------------------------------------------------------------------------------- 1 | Blake Seely 2 | A lot of the inspiration to early versions of this framework 3 | came from Blake's BSJSONAdditions project. 4 | 5 | Marc Lehmann 6 | Part of the inspiration for my JSON work has been from Marc's 7 | JSON::XS Perl module. I also adopted the way he organised the 8 | tests. Having a separate fixture for testing error conditions 9 | makes a lot of sense. 10 | 11 | Jens Alfke - http://mooseyard.com/Jens 12 | Jens emailed me out of the blue one day with a couple of patches 13 | that gave a speedup of 11x for generation and 5x for parsing of 14 | the long (12k) JSON string I've been using for testing. 15 | 16 | Greg Bolsinga 17 | Provided patches for dropping the dependency on AppKit and thus 18 | truly making this a Foundation framework, and for building a 19 | static library suitable for use with the iPhone. 20 | -------------------------------------------------------------------------------- /Source/Tests/HTTPRiotTestHelper.h: -------------------------------------------------------------------------------- 1 | // 2 | // HTTPRiotTestHelper.h 3 | // HTTPRiot 4 | // 5 | // Created by Justin Palmer on 2/11/09. 6 | // Copyright 2009 Alternateidea. All rights reserved. 7 | // 8 | 9 | 10 | #import 11 | 12 | #if !TARGET_IPHONE_SIMULATOR 13 | #import 14 | #else 15 | #import "GHUnit.h" 16 | #endif 17 | 18 | 19 | // Get the compiler to STFU when testing private methods 20 | @interface HRRestModel (STFU) 21 | + (void)setAttributeValue:(id)attr forKey:(NSString *)key; 22 | + (NSMutableDictionary *)classAttributes; 23 | + (NSMutableDictionary *)mergedOptions:(NSDictionary *)options; 24 | @end 25 | 26 | #define HTTPRiotTestServer @"http://localhost:4567" 27 | 28 | @interface HRTestPerson : HRRestModel {} @end 29 | @interface HRTestPerson2 : HRRestModel {} @end 30 | @interface HRTestPerson3 : HRRestModel {} @end 31 | @interface HRTestPerson4 : HRRestModel {} @end 32 | @interface HRTestPerson5 : HRRestModel {} @end 33 | @interface HRTestPerson6 : HRRestModel {} @end 34 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Extensions/NSDictionary+ParamUtils.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSDictionary+Misc.m 3 | // Legislate 4 | // 5 | // Created by Justin Palmer on 7/24/08. 6 | // Copyright 2008 Active Reload, LLC. All rights reserved. 7 | // 8 | 9 | #import "NSDictionary+ParamUtils.h" 10 | #import "NSString+EscapingUtils.h" 11 | 12 | @implementation NSDictionary (ParamUtils) 13 | 14 | 15 | 16 | - (NSString *)toQueryString { 17 | NSMutableArray *pairs = [[[NSMutableArray alloc] init] autorelease]; 18 | for (id key in [self allKeys]) { 19 | id value = [self objectForKey:key]; 20 | if ([value isKindOfClass:[NSArray class]]) { 21 | for (id val in value) { 22 | [pairs addObject:[NSString stringWithFormat:@"%@=%@",key, [val stringByPreparingForURL]]]; 23 | } 24 | } else { 25 | [pairs addObject:[NSString stringWithFormat:@"%@=%@",key, [value stringByPreparingForURL]]]; 26 | } 27 | } 28 | return [pairs componentsJoinedByString:@"&"]; 29 | } 30 | @end 31 | -------------------------------------------------------------------------------- /Resources/iPhoneSampleApp-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIconFile 12 | 13 | CFBundleIdentifier 14 | com.labratrevenge.${PRODUCT_NAME:rfc1034identifier} 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleName 18 | ${PRODUCT_NAME} 19 | CFBundlePackageType 20 | APPL 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSRequiresIPhoneOS 26 | 27 | NSMainNibFile 28 | MainWindow 29 | 30 | 31 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Formatters/HRFormatXML.m: -------------------------------------------------------------------------------- 1 | // 2 | // HTTPRiotFormatXML.m 3 | // HTTPRiot 4 | // 5 | // Created by Justin Palmer on 2/8/09. 6 | // Copyright 2009 Alternateidea. All rights reserved. 7 | // 8 | 9 | #import "HRFormatXML.h" 10 | #import "AIXMLSerialization.h" 11 | 12 | @implementation HRFormatXML 13 | - (NSString *)extension { 14 | return @"xml"; 15 | } 16 | 17 | - (NSString *)mimeType { 18 | return @"application/xml"; 19 | } 20 | 21 | - (id)decode:(NSData *)data error:(NSError **)error { 22 | NSError *parseError = nil; 23 | NSXMLDocument *doc = [[[NSXMLDocument alloc] initWithData:data options:NSXMLDocumentTidyXML error:&parseError] autorelease]; 24 | 25 | if(parseError != nil) { 26 | if(error != nil) 27 | *error = parseError; 28 | 29 | return nil; 30 | } 31 | 32 | return [doc toDictionary]; 33 | } 34 | 35 | - (NSString *)encode:(id)data error:(NSError **)error { 36 | NSAssert(true, @"XML Encoding is not supported. Currently accepting patches"); 37 | return nil; 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /Resources/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 Justin Palmer 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /Source/Tests/HTTPRiotTestHelper.m: -------------------------------------------------------------------------------- 1 | // 2 | // HTTPRiotTestHelper.m 3 | // HTTPRiot 4 | // 5 | // Created by Justin Palmer on 2/11/09. 6 | // Copyright 2009 Alternateidea. All rights reserved. 7 | // 8 | 9 | #import "HTTPRiotTestHelper.h" 10 | 11 | @implementation HRTestPerson 12 | + (void)initialize { 13 | [self setBaseURL:[NSURL URLWithString:HTTPRiotTestServer]]; 14 | [self setBasicAuthWithUsername:@"username@email.com" password:@"test"]; 15 | } 16 | @end 17 | 18 | @implementation HRTestPerson2 19 | + (void)initialize { 20 | [self setBaseURL:[NSURL URLWithString:HTTPRiotTestServer]]; 21 | } 22 | @end 23 | 24 | @implementation HRTestPerson3 25 | + (void)initialize { 26 | [self setBaseURL:[NSURL URLWithString:HTTPRiotTestServer]]; 27 | NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:@"bar", @"foo", @"bing", @"bada", nil]; 28 | [self setHeaders:params]; 29 | [self setDefaultParams:params]; 30 | } 31 | @end 32 | 33 | @implementation HRTestPerson4 34 | + (void)initialize { 35 | [self setBaseURL:[NSURL URLWithString:HTTPRiotTestServer]]; 36 | [self setFormat:HRDataFormatXML]; 37 | } 38 | @end 39 | 40 | @implementation HRTestPerson5 @end 41 | @implementation HRTestPerson6 @end 42 | 43 | -------------------------------------------------------------------------------- /Source/Tests/Server/views/people.erb: -------------------------------------------------------------------------------- 1 |

People

2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | <% @people.each do |person| %> 14 | 15 | 16 | 17 | 18 | 19 | 24 | 25 | <% end %> 26 | 27 | 37 | 38 | 39 |
NameEmailPhoneAddressDelete
<%= person[:name] %><%= person[:email] %><%= person[:telephone] %><%= person[:address] %> 20 |
21 | 22 |
23 |
28 |
29 | 30 | 31 | 32 | 33 | 34 | 35 |
36 |
-------------------------------------------------------------------------------- /Source/iPhoneSampleApp/iPhoneSampleAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // iPhoneSampleAppAppDelegate.m 3 | // iPhoneSampleApp 4 | // 5 | // Created by Justin Palmer on 6/24/09. 6 | // Copyright LabratRevenge LLC. 2009. All rights reserved. 7 | // 8 | 9 | #import "iPhoneSampleAppDelegate.h" 10 | #import "ISAPeopleTableViewController.h" 11 | #import 12 | 13 | @implementation iPhoneSampleAppDelegate 14 | 15 | @synthesize window; 16 | @synthesize navigationController; 17 | 18 | 19 | #pragma mark - 20 | #pragma mark Application lifecycle 21 | - (void)applicationDidFinishLaunching:(UIApplication *)application { 22 | ISAPeopleTableViewController *peopleController = [[[ISAPeopleTableViewController alloc] init] autorelease]; 23 | navigationController.viewControllers = [NSArray arrayWithObjects:peopleController, nil]; 24 | [HRRestModel setBaseURL:[NSURL URLWithString:@"http://localhost:4567"]]; 25 | 26 | [window addSubview:[navigationController view]]; 27 | [window makeKeyAndVisible]; 28 | } 29 | 30 | - (void)applicationWillTerminate:(UIApplication *)application { 31 | // Save data if appropriate 32 | } 33 | 34 | #pragma mark - 35 | #pragma mark Memory management 36 | 37 | - (void)dealloc { 38 | [navigationController release]; 39 | [window release]; 40 | [super dealloc]; 41 | } 42 | 43 | 44 | @end 45 | 46 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Formatters/HRFormatJSON.m: -------------------------------------------------------------------------------- 1 | // 2 | // HRFormatJSON.m 3 | // HTTPRiot 4 | // 5 | // Created by Justin Palmer on 2/8/09. 6 | // Copyright 2009 Alternateidea. All rights reserved. 7 | // 8 | 9 | #import "HRFormatJSON.h" 10 | #import "JSON.h" 11 | 12 | @implementation HRFormatJSON 13 | - (NSString *)extension { 14 | return @"json"; 15 | } 16 | 17 | - (NSString *)mimeType { 18 | return @"application/json"; 19 | } 20 | 21 | - (id)decode:(NSData *)data error:(NSError **)error { 22 | NSString *rawString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 23 | // If we failed to decode the data using UTF8 attempt to use ASCII encoding. 24 | if(rawString == nil && ([data length] > 0)) { 25 | rawString = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; 26 | } 27 | 28 | NSError *parseError = nil; 29 | SBJSON *parser = [[SBJSON alloc] init]; 30 | id results = [parser objectWithString:rawString error:&parseError]; 31 | [parser release]; 32 | [rawString release]; 33 | 34 | if(parseError && !results) { 35 | if(error != nil) 36 | *error = parseError; 37 | return nil; 38 | } 39 | 40 | return results; 41 | } 42 | 43 | - (NSString *)encode:(id)data error:(NSError **)error { 44 | return [data JSONRepresentation]; 45 | } 46 | @end 47 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Formatters/HRFormatterProtocol.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file HRFormatterProtocol.h Protocol for the formatters. 3 | */ 4 | 5 | // 6 | // HRFormatterProtocol.h 7 | // HTTPRiot 8 | // 9 | // Created by Justin Palmer on 2/8/09. 10 | // Copyright 2009 Alternateidea. All rights reserved. 11 | // 12 | #import 13 | 14 | /** 15 | * @protocol HRFormatterProtocol 16 | * 17 | * Formatters used in formatting response data 18 | * Formatters should be able to encode and decode a specific data type. 19 | */ 20 | @protocol HRFormatterProtocol 21 | 22 | /** 23 | * The file extension. Example: json, xml, plist, n3, etc. 24 | */ 25 | - (NSString *)extension; 26 | 27 | /** 28 | * The mime-type represented by this formatter 29 | */ 30 | - (NSString *)mimeType; 31 | 32 | /** 33 | * Takes the format and turns it into the appropriate Obj-C data type. 34 | * 35 | * @param data Raw data to be decoded. 36 | * @param error Returns any errors that happened while decoding. 37 | */ 38 | - (id)decode:(NSData *)data error:(NSError **)error; 39 | 40 | /** 41 | * Takes an Obj-C data type and turns it into the proper format. 42 | * 43 | * @param object The Obj-C object to be encoded by the formatter. 44 | * @param error Returns any errors that happened while encoding. 45 | */ 46 | - (NSString *)encode:(id)object error:(NSError **)error; 47 | @end 48 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/gh-unit-iphone/GHTestGroup+JUnitXML.h: -------------------------------------------------------------------------------- 1 | // 2 | // GHTestGroup+JUnitXML.h 3 | // GHUnit 4 | // 5 | // Created by Gabriel Handford on 6/4/10. 6 | // Copyright 2010. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import "GHTestGroup.h" 31 | 32 | @interface GHTestGroup (JUnitXML) 33 | 34 | - (NSString *)JUnitXML; 35 | 36 | - (BOOL)writeJUnitXMLAtPath:(NSString *)documentsPath error:(NSError **)error; 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/gh-unit-iphone/GHUnitIPhoneAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // GHUnitIPhoneAppDelegate.h 3 | // GHUnitIPhone 4 | // 5 | // Created by Gabriel Handford on 1/25/09. 6 | // Copyright 2009. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import 31 | 32 | @interface GHUnitIPhoneAppDelegate : NSObject { 33 | UIWindow *window_; 34 | 35 | UINavigationController *navigationController_; 36 | } 37 | 38 | @end 39 | 40 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/gh-unit-iphone/GHTest+JUnitXML.h: -------------------------------------------------------------------------------- 1 | // 2 | // GHTest+JUnitXML.h 3 | // GHUnit 4 | // 5 | // Created by Gabriel Handford on 6/4/10. 6 | // Copyright 2010. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import "GHTest.h" 31 | 32 | @interface GHTest (JUnitXML) 33 | 34 | /*! 35 | Return test results in JUnit XML format for external parsing use 36 | (such as a Continuous Integration system like Hudson) 37 | */ 38 | - (NSString *)JUnitXML; 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Extensions/NSObject+InvocationUtils.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+InvocationUtils.m 3 | // HTTPRiot 4 | // 5 | // Created by Justin Palmer on 6/25/09. 6 | // Copyright 2009 LabratRevenge LLC.. All rights reserved. 7 | // 8 | 9 | #import "NSObject+InvocationUtils.h" 10 | 11 | 12 | @implementation NSObject (InvocationUtils) 13 | - (void)performSelectorOnMainThread:(SEL)selector withObjects:(id)obj1, ... { 14 | id argitem; va_list args; 15 | NSMutableArray *objects = [[NSMutableArray alloc] init]; 16 | if(obj1 != nil) { 17 | [objects addObject:obj1]; 18 | va_start(args, obj1); 19 | 20 | while (argitem = va_arg(args, id)) { 21 | [objects addObject:argitem]; 22 | } 23 | 24 | va_end(args); 25 | } 26 | 27 | [self performSelectorOnMainThread:selector withObjectArray:objects]; 28 | [objects release]; 29 | } 30 | 31 | - (void)performSelectorOnMainThread:(SEL)selector withObjectArray:(NSArray *)objects { 32 | NSMethodSignature *signature = [self methodSignatureForSelector:selector]; 33 | if(signature) { 34 | NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature]; 35 | [invocation setTarget:self]; 36 | [invocation setSelector:selector]; 37 | 38 | for(size_t i = 0; i < objects.count; ++i) { 39 | id obj = [objects objectAtIndex:i]; 40 | [invocation setArgument:&obj atIndex:(i + 2)]; 41 | } 42 | 43 | [invocation performSelectorOnMainThread:@selector(invoke) withObject:nil waitUntilDone:YES]; 44 | } 45 | } 46 | @end 47 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Formatters/HRFormatterFactory.m: -------------------------------------------------------------------------------- 1 | // 2 | // HRFormatterFactory.m 3 | // HTTPRiot 4 | // 5 | // Created by Ognen Ivanovski on 10-12-27. 6 | // Copyright 2010 Netcetera Skopje. All rights reserved. 7 | // 8 | 9 | #import "HRGlobal.h" 10 | #import "HRFormatterFactory.h" 11 | #import "HRFormatJSON.h" 12 | #import "HRFormatXML.h" 13 | 14 | @implementation HRFormatterFactory 15 | 16 | static NSMutableDictionary *registry = nil; 17 | 18 | + (NSMutableDictionary *)formatters 19 | { 20 | if (registry == nil) { 21 | registry = [[NSMutableDictionary alloc] initWithObjectsAndKeys: 22 | [[[HRFormatJSON alloc] init] autorelease], [NSNumber numberWithInteger:HRDataFormatJSON], 23 | [[[HRFormatXML alloc] init] autorelease], [NSNumber numberWithInteger:HRDataFormatXML], 24 | nil]; 25 | } 26 | 27 | return registry; 28 | } 29 | 30 | 31 | + (void)registerFormatter:(id )formatter forFormat:(NSUInteger)format 32 | { 33 | [[self formatters] setObject:formatter forKey:[NSNumber numberWithInteger:format]]; 34 | } 35 | 36 | + (id ) formatterForFormat:(NSUInteger)format 37 | { 38 | id result = [[self formatters] objectForKey:[NSNumber numberWithInteger:format]]; 39 | 40 | if (!result) { 41 | [NSException raise:NSInvalidArgumentException 42 | format:@"There is no formatter for the specified format identifier registered"]; 43 | } 44 | 45 | return result; 46 | } 47 | 48 | + (void)resetRegistry 49 | { 50 | [registry release]; 51 | registry = nil; 52 | } 53 | @end 54 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/gh-unit-iphone/GHTestOperation.h: -------------------------------------------------------------------------------- 1 | // 2 | // GHTestOperation.h 3 | // GHUnit 4 | // 5 | // Created by Gabriel Handford on 6/4/10. 6 | // Copyright 2010. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import "GHTest.h" 31 | 32 | /*! 33 | Test for running in the context of an NSOperationQueue. 34 | */ 35 | @interface GHTestOperation : NSOperation { 36 | id test_; 37 | GHTestOptions options_; 38 | } 39 | 40 | - (id)initWithTest:(id)test options:(GHTestOptions)options; 41 | 42 | @end -------------------------------------------------------------------------------- /Source/iPhoneSampleApp/ISAEditableTextFieldCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // ISAEditableTextField.m 3 | // HTTPRiot 4 | // 5 | // Created by Justin Palmer on 6/24/09. 6 | // Copyright 2009 LabratRevenge LLC.. All rights reserved. 7 | // 8 | 9 | #import "ISAEditableTextFieldCell.h" 10 | 11 | 12 | @implementation ISAEditableTextFieldCell 13 | @synthesize labelField = _labelField; 14 | @synthesize valueField = _valueField; 15 | 16 | - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { 17 | if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { 18 | _labelField = [[UILabel alloc] init]; 19 | _labelField.font = [UIFont boldSystemFontOfSize:12.0]; 20 | _labelField.textAlignment = UITextAlignmentRight; 21 | _labelField.textColor = [UIColor grayColor]; 22 | 23 | _valueField = [[UITextField alloc] init]; 24 | _valueField.font = [UIFont systemFontOfSize:14.0]; 25 | _valueField.clearButtonMode = UITextFieldViewModeWhileEditing; 26 | _valueField.keyboardType = UIKeyboardTypeAlphabet; 27 | _valueField.returnKeyType = UIReturnKeyDone; 28 | 29 | [self.contentView addSubview:_labelField]; 30 | [self.contentView addSubview:_valueField]; 31 | 32 | } 33 | return self; 34 | } 35 | 36 | - (void)layoutSubviews 37 | { 38 | CGRect rect = self.contentView.frame; 39 | _labelField.frame = CGRectMake(rect.origin.x + 20, rect.origin.y + 10,70,20); 40 | _valueField.frame = CGRectMake(100,rect.origin.y + 10,200,20); 41 | } 42 | 43 | 44 | - (void)dealloc { 45 | [_labelField release]; 46 | [_valueField release]; 47 | [super dealloc]; 48 | } 49 | 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/gh-unit-iphone/GHUnit.h: -------------------------------------------------------------------------------- 1 | // 2 | // GHUnit.h 3 | // GHUnit 4 | // 5 | // Created by Gabriel Handford on 1/19/09. 6 | // Copyright 2009. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import "GHTestCase.h" 31 | #import "GHAsyncTestCase.h" 32 | #import "GHTestSuite.h" 33 | #import "GHTestMacros.h" 34 | #import "GHTestRunner.h" 35 | 36 | #ifdef DEBUG 37 | #define GHUDebug(fmt, ...) do { \ 38 | fputs([[[NSString stringWithFormat:fmt, ##__VA_ARGS__] stringByAppendingString:@"\n"] UTF8String], stdout); \ 39 | } while(0) 40 | #else 41 | #define GHUDebug(fmt, ...) do {} while(0) 42 | #endif -------------------------------------------------------------------------------- /Source/HTTPRiot/HRGlobal.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file HRGlobal.h Shared types and constants. 3 | */ 4 | #import 5 | 6 | /// Key for delgate 7 | extern NSString *kHRClassAttributesDelegateKey; 8 | /// Key for base url 9 | extern NSString *kHRClassAttributesBaseURLKey; 10 | /// Key for headers 11 | extern NSString *kHRClassAttributesHeadersKey; 12 | /// Key for basic auth 13 | extern NSString *kHRClassAttributesBasicAuthKey; 14 | /// Key for username 15 | extern NSString *kHRClassAttributesUsernameKey; 16 | /// Key for password 17 | extern NSString *kHRClassAttributesPasswordKey; 18 | /// Key for format 19 | extern NSString *kHRClassAttributesFormatKey; 20 | /// Key for default params 21 | extern NSString *kHRClassAttributesDefaultParamsKey; 22 | /// Key for params 23 | extern NSString *kHRClassAttributesParamsKey; 24 | /// Key for body 25 | extern NSString *kHRClassAttributesBodyKey; 26 | 27 | 28 | /** 29 | * Supported REST methods. 30 | * @see HRRequestOperation 31 | */ 32 | typedef enum { 33 | /// Unknown [NOT USED] 34 | HRRequestMethodUnknown = -1, 35 | /// GET 36 | HRRequestMethodGet, 37 | /// POST 38 | HRRequestMethodPost, 39 | /// PUT 40 | HRRequestMethodPut, 41 | /// DELETE 42 | HRRequestMethodDelete 43 | } HRRequestMethod; 44 | 45 | /** 46 | Default Supported formats. 47 | @see HRRestModel#setFormat 48 | */ 49 | typedef enum { 50 | /// Unknown [NOT USED] 51 | HRDataFormatUnknown = -1, 52 | /// JSON Format 53 | HRDataFormatJSON, 54 | /// XML Format 55 | HRDataFormatXML 56 | } HRDataFormat; 57 | 58 | /// HTTPRiot's error domain 59 | #define HTTPRiotErrorDomain @"com.labratrevenge.HTTPRiot.ErrorDomain" 60 | 61 | #ifdef DEBUG 62 | /// Logging Helper 63 | #define HRLOG NSLog 64 | #else 65 | /// Logging Helper 66 | #define HRLOG 67 | #endif -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/KissXML/DDXMLElement.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import "DDXMLNode.h" 3 | 4 | 5 | @interface DDXMLElement : DDXMLNode 6 | { 7 | } 8 | 9 | - (id)initWithName:(NSString *)name; 10 | - (id)initWithName:(NSString *)name URI:(NSString *)URI; 11 | - (id)initWithName:(NSString *)name stringValue:(NSString *)string; 12 | - (id)initWithXMLString:(NSString *)string error:(NSError **)error; 13 | 14 | #pragma mark --- Elements by name --- 15 | 16 | - (NSArray *)elementsForName:(NSString *)name; 17 | - (NSArray *)elementsForLocalName:(NSString *)localName URI:(NSString *)URI; 18 | 19 | #pragma mark --- Attributes --- 20 | 21 | - (void)addAttribute:(DDXMLNode *)attribute; 22 | - (void)removeAttributeForName:(NSString *)name; 23 | - (void)setAttributes:(NSArray *)attributes; 24 | //- (void)setAttributesAsDictionary:(NSDictionary *)attributes; 25 | - (NSArray *)attributes; 26 | - (DDXMLNode *)attributeForName:(NSString *)name; 27 | //- (DDXMLNode *)attributeForLocalName:(NSString *)localName URI:(NSString *)URI; 28 | 29 | #pragma mark --- Namespaces --- 30 | 31 | - (void)addNamespace:(DDXMLNode *)aNamespace; 32 | - (void)removeNamespaceForPrefix:(NSString *)name; 33 | - (void)setNamespaces:(NSArray *)namespaces; 34 | - (NSArray *)namespaces; 35 | - (DDXMLNode *)namespaceForPrefix:(NSString *)prefix; 36 | - (DDXMLNode *)resolveNamespaceForName:(NSString *)name; 37 | - (NSString *)resolvePrefixForNamespaceURI:(NSString *)namespaceURI; 38 | 39 | #pragma mark --- Children --- 40 | 41 | - (void)insertChild:(DDXMLNode *)child atIndex:(NSUInteger)index; 42 | //- (void)insertChildren:(NSArray *)children atIndex:(NSUInteger)index; 43 | - (void)removeChildAtIndex:(NSUInteger)index; 44 | - (void)setChildren:(NSArray *)children; 45 | - (void)addChild:(DDXMLNode *)child; 46 | //- (void)replaceChildAtIndex:(NSUInteger)index withNode:(DDXMLNode *)node; 47 | //- (void)normalizeAdjacentTextNodesPreservingCDATA:(BOOL)preserve; 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /Source/Tests/HRFormatterFactoryTest.m: -------------------------------------------------------------------------------- 1 | // 2 | // HRFormatterFactoryTest.m 3 | // HTTPRiot 4 | // 5 | // Created by Ognen Ivanovski on 10-12-27. 6 | // Copyright 2010 Netcetera Skopje. All rights reserved. 7 | // 8 | 9 | #import "HTTPRiotTestHelper.h" 10 | #import "HRFormatterFactory.h" 11 | 12 | @interface HRFormatterFactoryTest : GHTestCase { } @end 13 | 14 | @interface HRFormatterFactory(TestHelpers) 15 | + (void)resetRegistry; 16 | @end 17 | 18 | 19 | @interface MockCustomFormatter : NSObject {} @end 20 | 21 | 22 | @implementation HRFormatterFactoryTest 23 | 24 | - (void)setUp 25 | { 26 | [HRFormatterFactory resetRegistry]; 27 | } 28 | 29 | - (void)testShouldReturnDefaultFormatters 30 | { 31 | id json = [HRFormatterFactory formatterForFormat:HRDataFormatJSON]; 32 | id xml = [HRFormatterFactory formatterForFormat:HRDataFormatXML]; 33 | 34 | GHAssertNotNil(json, @"JSON formatter is present"); 35 | GHAssertNotNil(xml, @"XML formatter is present"); 36 | } 37 | 38 | 39 | - (void)testShouldRaiseWhenFormatIsNotRecognized 40 | { 41 | GHAssertThrows([HRFormatterFactory formatterForFormat:66556], 42 | @"Throws when format is not recognized"); 43 | } 44 | 45 | 46 | - (void)testShouldReturnCustomFormatter 47 | { 48 | MockCustomFormatter *formatter = [[MockCustomFormatter alloc] init]; 49 | 50 | [HRFormatterFactory registerFormatter:formatter forFormat:100]; 51 | 52 | GHAssertEquals(formatter, 53 | [HRFormatterFactory formatterForFormat:100], 54 | @"Returns the same registered formatter"); 55 | } 56 | 57 | @end 58 | 59 | 60 | 61 | @implementation MockCustomFormatter 62 | 63 | 64 | - (NSString *)extension { 65 | return @"custom"; 66 | } 67 | 68 | - (NSString *)mimeType { 69 | return @"custommime"; 70 | } 71 | 72 | - (id)decode:(NSData *)data error:(NSError **)error { 73 | return nil; 74 | } 75 | 76 | - (NSString *)encode:(id)object error:(NSError **)error { 77 | return nil; 78 | } 79 | 80 | @end 81 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #HTTPRiot - Easily Consume REST Services 2 | 3 | HTTPRiot is a simple HTTP library that works on the iPhone and Cocoa Apps. It tries to abstract as much as possible 4 | in the beginning. This means you don't spend a lot of time up front setting things up and staying on a golden path, but 5 | this also means it makes no assumptions about the data returned. It will convert JSON and XML automatically to NSDictionary or NSArray objects, 6 | allowing you to do what you want to with the data, but it's up to you to create your own models if you wish. 7 | 8 | It offers a lot of flexibility with the data returned, but the tradeoff is that you must know what to do with 9 | the data returned because if you initiate two requests from one model both will be routed through the same 10 | delegate methods that handle responses/errors/etc. 11 | 12 | ## Documentation and Samples: 13 | 14 | * [Online Documentation](http://labratrevenge.com/httpriot) 15 | * [Support & Community](http://justin.tenderapp.com) 16 | * Sample app and server included with the source 17 | 18 | ## Quick Examples 19 | // GET 20 | [model getPath:@"/foo/bar.json" withOptions:nil object:nil]; 21 | 22 | // POST 23 | NSDictionary *opts = [NSDictionary dictionaryWithObject:[obj JSONRepresentation] forKey:@"body"]; 24 | [model postPath:@"/foo" withOptions:params object:nil]; 25 | 26 | // PUT 27 | NSDictionary *opts = [NSDictionary dictionaryWithObject:[obj JSONRepresentation] forKey:@"body"]; 28 | [model putPath:@"/foo/1" withOptions:params object:nil]; 29 | 30 | // DELETE 31 | [model deletePath:@"/foo/1" withOptions:nil object:nil]; 32 | 33 | ##Similar Projects 34 | HTTPRiot was inspired by the httparty Ruby library. 35 | There are also numerous other HTTP libraries for Cocoa: 36 | 37 | * [ASIHTTPRequest](http://github.com/pokeb/asi-http-request/tree/master) 38 | * [Three20's TTURLRequest](http://github.com/joehewitt/three20/tree/master) 39 | * [ObjectiveResource](http://github.com/yfactorial/objectiveresource/tree/master) 40 | -------------------------------------------------------------------------------- /Source/Tests/HRExtensionsTest.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSStringURLTest.m 3 | // HTTPRiot 4 | // 5 | // Created by Justin Palmer on 7/8/09. 6 | // Copyright 2009 LabratRevenge LLC.. All rights reserved. 7 | // 8 | 9 | #import "HTTPRiotTestHelper.h" 10 | #import "HTTPRiot/NSString+EscapingUtils.h" 11 | #import "NSDictionary+ParamUtils.h" 12 | 13 | @interface HRExtensionsTest : GHTestCase {} @end 14 | 15 | @implementation HRExtensionsTest 16 | - (void)testShouldEscapeQueryValues { 17 | GHAssertEqualStrings([@"foo bar" stringByPreparingForURL], @"foo%20bar", nil); 18 | GHAssertEqualStrings([@"foo+bar" stringByPreparingForURL], @"foo%2Bbar", nil); 19 | GHAssertEqualStrings([@"._-~" stringByPreparingForURL], @"._-~", nil); 20 | GHAssertEqualStrings([@"&=" stringByPreparingForURL], @"%26%3D", nil); 21 | } 22 | 23 | - (void)testShouldBuildQueryStringFromDictionary { 24 | NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:@"Owyn", @"firstname", @"Lyons", @"lastname", nil]; 25 | GHAssertEqualStrings([params toQueryString], @"firstname=Owyn&lastname=Lyons", nil); 26 | } 27 | 28 | - (void)testShouldBuildQueryStringWithDuplicateKeysIfParamHasNestedArray { 29 | NSArray *characters = [NSArray arrayWithObjects:@"Fawkes", @"dogmeat", nil]; 30 | NSDictionary *params = [NSDictionary dictionaryWithObject:characters forKey:@"character"]; 31 | GHAssertEqualStrings([params toQueryString], @"character=Fawkes&character=dogmeat", nil); 32 | 33 | NSArray *moreCharacters = [NSArray arrayWithObjects:@"Clover", @"Jericho", nil]; 34 | NSDictionary *params2 = [NSDictionary dictionaryWithObjectsAndKeys:characters, @"character", moreCharacters, @"more", nil]; 35 | GHAssertEqualStrings([params2 toQueryString], @"more=Clover&more=Jericho&character=Fawkes&character=dogmeat", nil); 36 | 37 | NSDictionary *params3 = [NSDictionary dictionaryWithObjectsAndKeys:characters, @"character", @"Lone Wanderer", @"accompanies", nil]; 38 | GHAssertEqualStrings([params3 toQueryString], @"accompanies=Lone%20Wanderer&character=Fawkes&character=dogmeat", nil); 39 | } 40 | @end 41 | -------------------------------------------------------------------------------- /Source/Tests/Server/lib/authorization.rb: -------------------------------------------------------------------------------- 1 | # See http://github.com/foca/sinatra-ditties/tree/master 2 | # Released under an MIT License 3 | module Sinatra 4 | # HTTP Authorization helpers for Sinatra. 5 | # 6 | # In your helpers module, include Sinatra::Authorization and then define 7 | # an #authorize(user, password) method to handle user provided 8 | # credentials. 9 | # 10 | # Inside your events, call #login_required to trigger the HTTP 11 | # Authorization window to pop up in the browser. 12 | # 13 | # Code adapted from {Ryan Tomayko}[http://tomayko.com/about] and 14 | # {Christopher Schneid}[http://gittr.com], shared under an MIT License 15 | module Authorization 16 | # Redefine this method on your helpers block to actually contain 17 | # your authorization logic. 18 | def authorize(username, password) 19 | false 20 | end 21 | 22 | # From you app, call set :authorization_realm, "my app" to set this 23 | # or define a #authorization_realm method in your helpers block. 24 | def authorization_realm 25 | Sinatra::Default.authorization_realm 26 | end 27 | 28 | # Call in any event that requires authentication 29 | def login_required 30 | return if authorized? 31 | unauthorized! unless auth.provided? 32 | bad_request! unless auth.basic? 33 | unauthorized! unless authorize(*auth.credentials) 34 | request.env['REMOTE_USER'] = auth.username 35 | end 36 | 37 | # Convenience method to determine if a user is logged in 38 | def authorized? 39 | !!request.env['REMOTE_USER'] 40 | end 41 | alias :logged_in? :authorized? 42 | 43 | # Name provided by the current user to log in 44 | def current_user 45 | request.env['REMOTE_USER'] 46 | end 47 | 48 | private 49 | def auth 50 | @auth ||= Rack::Auth::Basic::Request.new(request.env) 51 | end 52 | 53 | def unauthorized!(realm=authorization_realm) 54 | response["WWW-Authenticate"] = %(Basic realm="#{realm}") 55 | throw :halt, [ 401, 'Authorization Required' ] 56 | end 57 | 58 | def bad_request! 59 | throw :halt, [ 400, 'Bad Request' ] 60 | end 61 | end 62 | end 63 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/KissXML/DDXMLDocument.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import "DDXMLElement.h" 3 | #import "DDXMLNode.h" 4 | 5 | 6 | enum { 7 | DDXMLDocumentXMLKind = 0, 8 | DDXMLDocumentXHTMLKind, 9 | DDXMLDocumentHTMLKind, 10 | DDXMLDocumentTextKind 11 | }; 12 | typedef NSUInteger DDXMLDocumentContentKind; 13 | 14 | @interface DDXMLDocument : DDXMLNode 15 | { 16 | } 17 | 18 | - (id)initWithXMLString:(NSString *)string options:(NSUInteger)mask error:(NSError **)error; 19 | //- (id)initWithContentsOfURL:(NSURL *)url options:(NSUInteger)mask error:(NSError **)error; 20 | - (id)initWithData:(NSData *)data options:(NSUInteger)mask error:(NSError **)error; 21 | //- (id)initWithRootElement:(DDXMLElement *)element; 22 | 23 | //+ (Class)replacementClassForClass:(Class)cls; 24 | 25 | //- (void)setCharacterEncoding:(NSString *)encoding; //primitive 26 | //- (NSString *)characterEncoding; //primitive 27 | 28 | //- (void)setVersion:(NSString *)version; 29 | //- (NSString *)version; 30 | 31 | //- (void)setStandalone:(BOOL)standalone; 32 | //- (BOOL)isStandalone; 33 | 34 | //- (void)setDocumentContentKind:(DDXMLDocumentContentKind)kind; 35 | //- (DDXMLDocumentContentKind)documentContentKind; 36 | 37 | //- (void)setMIMEType:(NSString *)MIMEType; 38 | //- (NSString *)MIMEType; 39 | 40 | //- (void)setDTD:(DDXMLDTD *)documentTypeDeclaration; 41 | //- (DDXMLDTD *)DTD; 42 | 43 | //- (void)setRootElement:(DDXMLNode *)root; 44 | - (DDXMLElement *)rootElement; 45 | 46 | //- (void)insertChild:(DDXMLNode *)child atIndex:(NSUInteger)index; 47 | 48 | //- (void)insertChildren:(NSArray *)children atIndex:(NSUInteger)index; 49 | 50 | //- (void)removeChildAtIndex:(NSUInteger)index; 51 | 52 | //- (void)setChildren:(NSArray *)children; 53 | 54 | //- (void)addChild:(DDXMLNode *)child; 55 | 56 | //- (void)replaceChildAtIndex:(NSUInteger)index withNode:(DDXMLNode *)node; 57 | 58 | - (NSData *)XMLData; 59 | - (NSData *)XMLDataWithOptions:(NSUInteger)options; 60 | 61 | //- (id)objectByApplyingXSLT:(NSData *)xslt arguments:(NSDictionary *)arguments error:(NSError **)error; 62 | //- (id)objectByApplyingXSLTString:(NSString *)xslt arguments:(NSDictionary *)arguments error:(NSError **)error; 63 | //- (id)objectByApplyingXSLTAtURL:(NSURL *)xsltURL arguments:(NSDictionary *)argument error:(NSError **)error; 64 | 65 | //- (BOOL)validateAndReturnError:(NSError **)error; 66 | 67 | @end 68 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/JSON/NSString+SBJSON.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2007-2009 Stig Brautaset. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the author nor the names of its contributors may be used 15 | to endorse or promote products derived from this software without specific 16 | prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #import "NSString+SBJSON.h" 31 | #import "SBJsonParser.h" 32 | 33 | @implementation NSString (NSString_SBJSON) 34 | 35 | - (id)JSONFragmentValue 36 | { 37 | SBJsonParser *jsonParser = [SBJsonParser new]; 38 | id repr = [jsonParser fragmentWithString:self]; 39 | if (!repr) 40 | NSLog(@"-JSONFragmentValue failed. Error trace is: %@", [jsonParser errorTrace]); 41 | [jsonParser release]; 42 | return repr; 43 | } 44 | 45 | - (id)JSONValue 46 | { 47 | SBJsonParser *jsonParser = [SBJsonParser new]; 48 | id repr = [jsonParser objectWithString:self]; 49 | if (!repr) 50 | NSLog(@"-JSONValue failed. Error trace is: %@", [jsonParser errorTrace]); 51 | [jsonParser release]; 52 | return repr; 53 | } 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/JSON/NSObject+SBJSON.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009 Stig Brautaset. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the author nor the names of its contributors may be used 15 | to endorse or promote products derived from this software without specific 16 | prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #import "NSObject+SBJSON.h" 31 | #import "SBJsonWriter.h" 32 | 33 | @implementation NSObject (NSObject_SBJSON) 34 | 35 | - (NSString *)JSONFragment { 36 | SBJsonWriter *jsonWriter = [SBJsonWriter new]; 37 | NSString *json = [jsonWriter stringWithFragment:self]; 38 | if (!json) 39 | NSLog(@"-JSONFragment failed. Error trace is: %@", [jsonWriter errorTrace]); 40 | [jsonWriter release]; 41 | return json; 42 | } 43 | 44 | - (NSString *)JSONRepresentation { 45 | SBJsonWriter *jsonWriter = [SBJsonWriter new]; 46 | NSString *json = [jsonWriter stringWithObject:self]; 47 | if (!json) 48 | NSLog(@"-JSONRepresentation failed. Error trace is: %@", [jsonWriter errorTrace]); 49 | [jsonWriter release]; 50 | return json; 51 | } 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/AIXMLSerialization/AIXMLSerialization.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | #if TARGET_OS_IPHONE 4 | 5 | #import "DDXML.h" 6 | 7 | #ifndef NSXMLNode 8 | #define NSXMLNode DDXMLNode 9 | #endif 10 | #ifndef NSXMLElement 11 | #define NSXMLElement DDXMLElement 12 | #endif 13 | #ifndef NSXMLDocument 14 | #define NSXMLDocument DDXMLDocument 15 | #endif 16 | 17 | #ifndef NSXMLNodeKind 18 | #define NSXMLInvalidKind DDXMLInvalidKind 19 | #define NSXMLDocumentKind DDXMLDocumentKind 20 | #define NSXMLElementKind DDXMLElementKind 21 | #define NSXMLAttributeKind DDXMLAttributeKind 22 | #define NSXMLNamespaceKind DDXMLNamespaceKind 23 | #define NSXMLProcessingInstructionKind DDXMLProcessingInstructionKind 24 | #define NSXMLCommentKind DDXMLCommentKind 25 | #define NSXMLTextKind DDXMLTextKind 26 | #define NSXMLDTDKind DDXMLDTDKind 27 | #define NSXMLEntityDeclarationKind DDXMLEntityDeclarationKind 28 | #define NSXMLAttributeDeclarationKind DDXMLAttributeDeclarationKind 29 | #define NSXMLElementDeclarationKind DDXMLElementDeclarationKind 30 | #define NSXMLNotationDeclarationKind DDXMLNotationDeclarationKind 31 | 32 | #define NSXMLNodeKind DDXMLNodeKind; 33 | #endif 34 | 35 | #ifndef NSXMLNodeOptionsNone 36 | #define NSXMLNodeOptionsNone DDXMLNodeOptionsNone 37 | #define NSXMLNodeExpandEmptyElement DDXMLNodeExpandEmptyElement 38 | #define NSXMLNodeCompactEmptyElement DDXMLNodeCompactEmptyElement 39 | #define NSXMLNodePrettyPrint DDXMLNodePrettyPrint 40 | #endif 41 | 42 | #ifndef NSXMLDocumentXMLKind 43 | #define NSXMLDocumentXMLKind DDXMLDocumentXMLKind 44 | #define NSXMLDocumentXHTMLKind DDXMLDocumentXHTMLKind 45 | #define NSXMLDocumentHTMLKind DDXMLDocumentHTMLKind 46 | #define NSXMLDocumentTextKind DDXMLDocumentTextKind 47 | 48 | #define NSXMLDocumentContentKind DDXMLDocumentContentKind 49 | #endif 50 | 51 | #ifndef NSXMLDocumentTidyHTML 52 | #define NSXMLDocumentTidyHTML 1 << 9 53 | #define NSXMLDocumentTidyXML 1 << 10 54 | #define NSXMLDocumentValidate 1 << 13 55 | #define NSXMLDocumentXInclude 1 << 16 56 | #endif 57 | 58 | #endif 59 | 60 | 61 | #import "AIXMLDocumentSerialize.h" 62 | #import "AIXMLElementSerialize.h" -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/JSON/JSON.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009 Stig Brautaset. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the author nor the names of its contributors may be used 15 | to endorse or promote products derived from this software without specific 16 | prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | /** 31 | @mainpage A strict JSON parser and generator for Objective-C 32 | 33 | JSON (JavaScript Object Notation) is a lightweight data-interchange 34 | format. This framework provides two apis for parsing and generating 35 | JSON. One standard object-based and a higher level api consisting of 36 | categories added to existing Objective-C classes. 37 | 38 | Learn more on the http://code.google.com/p/json-framework project site. 39 | 40 | This framework does its best to be as strict as possible, both in what it 41 | accepts and what it generates. For example, it does not support trailing commas 42 | in arrays or objects. Nor does it support embedded comments, or 43 | anything else not in the JSON specification. This is considered a feature. 44 | 45 | */ 46 | 47 | #import "SBJSON.h" 48 | #import "NSObject+SBJSON.h" 49 | #import "NSString+SBJSON.h" 50 | 51 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/JSON/NSString+SBJSON.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009 Stig Brautaset. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the author nor the names of its contributors may be used 15 | to endorse or promote products derived from this software without specific 16 | prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #import 31 | 32 | /** 33 | @brief Adds JSON parsing methods to NSString 34 | 35 | This is a category on NSString that adds methods for parsing the target string. 36 | */ 37 | @interface NSString (NSString_SBJSON) 38 | 39 | 40 | /** 41 | @brief Returns the object represented in the receiver, or nil on error. 42 | 43 | Returns a a scalar object represented by the string's JSON fragment representation. 44 | 45 | @deprecated Given we bill ourselves as a "strict" JSON library, this method should be removed. 46 | */ 47 | - (id)JSONFragmentValue; 48 | 49 | /** 50 | @brief Returns the NSDictionary or NSArray represented by the current string's JSON representation. 51 | 52 | Returns the dictionary or array represented in the receiver, or nil on error. 53 | 54 | Returns the NSDictionary or NSArray represented by the current string's JSON representation. 55 | */ 56 | - (id)JSONValue; 57 | 58 | @end 59 | -------------------------------------------------------------------------------- /Source/Tests/GHUnitTestMain.m: -------------------------------------------------------------------------------- 1 | // 2 | // GHUnitTestMain.m 3 | // GHUnit 4 | // 5 | // Created by Gabriel Handford on 2/22/09. 6 | // Copyright 2009. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import 31 | #import 32 | 33 | #import 34 | #import 35 | #import 36 | 37 | int main(int argc, char *argv[]) { 38 | // Setup any NSDebug settings 39 | NSDebugEnabled = YES; 40 | NSZombieEnabled = YES; 41 | NSDeallocateZombies = NO; 42 | NSHangOnUncaughtException = YES; 43 | setenv("NSAutoreleaseFreedObjectCheckEnabled", "1", 1); 44 | 45 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 46 | 47 | // Register any special test case classes 48 | //[[GHTesting sharedInstance] registerClassName:@"GHSpecialTestCase"]; 49 | 50 | int retVal = 0; 51 | // If GHUNIT_CLI is set we are using the command line interface and run the tests 52 | // Otherwise load the GUI app 53 | if (getenv("GHUNIT_CLI")) { 54 | retVal = [GHTestRunner run]; 55 | } else { 56 | // To run all tests (from ENV) 57 | GHTestApp *app = [[GHTestApp alloc] init]; 58 | // To run a different test suite: 59 | //GHTestSuite *suite = [GHTestSuite suiteWithTestFilter:@"GHSlowTest,GHAsyncTestCaseTest"]; 60 | //GHTestApp *app = [[GHTestApp alloc] initWithSuite:suite]; 61 | [NSApp run]; 62 | [app release]; 63 | } 64 | [pool release]; 65 | return retVal; 66 | } 67 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/KissXML/DDXMLPrivate.h: -------------------------------------------------------------------------------- 1 | #import "DDXMLNode.h" 2 | #import "DDXMLElement.h" 3 | #import "DDXMLDocument.h" 4 | 5 | // We can't rely solely on NSAssert, because many developers disable them for release builds. 6 | // Our API contract requires us to keep these assertions intact. 7 | #define DDCheck(condition, desc, ...) { if(!(condition)) { [[NSAssertionHandler currentHandler] handleFailureInMethod:_cmd object:self file:[NSString stringWithUTF8String:__FILE__] lineNumber:__LINE__ description:(desc), ##__VA_ARGS__]; } } 8 | 9 | #define DDLastErrorKey @"DDXML:LastError" 10 | 11 | 12 | @interface DDXMLNode (PrivateAPI) 13 | 14 | + (id)nodeWithUnknownPrimitive:(xmlKindPtr)kindPtr; 15 | 16 | + (id)nodeWithPrimitive:(xmlKindPtr)kindPtr; 17 | - (id)initWithCheckedPrimitive:(xmlKindPtr)kindPtr; 18 | 19 | + (id)nodeWithPrimitive:(xmlNsPtr)ns nsParent:(xmlNodePtr)parent; 20 | - (id)initWithCheckedPrimitive:(xmlNsPtr)ns nsParent:(xmlNodePtr)parent; 21 | 22 | + (BOOL)isXmlAttrPtr:(xmlKindPtr)kindPtr; 23 | - (BOOL)isXmlAttrPtr; 24 | 25 | + (BOOL)isXmlNodePtr:(xmlKindPtr)kindPtr; 26 | - (BOOL)isXmlNodePtr; 27 | 28 | + (BOOL)isXmlDocPtr:(xmlKindPtr)kindPtr; 29 | - (BOOL)isXmlDocPtr; 30 | 31 | + (BOOL)isXmlDtdPtr:(xmlKindPtr)kindPtr; 32 | - (BOOL)isXmlDtdPtr; 33 | 34 | + (BOOL)isXmlNsPtr:(xmlKindPtr)kindPtr; 35 | - (BOOL)isXmlNsPtr; 36 | 37 | - (BOOL)hasParent; 38 | 39 | + (void)recursiveStripDocPointersFromNode:(xmlNodePtr)node; 40 | 41 | + (void)detachAttribute:(xmlAttrPtr)attr fromNode:(xmlNodePtr)node; 42 | + (void)removeAttribute:(xmlAttrPtr)attr fromNode:(xmlNodePtr)node; 43 | + (void)removeAllAttributesFromNode:(xmlNodePtr)node; 44 | 45 | + (void)detachNamespace:(xmlNsPtr)ns fromNode:(xmlNodePtr)node; 46 | + (void)removeNamespace:(xmlNsPtr)ns fromNode:(xmlNodePtr)node; 47 | + (void)removeAllNamespacesFromNode:(xmlNodePtr)node; 48 | 49 | + (void)detachChild:(xmlNodePtr)child fromNode:(xmlNodePtr)node; 50 | + (void)removeChild:(xmlNodePtr)child fromNode:(xmlNodePtr)node; 51 | + (void)removeAllChildrenFromNode:(xmlNodePtr)node; 52 | 53 | + (void)removeAllChildrenFromDoc:(xmlDocPtr)doc; 54 | 55 | - (void)nodeRetain; 56 | - (void)nodeRelease; 57 | 58 | + (NSError *)lastError; 59 | 60 | @end 61 | 62 | @interface DDXMLElement (PrivateAPI) 63 | 64 | + (id)nodeWithPrimitive:(xmlKindPtr)kindPtr; 65 | - (id)initWithCheckedPrimitive:(xmlKindPtr)kindPtr; 66 | 67 | - (NSArray *)elementsWithName:(NSString *)name uri:(NSString *)URI; 68 | 69 | + (DDXMLNode *)resolveNamespaceForPrefix:(NSString *)prefix atNode:(xmlNodePtr)nodePtr; 70 | + (NSString *)resolvePrefixForURI:(NSString *)uri atNode:(xmlNodePtr)nodePtr; 71 | 72 | @end 73 | 74 | @interface DDXMLDocument (PrivateAPI) 75 | 76 | + (id)nodeWithPrimitive:(xmlKindPtr)kindPtr; 77 | - (id)initWithCheckedPrimitive:(xmlKindPtr)kindPtr; 78 | 79 | @end -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/JSON/NSObject+SBJSON.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009 Stig Brautaset. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the author nor the names of its contributors may be used 15 | to endorse or promote products derived from this software without specific 16 | prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #import 31 | 32 | 33 | /** 34 | @brief Adds JSON generation to Foundation classes 35 | 36 | This is a category on NSObject that adds methods for returning JSON representations 37 | of standard objects to the objects themselves. This means you can call the 38 | -JSONRepresentation method on an NSArray object and it'll do what you want. 39 | */ 40 | @interface NSObject (NSObject_SBJSON) 41 | 42 | /** 43 | @brief Returns a string containing the receiver encoded as a JSON fragment. 44 | 45 | This method is added as a category on NSObject but is only actually 46 | supported for the following objects: 47 | @li NSDictionary 48 | @li NSArray 49 | @li NSString 50 | @li NSNumber (also used for booleans) 51 | @li NSNull 52 | 53 | @deprecated Given we bill ourselves as a "strict" JSON library, this method should be removed. 54 | */ 55 | - (NSString *)JSONFragment; 56 | 57 | /** 58 | @brief Returns a string containing the receiver encoded in JSON. 59 | 60 | This method is added as a category on NSObject but is only actually 61 | supported for the following objects: 62 | @li NSDictionary 63 | @li NSArray 64 | */ 65 | - (NSString *)JSONRepresentation; 66 | 67 | @end 68 | 69 | -------------------------------------------------------------------------------- /Documentation/Samples/Tweet.m: -------------------------------------------------------------------------------- 1 | @implementation Tweet 2 | @synthesize screenName; 3 | @synthesize name; 4 | @synthesize text; 5 | @synthesize location; 6 | 7 | // Set default options here 8 | + (void)initialize { 9 | [self setDelegate:self]; 10 | [self setBaseURL:[NSURL URLWithString:@"http://twitter.com"]]; 11 | } 12 | 13 | - (void)initWithDictionary:(NSDictionary *)dict { 14 | if(self = [super init]) { 15 | [self setScreenName:[dict valueForKeyPath:@"user.screen_name"]]; 16 | [self setName:[dict valueForKeyPath:@"user.name"]]; 17 | [self setLocation:[dict valueForKeyPath:@"user.location"]]; 18 | [self setText:[dict valueForKey:@"text"]]; 19 | } 20 | 21 | return self; 22 | } 23 | 24 | // NOTE: The `delegate` object isn't neccissary here, but there is an important reason why 25 | // I'm using this approach. I want to give my controller fully initialized models instead of 26 | // raw NSDIctionary objects. On that note I pass the controller as the object to the 27 | // request so I can call back to it in the delegate methods handling the responses. 28 | + (id)timelineForUser:(NSString *)user delegate:(id)delegate { 29 | NSDictionary *params = [NSDictionary dictionaryWithObject:user forKey:@"screen_name"]; 30 | NSDictionary *opts = [NSDictionary dictionaryWithObject:params forKey:@"params"]; 31 | 32 | [self getPath:@"/statuses/user_timeline.json" withOptions:opts object:delegate]; 33 | } 34 | 35 | + (id)publicTimelineWithDelegate:(id)delegate { 36 | [self getPath:@"/statuses/public_timeline.json" withOptions:nil object:delegate]; 37 | } 38 | 39 | #pragma mark - HRRequestOperation Delegates 40 | + (void)restConnection:(NSURLConnection *)connection didFailWithError:(NSError *)error object:(id)object { 41 | // Handle connection errors. Failures to connect to the server, etc. 42 | } 43 | 44 | + (void)restConnection:(NSURLConnection *)connection didReceiveError:(NSError *)error response:(NSHTTPURLResponse *)response object:(id)object { 45 | // Handle invalid responses, 404, 500, etc. 46 | } 47 | 48 | + (void)restConnection:(NSURLConnection *)connection didReceiveParseError:(NSError *)error responseBody:(NSString *)string { 49 | // Request was successful, but couldn't parse the data returned by the server. 50 | } 51 | 52 | // Given I've passed the controller as the object here, I can call any method I want to on it 53 | // giving it a collection of models I've initialized. 54 | + (void)restConnection:(NSURLConnection *)connection didReturnResource:(id)resource object:(id)object { 55 | NSMutableArray *tweets = [[[NSMutableArray alloc] init] autorelease]; 56 | 57 | for(id item in resource) { 58 | [tweets addItem:[[Tweet alloc] initWithDictionary:item]]; 59 | } 60 | 61 | [object performSelector:@selector(tweetsLoaded:) withObject:tweets]; 62 | } 63 | @end 64 | 65 | 66 | -------------------------------------------------------------------------------- /Source/HTTPRiot/HRResponseDelegate.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file HRResponseDelegate.h Protocol for the response delegate methods. 3 | */ 4 | 5 | // 6 | // HRResponseDelegate.h 7 | // HTTPRiot 8 | // 9 | // Created by Justin Palmer on 6/24/09. 10 | // Copyright 2009 LabratRevenge LLC.. All rights reserved. 11 | // 12 | 13 | /** 14 | * @protocol HRResponseDelegate 15 | * 16 | * Implementing the HRResponseDelegate protocol allows you to handle requests. 17 | */ 18 | @protocol HRResponseDelegate 19 | @optional 20 | /** 21 | * Called when the resource was succeffully fetched and encoded 22 | * 23 | * @param connection The connection object for the current request 24 | * @param resource The converted objc representation of the response data returned by the server. 25 | * @param object Any custom object you passed in while making the request. 26 | */ 27 | - (void)restConnection:(NSURLConnection *)connection didReturnResource:(id)resource object:(id)object; 28 | 29 | /** 30 | * Called when the connection fails in situations where the server is not available, etc. 31 | * 32 | * @param connection The connection object for the current request 33 | * @param error The error returned by the connection. 34 | * @param object Any custom object you passed in while making the request. 35 | */ 36 | - (void)restConnection:(NSURLConnection *)connection didFailWithError:(NSError *)error object:(id)object; 37 | 38 | /** 39 | * Called when the connection receieves any type of response 40 | * 41 | * @param connection The connection object for the current request 42 | * @param response The response object returned by the server. 43 | * @param object Any custom object you passed in while making the request. 44 | */ 45 | - (void)restConnection:(NSURLConnection *)connection didReceiveResponse:(NSHTTPURLResponse *)response object:(id)object; 46 | 47 | /** 48 | * Called when the connection receieves a statusCode that isn't a success code. 49 | * 50 | * @param connection The connection object for the current request 51 | * @param error The error returned by the connection. 52 | * @param response The response object returned by the server. 53 | * @param object Any custom object you passed in while making the request. 54 | */ 55 | - (void)restConnection:(NSURLConnection *)connection didReceiveError:(NSError *)error response:(NSHTTPURLResponse *)response object:(id)object; 56 | 57 | /** 58 | * Called when the HRFormatter recieved an error parsing the response data. 59 | * 60 | * @param connection The connection object for the current request 61 | * @param error The parser error returned by the formatter. 62 | * @param body A string representation of the response body returned by the server. 63 | * @param object Any custom object you passed in while making the request. 64 | */ 65 | - (void)restConnection:(NSURLConnection *)connection didReceiveParseError:(NSError *)error responseBody:(NSString *)body object:(id)object; 66 | @end 67 | -------------------------------------------------------------------------------- /Source/Tests/Server/views/layout.erb: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | application 8 | 116 | 117 | 118 |
119 | <%= yield %> 120 |
121 | 122 | 123 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/JSON/SBJsonBase.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009 Stig Brautaset. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the author nor the names of its contributors may be used 15 | to endorse or promote products derived from this software without specific 16 | prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #import "SBJsonBase.h" 31 | NSString * SBJSONErrorDomain = @"org.brautaset.JSON.ErrorDomain"; 32 | 33 | 34 | @implementation SBJsonBase 35 | 36 | @synthesize errorTrace; 37 | @synthesize maxDepth; 38 | 39 | - (id)init { 40 | self = [super init]; 41 | if (self) 42 | self.maxDepth = 512; 43 | return self; 44 | } 45 | 46 | - (void)dealloc { 47 | [errorTrace release]; 48 | [super dealloc]; 49 | } 50 | 51 | - (void)addErrorWithCode:(NSUInteger)code description:(NSString*)str { 52 | NSDictionary *userInfo; 53 | if (!errorTrace) { 54 | errorTrace = [NSMutableArray new]; 55 | userInfo = [NSDictionary dictionaryWithObject:str forKey:NSLocalizedDescriptionKey]; 56 | 57 | } else { 58 | userInfo = [NSDictionary dictionaryWithObjectsAndKeys: 59 | str, NSLocalizedDescriptionKey, 60 | [errorTrace lastObject], NSUnderlyingErrorKey, 61 | nil]; 62 | } 63 | 64 | NSError *error = [NSError errorWithDomain:SBJSONErrorDomain code:code userInfo:userInfo]; 65 | 66 | [self willChangeValueForKey:@"errorTrace"]; 67 | [errorTrace addObject:error]; 68 | [self didChangeValueForKey:@"errorTrace"]; 69 | } 70 | 71 | - (void)clearErrorTrace { 72 | [self willChangeValueForKey:@"errorTrace"]; 73 | [errorTrace release]; 74 | errorTrace = nil; 75 | [self didChangeValueForKey:@"errorTrace"]; 76 | } 77 | 78 | @end 79 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/JSON/SBJSON.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2007-2009 Stig Brautaset. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the author nor the names of its contributors may be used 15 | to endorse or promote products derived from this software without specific 16 | prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #import 31 | #import "SBJsonParser.h" 32 | #import "SBJsonWriter.h" 33 | 34 | /** 35 | @brief Facade for SBJsonWriter/SBJsonParser. 36 | 37 | Requests are forwarded to instances of SBJsonWriter and SBJsonParser. 38 | */ 39 | @interface SBJSON : SBJsonBase { 40 | 41 | @private 42 | SBJsonParser *jsonParser; 43 | SBJsonWriter *jsonWriter; 44 | } 45 | 46 | 47 | /// Return the fragment represented by the given string 48 | - (id)fragmentWithString:(NSString*)jsonrep 49 | error:(NSError**)error; 50 | 51 | /// Return the object represented by the given string 52 | - (id)objectWithString:(NSString*)jsonrep 53 | error:(NSError**)error; 54 | 55 | /// Parse the string and return the represented object (or scalar) 56 | - (id)objectWithString:(id)value 57 | allowScalar:(BOOL)x 58 | error:(NSError**)error; 59 | 60 | 61 | /// Return JSON representation of an array or dictionary 62 | - (NSString*)stringWithObject:(id)value 63 | error:(NSError**)error; 64 | 65 | /// Return JSON representation of any legal JSON value 66 | - (NSString*)stringWithFragment:(id)value 67 | error:(NSError**)error; 68 | 69 | /// Return JSON representation (or fragment) for the given object 70 | - (NSString*)stringWithObject:(id)value 71 | allowScalar:(BOOL)x 72 | error:(NSError**)error; 73 | 74 | 75 | @end 76 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/JSON/SBJsonBase.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009 Stig Brautaset. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the author nor the names of its contributors may be used 15 | to endorse or promote products derived from this software without specific 16 | prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #import 31 | 32 | extern NSString * SBJSONErrorDomain; 33 | 34 | 35 | enum { 36 | EUNSUPPORTED = 1, 37 | EPARSENUM, 38 | EPARSE, 39 | EFRAGMENT, 40 | ECTRL, 41 | EUNICODE, 42 | EDEPTH, 43 | EESCAPE, 44 | ETRAILCOMMA, 45 | ETRAILGARBAGE, 46 | EEOF, 47 | EINPUT 48 | }; 49 | 50 | /** 51 | @brief Common base class for parsing & writing. 52 | 53 | This class contains the common error-handling code and option between the parser/writer. 54 | */ 55 | @interface SBJsonBase : NSObject { 56 | NSMutableArray *errorTrace; 57 | 58 | @protected 59 | NSUInteger depth, maxDepth; 60 | } 61 | 62 | /** 63 | @brief The maximum recursing depth. 64 | 65 | Defaults to 512. If the input is nested deeper than this the input will be deemed to be 66 | malicious and the parser returns nil, signalling an error. ("Nested too deep".) You can 67 | turn off this security feature by setting the maxDepth value to 0. 68 | */ 69 | @property NSUInteger maxDepth; 70 | 71 | /** 72 | @brief Return an error trace, or nil if there was no errors. 73 | 74 | Note that this method returns the trace of the last method that failed. 75 | You need to check the return value of the call you're making to figure out 76 | if the call actually failed, before you know call this method. 77 | */ 78 | @property(copy,readonly) NSArray* errorTrace; 79 | 80 | /// @internal for use in subclasses to add errors to the stack trace 81 | - (void)addErrorWithCode:(NSUInteger)code description:(NSString*)str; 82 | 83 | /// @internal for use in subclasess to clear the error before a new parsing attempt 84 | - (void)clearErrorTrace; 85 | 86 | @end 87 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/gh-unit-iphone/NSValue+GHValueFormatter.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSValue+GHValueFormatter.h 3 | // 4 | // Created by Johannes Rudolph on 23.9.2009. 5 | // Copyright 2009. All rights reserved. 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | // 30 | // Portions of this file fall under the following license, marked with 31 | // SENTE_BEGIN - SENTE_END 32 | // 33 | // Copyright (c) 1997-2005, Sen:te (Sente SA). All rights reserved. 34 | // 35 | // Use of this source code is governed by the following license: 36 | // 37 | // Redistribution and use in source and binary forms, with or without modification, 38 | // are permitted provided that the following conditions are met: 39 | // 40 | // (1) Redistributions of source code must retain the above copyright notice, 41 | // this list of conditions and the following disclaimer. 42 | // 43 | // (2) Redistributions in binary form must reproduce the above copyright notice, 44 | // this list of conditions and the following disclaimer in the documentation 45 | // and/or other materials provided with the distribution. 46 | // 47 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 48 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 49 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 50 | // IN NO EVENT SHALL Sente SA OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 51 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 52 | // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 53 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 54 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 55 | // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 56 | // 57 | // Note: this license is equivalent to the FreeBSD license. 58 | // 59 | // This notice may not be removed from this file. 60 | 61 | #import 62 | 63 | // SENTE_BEGIN 64 | @interface NSValue (GHValueFormatter) 65 | - (NSString *)ghu_contentDescription; 66 | @end 67 | // SENTE_END 68 | -------------------------------------------------------------------------------- /Source/HTTPRiot/HRRequestOperation.h: -------------------------------------------------------------------------------- 1 | // 2 | // HRRequestOperation.h 3 | // HTTPRiot 4 | // 5 | // Created by Justin Palmer on 1/30/09. 6 | // Copyright 2009 LabratRevenge LLC.. All rights reserved. 7 | // 8 | #import 9 | #import "HRGlobal.h" 10 | #import "HRResponseDelegate.h" 11 | #import "HRFormatterProtocol.h" 12 | 13 | /** 14 | * The object which all requests are routed through. You shouldn't need to use 15 | * this class directly, but instead use HRRestModel which wraps the method 16 | * of this class neatly. 17 | */ 18 | @interface HRRequestOperation : NSOperation { 19 | /// HRResponse Delegate 20 | NSObject *_delegate; 21 | 22 | /// Connection object 23 | NSURLConnection *_connection; 24 | 25 | /// Data received from response 26 | NSMutableData *_responseData; 27 | 28 | /// The path or URL to use in REST methods 29 | NSString *_path; 30 | 31 | /// Contains all options used by the request. 32 | NSDictionary *_options; 33 | 34 | /// How long before the request will timeout 35 | NSTimeInterval _timeout; 36 | 37 | /// The request method to use 38 | HRRequestMethod _requestMethod; 39 | 40 | /// The HRFormatter object 41 | id _formatter; 42 | 43 | /// The object passed to all delegate methods 44 | id _object; 45 | 46 | /// Determines whether the operation is finished 47 | BOOL _isFinished; 48 | 49 | /// Determines whether the operation is executing 50 | BOOL _isExecuting; 51 | 52 | /// Determines whether the connection is cancelled 53 | BOOL _isCancelled; 54 | } 55 | 56 | /// The HRResponseDelegate 57 | /** 58 | * The HRResponseDelegate responsible for handling the success and failure of 59 | * a request. 60 | */ 61 | @property (nonatomic, readonly, assign) NSObject *delegate; 62 | 63 | /// The lenght of time in seconds before the request times out. 64 | /** 65 | * Sets the length of time in seconds before a request will timeout. 66 | * This defaults to 30.0. 67 | */ 68 | @property (nonatomic, assign) NSTimeInterval timeout; 69 | 70 | /// The REST method to use when performing a request 71 | /** 72 | * This defaults to HRRequestMethodGet. Valid options are ::HRRequestMethod. 73 | */ 74 | @property (nonatomic, assign) HRRequestMethod requestMethod; 75 | 76 | /// The relative path or url string used in a request 77 | /** 78 | If you provide a relative path here, you must set the baseURL option. 79 | If given a full url this will overide the baseURL option. 80 | */ 81 | @property (nonatomic, copy) NSString *path; 82 | 83 | /// An NSDictionary containing all the options for a request. 84 | /** 85 | This needs documented 86 | */ 87 | @property (nonatomic, retain) NSDictionary *options; 88 | 89 | /// The formatter used to decode the response body. 90 | /** 91 | Currently, only JSON is supported. 92 | */ 93 | @property (nonatomic, readonly) id formatter; 94 | 95 | /** 96 | * Returns an HRRequestOperation 97 | */ 98 | + (HRRequestOperation *)requestWithMethod:(HRRequestMethod)method path:(NSString*)urlPath options:(NSDictionary*)requestOptions object:(id)obj; 99 | @end 100 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/JSON/SBJsonParser.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009 Stig Brautaset. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the author nor the names of its contributors may be used 15 | to endorse or promote products derived from this software without specific 16 | prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #import 31 | #import "SBJsonBase.h" 32 | 33 | /** 34 | @brief Options for the parser class. 35 | 36 | This exists so the SBJSON facade can implement the options in the parser without having to re-declare them. 37 | */ 38 | @protocol SBJsonParser 39 | 40 | /** 41 | @brief Return the object represented by the given string. 42 | 43 | Returns the object represented by the passed-in string or nil on error. The returned object can be 44 | a string, number, boolean, null, array or dictionary. 45 | 46 | @param repr the json string to parse 47 | */ 48 | - (id)objectWithString:(NSString *)repr; 49 | 50 | @end 51 | 52 | 53 | /** 54 | @brief The JSON parser class. 55 | 56 | JSON is mapped to Objective-C types in the following way: 57 | 58 | @li Null -> NSNull 59 | @li String -> NSMutableString 60 | @li Array -> NSMutableArray 61 | @li Object -> NSMutableDictionary 62 | @li Boolean -> NSNumber (initialised with -initWithBool:) 63 | @li Number -> NSDecimalNumber 64 | 65 | Since Objective-C doesn't have a dedicated class for boolean values, these turns into NSNumber 66 | instances. These are initialised with the -initWithBool: method, and 67 | round-trip back to JSON properly. (They won't silently suddenly become 0 or 1; they'll be 68 | represented as 'true' and 'false' again.) 69 | 70 | JSON numbers turn into NSDecimalNumber instances, 71 | as we can thus avoid any loss of precision. (JSON allows ridiculously large numbers.) 72 | 73 | */ 74 | @interface SBJsonParser : SBJsonBase { 75 | 76 | @private 77 | const char *c; 78 | } 79 | 80 | @end 81 | 82 | // don't use - exists for backwards compatibility with 2.1.x only. Will be removed in 2.3. 83 | @interface SBJsonParser (Private) 84 | - (id)fragmentWithString:(id)repr; 85 | @end 86 | 87 | 88 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/gh-unit-iphone/GHUnitIPhoneTestMain.m: -------------------------------------------------------------------------------- 1 | // 2 | // GHUnitIPhoneTestMain.m 3 | // GHUnitIPhone 4 | // 5 | // Created by Gabriel Handford on 1/25/09. 6 | // Copyright 2009. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import 31 | 32 | #import "GHUnit.h" 33 | #import "GHTesting.h" 34 | 35 | // Default exception handler 36 | void exceptionHandler(NSException *exception) { 37 | NSLog(@"%@\n%@", [exception reason], GHUStackTraceFromException(exception)); 38 | } 39 | 40 | int main(int argc, char *argv[]) { 41 | 42 | /*! 43 | For debugging: 44 | Go into the "Get Info" contextual menu of your (test) executable (inside the "Executables" group in the left panel of XCode). 45 | Then go in the "Arguments" tab. You can add the following environment variables: 46 | 47 | Default: Set to: 48 | NSDebugEnabled NO "YES" 49 | NSZombieEnabled NO "YES" 50 | NSDeallocateZombies NO "YES" 51 | NSHangOnUncaughtException NO "YES" 52 | 53 | NSEnableAutoreleasePool YES "NO" 54 | NSAutoreleaseFreedObjectCheckEnabled NO "YES" 55 | NSAutoreleaseHighWaterMark 0 non-negative integer 56 | NSAutoreleaseHighWaterResolution 0 non-negative integer 57 | 58 | For info on these varaiables see NSDebug.h; http://theshadow.uw.hu/iPhoneSDKdoc/Foundation.framework/NSDebug.h.html 59 | 60 | For malloc debugging see: http://developer.apple.com/mac/library/documentation/Performance/Conceptual/ManagingMemory/Articles/MallocDebug.html 61 | */ 62 | 63 | NSSetUncaughtExceptionHandler(&exceptionHandler); 64 | 65 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 66 | 67 | // Register any special test case classes 68 | //[[GHTesting sharedInstance] registerClassName:@"GHSpecialTestCase"]; 69 | 70 | int retVal = 0; 71 | // If GHUNIT_CLI is set we are using the command line interface and run the tests 72 | // Otherwise load the GUI app 73 | if (getenv("GHUNIT_CLI")) { 74 | retVal = [GHTestRunner run]; 75 | } else { 76 | retVal = UIApplicationMain(argc, argv, nil, @"GHUnitIPhoneAppDelegate"); 77 | } 78 | [pool release]; 79 | return retVal; 80 | } 81 | -------------------------------------------------------------------------------- /Source/Tests/HTTPRiotRestModelTest.m: -------------------------------------------------------------------------------- 1 | // 2 | // RestModelTest.m 3 | // HTTPRiot 4 | // 5 | // Created by Justin Palmer on 1/30/09. 6 | // Copyright 2009 Alternateidea. All rights reserved. 7 | // 8 | 9 | #import "HTTPRiotTestHelper.h" 10 | 11 | @interface HRRestModelTest : GHTestCase {} @end 12 | 13 | @implementation HRRestModelTest 14 | - (void) testSetsBaseURL { 15 | GHAssertEqualObjects(@"http://localhost:4567", [[HRTestPerson baseURL] absoluteString], nil); 16 | GHAssertEqualObjects([NSURL URLWithString:@"http://localhost:4567"], [HRTestPerson2 baseURL], nil); 17 | } 18 | 19 | - (void)testDefaultFormatIsJSON { 20 | GHAssertEquals([HRTestPerson format], HRDataFormatJSON, nil); 21 | } 22 | 23 | - (void)testShouldSetFormat { 24 | [HRTestPerson4 setFormat:HRDataFormatXML]; 25 | GHAssertEquals([HRTestPerson4 format], HRDataFormatXML, nil); 26 | } 27 | 28 | - (void)testShouldSetDefaultHeaders { 29 | NSDictionary *headers = [HRTestPerson3 headers]; 30 | GHAssertEqualObjects(@"bar", [headers objectForKey:@"foo"], nil); 31 | GHAssertEqualObjects(@"bing", [headers objectForKey:@"bada"], nil); 32 | } 33 | 34 | - (void)testShouldSetDefaultParams { 35 | NSDictionary *params = [HRTestPerson3 defaultParams]; 36 | GHAssertEqualObjects(@"bar", [params objectForKey:@"foo"], nil); 37 | GHAssertEqualObjects(@"bing", [params objectForKey:@"bada"], nil); 38 | } 39 | 40 | - (void)testShouldSetBasicAuthCredentials { 41 | NSDictionary *expectedAuth = [NSDictionary dictionaryWithObjectsAndKeys:@"username@email.com", @"username", @"test", @"password", nil]; 42 | NSDictionary *basicAuth = [HRTestPerson basicAuth]; 43 | GHAssertEqualObjects(basicAuth, expectedAuth, nil); 44 | } 45 | 46 | - (void)testShouldMergeDefaultParamsWithParamsPassedToMethod { 47 | // defaultParams: {foo: 'bar', bada: 'bing'} 48 | NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:@"5",@"limit", nil]; 49 | NSDictionary *opts = [NSDictionary dictionaryWithObject:params forKey:@"params"]; 50 | 51 | NSDictionary *mergedOpts = [HRTestPerson3 mergedOptions:opts]; 52 | params = [mergedOpts valueForKey:@"params"]; 53 | 54 | GHAssertEqualObjects([params valueForKey:@"limit"], @"5", nil); 55 | GHAssertEqualObjects([params valueForKey:@"bada"], @"bing", nil); 56 | } 57 | 58 | - (void)testParamsProvidedInMethodShouldOverideDefaultParams { 59 | // defaultParams: {foo: 'bar', bada: 'bing'} 60 | NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:@"123",@"foo", nil]; 61 | NSDictionary *opts = [NSDictionary dictionaryWithObject:params forKey:@"params"]; 62 | 63 | NSDictionary *mergedOpts = [HRTestPerson3 mergedOptions:opts]; 64 | params = [mergedOpts valueForKey:@"params"]; 65 | 66 | GHAssertEqualObjects([params valueForKey:@"foo"], @"123", nil); 67 | GHAssertEqualObjects([params valueForKey:@"bada"], @"bing", nil); 68 | } 69 | 70 | - (void) testShouldCreateUniqueClassAttributesForSubClasses { 71 | NSDictionary *h5attrs = [HRTestPerson5 classAttributes]; 72 | NSDictionary *h6attrs = [HRTestPerson6 classAttributes]; 73 | NSURL *h5URL = [NSURL URLWithString:@"http://foo.com"]; 74 | NSURL *h6URL = [NSURL URLWithString:@"http://bar.com"]; 75 | [HRTestPerson5 setBaseURL:h5URL]; 76 | [HRTestPerson6 setBaseURL:h6URL]; 77 | 78 | GHAssertEqualObjects([h5attrs objectForKey:@"baseURL"], h5URL, nil); 79 | GHAssertEqualObjects([h6attrs objectForKey:@"baseURL"], h6URL, nil); 80 | } 81 | 82 | @end 83 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/KissXML/DDXMLElementAdditions.m: -------------------------------------------------------------------------------- 1 | #import "DDXMLElementAdditions.h" 2 | 3 | @implementation DDXMLElement (DDAdditions) 4 | 5 | /** 6 | * Quick method to create an element 7 | **/ 8 | + (DDXMLElement *)elementWithName:(NSString *)name xmlns:(NSString *)ns 9 | { 10 | DDXMLElement *element = [DDXMLElement elementWithName:name]; 11 | [element setXmlns:ns]; 12 | return element; 13 | } 14 | 15 | /** 16 | * This method returns the first child element for the given name. 17 | * If no child element exists for the given name, returns nil. 18 | **/ 19 | - (DDXMLElement *)elementForName:(NSString *)name 20 | { 21 | NSArray *elements = [self elementsForName:name]; 22 | if([elements count] > 0) 23 | { 24 | return [elements objectAtIndex:0]; 25 | } 26 | else 27 | { 28 | // Note: If you port this code to work with Apple's NSXML, beware of the following: 29 | // 30 | // There is a bug in the NSXMLElement elementsForName: method. 31 | // Consider the following XML fragment: 32 | // 33 | // 34 | // 35 | // 36 | // 37 | // Calling [query elementsForName:@"x"] results in an empty array! 38 | // 39 | // However, it will work properly if you use the following: 40 | // [query elementsForLocalName:@"x" URI:@"some:other:namespace"] 41 | // 42 | // The trouble with this is that we may not always know the xmlns in advance, 43 | // so in this particular case there is no way to access the element without looping through the children. 44 | // 45 | // This bug was submitted to apple on June 1st, 2007 and was classified as "serious". 46 | // 47 | // --!!-- This bug does NOT exist in DDXML --!!-- 48 | 49 | return nil; 50 | } 51 | } 52 | 53 | /** 54 | * This method returns the first child element for the given name and given xmlns. 55 | * If no child elements exist for the given name and given xmlns, returns nil. 56 | **/ 57 | - (DDXMLElement *)elementForName:(NSString *)name xmlns:(NSString *)xmlns 58 | { 59 | NSArray *elements = [self elementsForLocalName:name URI:xmlns]; 60 | if([elements count] > 0) 61 | { 62 | return [elements objectAtIndex:0]; 63 | } 64 | else 65 | { 66 | return nil; 67 | } 68 | } 69 | 70 | /** 71 | * Returns the common xmlns "attribute", which is only accessible via the namespace methods. 72 | * The xmlns value is often used in jabber elements. 73 | **/ 74 | - (NSString *)xmlns 75 | { 76 | return [[self namespaceForPrefix:@""] stringValue]; 77 | } 78 | 79 | - (void)setXmlns:(NSString *)ns 80 | { 81 | // If you use setURI: then the xmlns won't be displayed in the XMLString. 82 | // Adding the namespace this way works properly. 83 | // 84 | // This applies to both Apple's NSXML and DDXML. 85 | 86 | [self addNamespace:[DDXMLNode namespaceWithName:@"" stringValue:ns]]; 87 | } 88 | 89 | /** 90 | * Shortcut to avoid having to manually create a DDXMLNode everytime. 91 | **/ 92 | - (void)addAttributeWithName:(NSString *)name stringValue:(NSString *)string 93 | { 94 | [self addAttribute:[DDXMLNode attributeWithName:name stringValue:string]]; 95 | } 96 | 97 | /** 98 | * Returns all the attributes as a dictionary. 99 | **/ 100 | - (NSDictionary *)attributesAsDictionary 101 | { 102 | NSArray *attributes = [self attributes]; 103 | NSMutableDictionary *result = [NSMutableDictionary dictionaryWithCapacity:[attributes count]]; 104 | 105 | uint i; 106 | for(i = 0; i < [attributes count]; i++) 107 | { 108 | DDXMLNode *node = [attributes objectAtIndex:i]; 109 | 110 | [result setObject:[node stringValue] forKey:[node name]]; 111 | } 112 | return result; 113 | } 114 | 115 | @end 116 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/KissXML/DDXMLDocument.m: -------------------------------------------------------------------------------- 1 | #import "DDXMLDocument.h" 2 | #import "NSStringAdditions.h" 3 | #import "DDXMLPrivate.h" 4 | 5 | 6 | @implementation DDXMLDocument 7 | 8 | /** 9 | * Returns a DDXML wrapper object for the given primitive node. 10 | * The given node MUST be non-NULL and of the proper type. 11 | * 12 | * If the wrapper object already exists, it is retained/autoreleased and returned. 13 | * Otherwise a new wrapper object is alloc/init/autoreleased and returned. 14 | **/ 15 | + (id)nodeWithPrimitive:(xmlKindPtr)kindPtr 16 | { 17 | // If a wrapper object already exists, the _private variable is pointing to it. 18 | 19 | xmlDocPtr doc = (xmlDocPtr)kindPtr; 20 | if(doc->_private == NULL) 21 | return [[[DDXMLDocument alloc] initWithCheckedPrimitive:kindPtr] autorelease]; 22 | else 23 | return [[((DDXMLDocument *)(doc->_private)) retain] autorelease]; 24 | } 25 | 26 | /** 27 | * Returns a DDXML wrapper object for the given primitive node. 28 | * The given node MUST be non-NULL and of the proper type. 29 | * 30 | * The given node is checked, meaning a wrapper object for it does not already exist. 31 | **/ 32 | - (id)initWithCheckedPrimitive:(xmlKindPtr)kindPtr 33 | { 34 | self = [super initWithCheckedPrimitive:kindPtr]; 35 | return self; 36 | } 37 | 38 | /** 39 | * Initializes and returns a DDXMLDocument object created from an NSData object. 40 | * 41 | * Returns an initialized DDXMLDocument object, or nil if initialization fails 42 | * because of parsing errors or other reasons. 43 | **/ 44 | - (id)initWithXMLString:(NSString *)string options:(NSUInteger)mask error:(NSError **)error 45 | { 46 | return [self initWithData:[string dataUsingEncoding:NSUTF8StringEncoding] options:mask error:error]; 47 | } 48 | 49 | /** 50 | * Initializes and returns a DDXMLDocument object created from an NSData object. 51 | * 52 | * Returns an initialized DDXMLDocument object, or nil if initialization fails 53 | * because of parsing errors or other reasons. 54 | **/ 55 | - (id)initWithData:(NSData *)data options:(NSUInteger)mask error:(NSError **)error 56 | { 57 | if(data == nil || [data length] == 0) 58 | { 59 | if(error) *error = [NSError errorWithDomain:@"DDXMLErrorDomain" code:0 userInfo:nil]; 60 | 61 | [self release]; 62 | return nil; 63 | } 64 | 65 | // Even though xmlKeepBlanksDefault(0) is called in DDXMLNode's initialize method, 66 | // it has been documented that this call seems to get reset on the iPhone: 67 | // http://code.google.com/p/kissxml/issues/detail?id=8 68 | // 69 | // Therefore, we call it again here just to be safe. 70 | xmlKeepBlanksDefault(0); 71 | 72 | xmlDocPtr doc = xmlParseMemory([data bytes], [data length]); 73 | if(doc == NULL) 74 | { 75 | if(error) *error = [NSError errorWithDomain:@"DDXMLErrorDomain" code:1 userInfo:nil]; 76 | 77 | [self release]; 78 | return nil; 79 | } 80 | 81 | return [self initWithCheckedPrimitive:(xmlKindPtr)doc]; 82 | } 83 | 84 | /** 85 | * Returns the root element of the receiver. 86 | **/ 87 | - (DDXMLElement *)rootElement 88 | { 89 | xmlDocPtr doc = (xmlDocPtr)genericPtr; 90 | 91 | // doc->children is a list containing possibly comments, DTDs, etc... 92 | 93 | xmlNodePtr rootNode = xmlDocGetRootElement(doc); 94 | 95 | if(rootNode != NULL) 96 | return [DDXMLElement nodeWithPrimitive:(xmlKindPtr)rootNode]; 97 | else 98 | return nil; 99 | } 100 | 101 | - (NSData *)XMLData 102 | { 103 | return [[self XMLString] dataUsingEncoding:NSUTF8StringEncoding]; 104 | } 105 | 106 | - (NSData *)XMLDataWithOptions:(NSUInteger)options 107 | { 108 | return [[self XMLStringWithOptions:options] dataUsingEncoding:NSUTF8StringEncoding]; 109 | } 110 | 111 | @end 112 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Utilities/HRBase64.m: -------------------------------------------------------------------------------- 1 | // 2 | // HRBase64.m 3 | // HTTPRiot 4 | // 5 | // Created by Justin Palmer on 7/2/09. 6 | // Copyright 2009 LabratRevenge LLC.. All rights reserved. 7 | // 8 | 9 | #import "HRBase64.h" 10 | 11 | @interface NSData (MBBase64) 12 | + (id)dataWithBase64EncodedString:(NSString *)string; // Padding '=' characters are optional. Whitespace is ignored. 13 | - (NSString *)base64Encoding; 14 | @end 15 | 16 | static const char encodingTable[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 17 | 18 | 19 | @implementation NSData (MBBase64) 20 | 21 | + (id)dataWithBase64EncodedString:(NSString *)string { 22 | if (string == nil) 23 | [NSException raise:NSInvalidArgumentException format:@""]; 24 | if ([string length] == 0) 25 | return [NSData data]; 26 | 27 | static char *decodingTable = NULL; 28 | if (decodingTable == NULL) 29 | { 30 | decodingTable = malloc(256); 31 | if (decodingTable == NULL) 32 | return nil; 33 | memset(decodingTable, CHAR_MAX, 256); 34 | NSUInteger i; 35 | for (i = 0; i < 64; i++) 36 | decodingTable[(short)encodingTable[i]] = i; 37 | } 38 | 39 | const char *characters = [string cStringUsingEncoding:NSASCIIStringEncoding]; 40 | if (characters == NULL) // Not an ASCII string! 41 | return nil; 42 | char *bytes = malloc((([string length] + 3) / 4) * 3); 43 | if (bytes == NULL) 44 | return nil; 45 | NSUInteger length = 0; 46 | 47 | NSUInteger i = 0; 48 | while (YES) 49 | { 50 | char buffer[4]; 51 | short bufferLength; 52 | for (bufferLength = 0; bufferLength < 4; i++) 53 | { 54 | if (characters[i] == '\0') 55 | break; 56 | if (isspace(characters[i]) || characters[i] == '=') 57 | continue; 58 | buffer[bufferLength] = decodingTable[(short)characters[i]]; 59 | if (buffer[bufferLength++] == CHAR_MAX) // Illegal character! 60 | { 61 | free(bytes); 62 | return nil; 63 | } 64 | } 65 | 66 | if (bufferLength == 0) 67 | break; 68 | if (bufferLength == 1) // At least two characters are needed to produce one byte! 69 | { 70 | free(bytes); 71 | return nil; 72 | } 73 | 74 | // Decode the characters in the buffer to bytes. 75 | bytes[length++] = (buffer[0] << 2) | (buffer[1] >> 4); 76 | if (bufferLength > 2) 77 | bytes[length++] = (buffer[1] << 4) | (buffer[2] >> 2); 78 | if (bufferLength > 3) 79 | bytes[length++] = (buffer[2] << 6) | buffer[3]; 80 | } 81 | 82 | realloc(bytes, length); 83 | return [NSData dataWithBytesNoCopy:bytes length:length]; 84 | } 85 | 86 | - (NSString *)base64Encoding { 87 | if ([self length] == 0) 88 | return @""; 89 | 90 | char *characters = malloc((([self length] + 2) / 3) * 4); 91 | if (characters == NULL) 92 | return nil; 93 | NSUInteger length = 0; 94 | 95 | NSUInteger i = 0; 96 | while (i < [self length]) 97 | { 98 | char buffer[3] = {0,0,0}; 99 | short bufferLength = 0; 100 | while (bufferLength < 3 && i < [self length]) 101 | buffer[bufferLength++] = ((char *)[self bytes])[i++]; 102 | 103 | // Encode the bytes in the buffer to four characters, including padding "=" characters if necessary. 104 | characters[length++] = encodingTable[(buffer[0] & 0xFC) >> 2]; 105 | characters[length++] = encodingTable[((buffer[0] & 0x03) << 4) | ((buffer[1] & 0xF0) >> 4)]; 106 | if (bufferLength > 1) 107 | characters[length++] = encodingTable[((buffer[1] & 0x0F) << 2) | ((buffer[2] & 0xC0) >> 6)]; 108 | else characters[length++] = '='; 109 | if (bufferLength > 2) 110 | characters[length++] = encodingTable[buffer[2] & 0x3F]; 111 | else characters[length++] = '='; 112 | } 113 | 114 | NSString *str = [[[NSString alloc] initWithBytesNoCopy:characters length:length encoding:NSASCIIStringEncoding freeWhenDone:YES] autorelease]; 115 | return [str stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]]; 116 | } 117 | 118 | @end 119 | 120 | @implementation HRBase64 121 | + (NSString*) encode:(NSData *) rawBytes { 122 | return [rawBytes base64Encoding]; 123 | } 124 | @end 125 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/gh-unit-iphone/NSException+GHTestFailureExceptions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSException+GHTestFailureExceptions.h 3 | // 4 | // Created by Johannes Rudolph on 23.09.09. 5 | // Copyright 2009. All rights reserved. 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | // 30 | // Portions of this file fall under the following license, marked with: 31 | // GTM_BEGIN : GTM_END 32 | // 33 | // Copyright 2008 Google Inc. 34 | // 35 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not 36 | // use this file except in compliance with the License. You may obtain a copy 37 | // of the License at 38 | // 39 | // http://www.apache.org/licenses/LICENSE-2.0 40 | // 41 | // Unless required by applicable law or agreed to in writing, software 42 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 43 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 44 | // License for the specific language governing permissions and limitations under 45 | // the License. 46 | // 47 | 48 | extern NSString *const GHTestFilenameKey; 49 | extern NSString *const GHTestLineNumberKey; 50 | extern NSString *const GHTestFailureException; 51 | 52 | 53 | // GTM_BEGIN 54 | 55 | #import 56 | 57 | @interface NSException (GHUTestFailureExceptions) 58 | + (NSException *)ghu_failureInFile:(NSString *)filename 59 | atLine:(int)lineNumber 60 | withDescription:(NSString *)formatString, ...; 61 | + (NSException *)ghu_failureInCondition:(NSString *)condition 62 | isTrue:(BOOL)isTrue 63 | inFile:(NSString *)filename 64 | atLine:(int)lineNumber 65 | withDescription:(NSString *)formatString, ...; 66 | + (NSException *)ghu_failureInEqualityBetweenObject:(id)left 67 | andObject:(id)right 68 | inFile:(NSString *)filename 69 | atLine:(int)lineNumber 70 | withDescription:(NSString *)formatString, ...; 71 | + (NSException *)ghu_failureInEqualityBetweenValue:(NSValue *)left 72 | andValue:(NSValue *)right 73 | withAccuracy:(NSValue *)accuracy 74 | inFile:(NSString *)filename 75 | atLine:(int) ineNumber 76 | withDescription:(NSString *)formatString, ...; 77 | + (NSException *)ghu_failureInRaise:(NSString *)expression 78 | inFile:(NSString *)filename 79 | atLine:(int)lineNumber 80 | withDescription:(NSString *)formatString, ...; 81 | + (NSException *)ghu_failureInRaise:(NSString *)expression 82 | exception:(NSException *)exception 83 | inFile:(NSString *)filename 84 | atLine:(int)lineNumber 85 | withDescription:(NSString *)formatString, ...; 86 | @end 87 | 88 | // GTM_END -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/gh-unit-iphone/GHTestSuite.h: -------------------------------------------------------------------------------- 1 | // 2 | // GHTestSuite.h 3 | // GHUnit 4 | // 5 | // Created by Gabriel Handford on 1/25/09. 6 | // Copyright 2009. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import "GHTestGroup.h" 31 | 32 | /*! 33 | If set, will run it as a "test filter" like the env variable TEST. 34 | */ 35 | extern NSString *GHUnitTest; 36 | 37 | 38 | /*! 39 | Test suite is an alias for test group. 40 | 41 | A test case is an instance of a test case class with test methods. 42 | A test is a id which represents a target and a selector. 43 | A test group is a collection of tests; A collection of id (GHTest or GHTestGroup). 44 | 45 | For example, if you have 2 test cases, GHTestCase1 (with some test methods) and GHTestCase2 (with some test methods), 46 | your test suite might look like: 47 | 48 | "Tests" (GHTestSuite) 49 | GHTestGroup (collection of tests from GHTestCase1) 50 | - (void)testA1 (GHTest with target GHTestCase1 + testA1) 51 | - (void)testA2 (GHTest with target GHTestCase1 + testA2) 52 | GHTestGroup (collection of tests from GHTestCase2) 53 | - (void)testB1; (GHTest with target GHTestCase2 + testB1) 54 | - (void)testB2; (GHTest with target GHTestCase2 + testB2) 55 | 56 | */ 57 | @interface GHTestSuite : GHTestGroup { } 58 | 59 | /*! 60 | Create test suite with test cases. 61 | @param name Label to give the suite 62 | @param testCases Array of init'ed test case classes 63 | @param delegate 64 | */ 65 | - (id)initWithName:(NSString *)name testCases:(NSArray *)testCases delegate:(id)delegate; 66 | 67 | /*! 68 | Creates a suite of all tests. 69 | Will load all classes that subclass from GHTestCase, SenTestCase or GTMTestCase (or register test case class). 70 | @result Suite 71 | */ 72 | + (GHTestSuite *)allTests; 73 | 74 | /*! 75 | Create suite of tests with filter. 76 | This is useful for running a single test or all tests in a single test case. 77 | 78 | For example, 79 | 'GHSlowTest' -- Runs all test method in GHSlowTest 80 | 'GHSlowTest/testSlowA -- Only runs the test method testSlowA in GHSlowTest 81 | 82 | @param testFilter Test filter 83 | @result Suite 84 | */ 85 | + (GHTestSuite *)suiteWithTestFilter:(NSString *)testFilter; 86 | 87 | /*! 88 | Create suite of tests that start with prefix. 89 | @param prefix If test case class starts with the prefix; If nil or empty string, returns all tests 90 | @param options Compare options 91 | */ 92 | + (GHTestSuite *)suiteWithPrefix:(NSString *)prefix options:(NSStringCompareOptions)options; 93 | 94 | /*! 95 | Suite for a single test/method. 96 | @param testCaseClass 97 | @param method 98 | @result Suite 99 | */ 100 | + (GHTestSuite *)suiteWithTestCaseClass:(Class)testCaseClass method:(SEL)method; 101 | 102 | /*! 103 | Return test suite based on environment (TEST=TestFoo/foo) 104 | @result Suite 105 | */ 106 | + (GHTestSuite *)suiteFromEnv; 107 | 108 | @end 109 | 110 | @interface GHTestSuite (JUnitXML) 111 | 112 | - (BOOL)writeJUnitXML:(NSError **)error; 113 | 114 | @end 115 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/gh-unit-iphone/GHTesting.h: -------------------------------------------------------------------------------- 1 | // 2 | // GHTesting.h 3 | // GHUnit 4 | // 5 | // Created by Gabriel Handford on 1/30/09. 6 | // Copyright 2008 Gabriel Handford 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | // 31 | // Portions of this file fall under the following license, marked with: 32 | // GTM_BEGIN : GTM_END 33 | // 34 | // Copyright 2008 Google Inc. 35 | // 36 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not 37 | // use this file except in compliance with the License. You may obtain a copy 38 | // of the License at 39 | // 40 | // http://www.apache.org/licenses/LICENSE-2.0 41 | // 42 | // Unless required by applicable law or agreed to in writing, software 43 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 44 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 45 | // License for the specific language governing permissions and limitations under 46 | // the License. 47 | // 48 | 49 | extern NSString *GHUStackTraceFromException(NSException *e); 50 | 51 | // GTM_BEGIN 52 | BOOL isTestFixtureOfClass(Class aClass, Class testCaseClass); 53 | // GTM_END 54 | 55 | /*! 56 | Utility test for loading and running tests. 57 | @note Much of this is borrowed from GTM/UnitTesting. 58 | */ 59 | @interface GHTesting : NSObject { 60 | 61 | NSMutableArray/* of NSString*/ *testCaseClassNames_; 62 | 63 | } 64 | 65 | /*! 66 | The shared testing instance. 67 | */ 68 | + (GHTesting *)sharedInstance; 69 | 70 | /*! 71 | Load all test classes that we can "see". 72 | @result Array of initialized (and autoreleased) test case classes in an autoreleased array. 73 | */ 74 | - (NSArray *)loadAllTestCases; 75 | 76 | /*! 77 | Load tests from target. 78 | @result Array of id 79 | */ 80 | - (NSArray *)loadTestsFromTarget:(id)target; 81 | 82 | /*! 83 | See if class is of a registered test case class. 84 | */ 85 | - (BOOL)isTestCaseClass:(Class)aClass; 86 | 87 | /*! 88 | Register test case class. 89 | @param aClass 90 | */ 91 | - (void)registerClass:(Class)aClass; 92 | 93 | /*! 94 | Register test case class by name. 95 | @param className Class name (via NSStringFromClass(aClass) 96 | */ 97 | - (void)registerClassName:(NSString *)className; 98 | 99 | /*! 100 | Format test exception. 101 | @param exception 102 | @result Description 103 | */ 104 | + (NSString *)descriptionForException:(NSException *)exception; 105 | 106 | /*! 107 | Filename for cause of test exception. 108 | @param test 109 | @result Filename 110 | */ 111 | + (NSString *)exceptionFilenameForTest:(id)test; 112 | 113 | /*! 114 | Line number for cause of test exception. 115 | @param test 116 | @result Line number 117 | */ 118 | + (NSInteger)exceptionLineNumberForTest:(id)test; 119 | 120 | /*! 121 | Run test. 122 | @param target 123 | @param selector 124 | @param exception Exception, if set, is retained and should be released by the caller. 125 | @param interval Time to run the test 126 | @param reraiseExceptions If YES, will re-raise exceptions 127 | */ 128 | + (BOOL)runTestWithTarget:(id)target selector:(SEL)selector exception:(NSException **)exception 129 | interval:(NSTimeInterval *)interval reraiseExceptions:(BOOL)reraiseExceptions; 130 | 131 | /*! 132 | Same as normal runTest without catching exceptions. 133 | */ 134 | + (BOOL)runTestOrRaiseWithTarget:(id)target selector:(SEL)selector exception:(NSException **)exception interval:(NSTimeInterval *)interval; 135 | 136 | @end 137 | 138 | @protocol GHSenTestCase 139 | - (void)raiseAfterFailure; 140 | @end 141 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/gh-unit-iphone/GHAsyncTestCase.h: -------------------------------------------------------------------------------- 1 | // 2 | // GHAsyncTestCase.h 3 | // GHUnit 4 | // 5 | // Created by Gabriel Handford on 4/8/09. 6 | // Copyright 2009. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import "GHTestCase.h" 31 | 32 | // Some default statuses to use; Or define and use your own 33 | enum { 34 | kGHUnitWaitStatusUnknown = 0, 35 | kGHUnitWaitStatusSuccess, 36 | kGHUnitWaitStatusFailure, 37 | kGHUnitWaitStatusCancelled 38 | }; 39 | 40 | /*! 41 | Asynchronous test case with wait and notify. 42 | 43 | If notify occurs before wait has started (if it was a synchronous call), this test 44 | case will still work. 45 | 46 | Be sure to call prepare before the asynchronous method (otherwise an exception will raise). 47 | 48 | @code 49 | - (void)testSuccess { 50 | [self prepare]; 51 | 52 | // Do asynchronous task here 53 | [self performSelector:@selector(_succeed) withObject:nil afterDelay:0.1]; 54 | 55 | [self waitForStatus:kGHUnitWaitStatusSuccess timeout:1.0]; 56 | } 57 | 58 | - (void)_succeed { 59 | // Notice the forSelector points to the test above. This is so that 60 | // stray notifies don't error or falsely succeed other tests. 61 | // To ignore the check, forSelector can be NULL. 62 | [self notify:kGHUnitWaitStatusSuccess forSelector:@selector(testSuccess)]; 63 | } 64 | @endcode 65 | */ 66 | @interface GHAsyncTestCase : GHTestCase { 67 | 68 | NSInteger waitForStatus_; 69 | NSInteger notifiedStatus_; 70 | 71 | BOOL prepared_; // Whether prepared was called before waitForStatus:timeout: 72 | NSRecursiveLock *lock_; // Lock to synchronize on 73 | SEL waitSelector_; // The selector we are waiting on 74 | 75 | NSArray *_runLoopModes; 76 | } 77 | 78 | /*! 79 | Run loop modes to run while waiting; 80 | Defaults to NSDefaultRunLoopMode, NSRunLoopCommonModes, NSConnectionReplyMode 81 | */ 82 | @property (retain, nonatomic) NSArray *runLoopModes; 83 | 84 | /*! 85 | Prepare before calling the asynchronous method. 86 | */ 87 | - (void)prepare; 88 | 89 | /*! 90 | Prepare and specify the selector we will use in notify. 91 | 92 | @param selector 93 | */ 94 | - (void)prepare:(SEL)selector; 95 | 96 | /*! 97 | Wait for notification of status or timeout. 98 | 99 | Be sure to prepare before calling your asynchronous method. 100 | For example, 101 | 102 | @code 103 | - (void)testFoo { 104 | [self prepare]; 105 | // Do asynchronous task here 106 | [self waitForStatus:kGHUnitWaitStatusSuccess timeout:1.0]; 107 | } 108 | @endcode 109 | 110 | @param status kGHUnitWaitStatusSuccess, kGHUnitWaitStatusFailure or custom status 111 | @param timeout Timeout in seconds 112 | */ 113 | - (void)waitForStatus:(NSInteger)status timeout:(NSTimeInterval)timeout; 114 | 115 | // Deprecated 116 | - (void)waitFor:(NSInteger)status timeout:(NSTimeInterval)timeout; 117 | 118 | /*! 119 | Wait for timeout to occur. 120 | Fails if we did _NOT_ timeout. 121 | @param timeout 122 | */ 123 | - (void)waitForTimeout:(NSTimeInterval)timeout; 124 | 125 | /*! 126 | Notify waiting of status for test selector. 127 | @param status Status, for example, kGHUnitWaitStatusSuccess 128 | @param selector If not NULL, then will verify this selector is where we are waiting. 129 | This prevents stray asynchronous callbacks to fail a later test 130 | */ 131 | - (void)notify:(NSInteger)status forSelector:(SEL)selector; 132 | 133 | /*! 134 | Notify waiting of status for any selector. 135 | @param status Status, for example, kGHUnitWaitStatusSuccess 136 | */ 137 | - (void)notify:(NSInteger)status; 138 | 139 | @end 140 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/gh-unit-iphone/GHTestCase.h: -------------------------------------------------------------------------------- 1 | // 2 | // GHTestCase.h 3 | // GHUnit 4 | // 5 | // Created by Gabriel Handford on 1/21/09. 6 | // Copyright 2009. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | // 31 | // Portions of this file fall under the following license, marked with: 32 | // GTM_BEGIN : GTM_END 33 | // 34 | // Copyright 2008 Google Inc. 35 | // 36 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not 37 | // use this file except in compliance with the License. You may obtain a copy 38 | // of the License at 39 | // 40 | // http://www.apache.org/licenses/LICENSE-2.0 41 | // 42 | // Unless required by applicable law or agreed to in writing, software 43 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 44 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 45 | // License for the specific language governing permissions and limitations under 46 | // the License. 47 | // 48 | 49 | #import "GHTestMacros.h" 50 | #import "GHTest.h" 51 | 52 | // Log to your test case logger. 53 | // For example, GHTestLog(@"Some debug info, %@", obj) 54 | #define GHTestLog(...) [self log:[NSString stringWithFormat:__VA_ARGS__, nil]] 55 | 56 | /*! 57 | The base class for a test case. 58 | 59 | @code 60 | @interface MyTest : GHTestCase {} 61 | @end 62 | 63 | @implementation MyTest 64 | 65 | // Run before each test method 66 | - (void)setUp { } 67 | 68 | // Run after each test method 69 | - (void)tearDown { } 70 | 71 | // Run before the tests are run for this class 72 | - (void)setUpClass { } 73 | 74 | // Run before the tests are run for this class 75 | - (void)tearDownClass { } 76 | 77 | // Tests are prefixed by 'test' and contain no arguments and no return value 78 | - (void)testA { 79 | GHTestLog(@"Log with a test with the GHTestLog(...) for test specific logging."); 80 | } 81 | 82 | // Another test; Tests are run in lexical order 83 | - (void)testB { } 84 | 85 | // Override any exceptions; By default exceptions are raised, causing a test failure 86 | - (void)failWithException:(NSException *)exception { } 87 | 88 | @end 89 | @endcode 90 | 91 | */ 92 | @interface GHTestCase : NSObject { 93 | id logWriter_; // weak 94 | 95 | SEL currentSelector_; 96 | } 97 | 98 | //! The current test selector 99 | @property (assign, nonatomic) SEL currentSelector; 100 | @property (assign, nonatomic) id logWriter; 101 | 102 | // GTM_BEGIN 103 | //! Run before each test method 104 | - (void)setUp; 105 | 106 | //! Run after each test method 107 | - (void)tearDown; 108 | 109 | /*! 110 | By default exceptions are raised, causing a test failure 111 | @brief Override any exceptions 112 | @param exception Exception that was raised by test 113 | */ 114 | - (void)failWithException:(NSException*)exception; 115 | // GTM_END 116 | 117 | //! Run before the tests (once per test case) 118 | - (void)setUpClass; 119 | 120 | //! Run after the tests (once per test case) 121 | - (void)tearDownClass; 122 | 123 | /*! 124 | Whether to run the tests on a separate thread. Override this method in your 125 | test case to override the default. 126 | Default is NO, tests are run on a separate thread by default. 127 | @result If YES runs on the main thread 128 | */ 129 | - (BOOL)shouldRunOnMainThread; 130 | 131 | //! Any special handling of exceptions after they are thrown; By default logs stack trace to standard out. 132 | - (void)handleException:(NSException *)exception; 133 | 134 | /*! 135 | Log a message, which notifies the log delegate. 136 | This is not meant to be used directly, see GHTestLog(...) macro. 137 | @param message 138 | */ 139 | - (void)log:(NSString *)message; 140 | 141 | @end 142 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/JSON/SBJsonWriter.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009 Stig Brautaset. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the author nor the names of its contributors may be used 15 | to endorse or promote products derived from this software without specific 16 | prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #import 31 | #import "SBJsonBase.h" 32 | 33 | /** 34 | @brief Options for the writer class. 35 | 36 | This exists so the SBJSON facade can implement the options in the writer without having to re-declare them. 37 | */ 38 | @protocol SBJsonWriter 39 | 40 | /** 41 | @brief Whether we are generating human-readable (multiline) JSON. 42 | 43 | Set whether or not to generate human-readable JSON. The default is NO, which produces 44 | JSON without any whitespace. (Except inside strings.) If set to YES, generates human-readable 45 | JSON with linebreaks after each array value and dictionary key/value pair, indented two 46 | spaces per nesting level. 47 | */ 48 | @property BOOL humanReadable; 49 | 50 | /** 51 | @brief Whether or not to sort the dictionary keys in the output. 52 | 53 | If this is set to YES, the dictionary keys in the JSON output will be in sorted order. 54 | (This is useful if you need to compare two structures, for example.) The default is NO. 55 | */ 56 | @property BOOL sortKeys; 57 | 58 | /** 59 | @brief Return JSON representation (or fragment) for the given object. 60 | 61 | Returns a string containing JSON representation of the passed in value, or nil on error. 62 | If nil is returned and @p error is not NULL, @p *error can be interrogated to find the cause of the error. 63 | 64 | @param value any instance that can be represented as a JSON fragment 65 | 66 | */ 67 | - (NSString*)stringWithObject:(id)value; 68 | 69 | @end 70 | 71 | 72 | /** 73 | @brief The JSON writer class. 74 | 75 | Objective-C types are mapped to JSON types in the following way: 76 | 77 | @li NSNull -> Null 78 | @li NSString -> String 79 | @li NSArray -> Array 80 | @li NSDictionary -> Object 81 | @li NSNumber (-initWithBool:) -> Boolean 82 | @li NSNumber -> Number 83 | 84 | In JSON the keys of an object must be strings. NSDictionary keys need 85 | not be, but attempting to convert an NSDictionary with non-string keys 86 | into JSON will throw an exception. 87 | 88 | NSNumber instances created with the +initWithBool: method are 89 | converted into the JSON boolean "true" and "false" values, and vice 90 | versa. Any other NSNumber instances are converted to a JSON number the 91 | way you would expect. 92 | 93 | */ 94 | @interface SBJsonWriter : SBJsonBase { 95 | 96 | @private 97 | BOOL sortKeys, humanReadable; 98 | } 99 | 100 | @end 101 | 102 | // don't use - exists for backwards compatibility. Will be removed in 2.3. 103 | @interface SBJsonWriter (Private) 104 | - (NSString*)stringWithFragment:(id)value; 105 | @end 106 | 107 | /** 108 | @brief Allows generation of JSON for otherwise unsupported classes. 109 | 110 | If you have a custom class that you want to create a JSON representation for you can implement 111 | this method in your class. It should return a representation of your object defined 112 | in terms of objects that can be translated into JSON. For example, a Person 113 | object might implement it like this: 114 | 115 | @code 116 | - (id)jsonProxyObject { 117 | return [NSDictionary dictionaryWithObjectsAndKeys: 118 | name, @"name", 119 | phone, @"phone", 120 | email, @"email", 121 | nil]; 122 | } 123 | @endcode 124 | 125 | */ 126 | @interface NSObject (SBProxyForJson) 127 | - (id)proxyForJson; 128 | @end 129 | 130 | -------------------------------------------------------------------------------- /Source/Tests/Server/testserver.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | require 'sinatra' 3 | require 'sequel' 4 | require 'json' 5 | require 'faker' 6 | require 'pp' 7 | require 'builder' 8 | 9 | require File.join(File.dirname(__FILE__), 'lib/authorization') 10 | 11 | 12 | # Stupid hack so XmlSimple can use symbolized keys 13 | class Symbol 14 | def [](*args) 15 | to_s[*args] 16 | end 17 | end 18 | 19 | # connect to an in-memory database 20 | DB = Sequel.sqlite unless self.class.const_defined?('DB') 21 | 22 | 23 | begin 24 | DB.schema(:people) 25 | rescue 26 | # setup a people table 27 | DB.create_table :people do 28 | primary_key :id 29 | column :name, :text 30 | column :email, :text 31 | column :bio, :text 32 | column :address, :text 33 | column :telephone, :text 34 | column :created_at, :date 35 | end 36 | end 37 | 38 | # simple person model 39 | class Person < Sequel::Model 40 | plugin :validation_helpers 41 | 42 | def validate 43 | validates_presence([:name, :email, :address], {}) 44 | end 45 | 46 | def before_create 47 | self.created_at = Time.now 48 | end 49 | 50 | 51 | def self.respond(params) 52 | #edit or create 53 | if params[:id] 54 | person = self.find("id = ?", params[:id]) 55 | else 56 | person = self.new 57 | end 58 | data = {} #JSON.parse(params) 59 | if person.update(data) 60 | {:status => 200, :name => person.name} 61 | else 62 | {:status => 500} 63 | end 64 | end 65 | end 66 | 67 | # create some records using Faker 68 | if Person.count == 0 69 | 10.times do 70 | Person.create({ 71 | :name => Faker::Name.name, 72 | :email => Faker::Internet.email, 73 | :address => Faker::Address.street_address, 74 | :telephone => Faker::PhoneNumber.phone_number, 75 | :bio => Faker::Lorem.paragraph, 76 | :created_at => Time.now 77 | }) 78 | end 79 | end 80 | 81 | 82 | # Set every request to JSON 83 | before do 84 | #pp request.env 85 | def xml? 86 | request.env['CONTENT_TYPE'] == "application/xml" || 87 | request.env['REQUEST_URI'].split('.')[1] == 'xml' 88 | end 89 | # 90 | def json? 91 | request.env['CONTENT_TYPE'] == "application/json" || 92 | request.env['REQUEST_URI'].split('.')[1] == 'json' 93 | end 94 | 95 | def people_xml 96 | @people ||= Person.all.collect { |p| p.values} 97 | xml = Builder::XmlMarkup.new 98 | xml.people do 99 | @people.each do |per| 100 | xml.person do |p| 101 | p.name per[:name] 102 | p.email per[:email] 103 | p.address per[:address] 104 | p.telephone per[:telephone] 105 | p.bio per[:bio] 106 | p.created_at per[:created_at] 107 | end 108 | end 109 | end 110 | end 111 | 112 | if xml? 113 | content_type 'application/xml' 114 | elsif json? 115 | content_type 'application/json' 116 | end 117 | end 118 | 119 | #GET /status/500 returns the given status code 120 | get '/status/:code' do 121 | status params[:code].to_i 122 | end 123 | 124 | get '/search' do 125 | Person.filter('id < ?', params[:limit]).collect { |p| p.values }.to_json 126 | end 127 | 128 | #GET /people returns all posts as json 129 | get '/people*' do 130 | pp request 131 | @people = Person.all.collect { |p| p.values } 132 | 133 | if json? 134 | return @people.to_json 135 | elsif xml? 136 | return people_xml 137 | end 138 | 139 | erb :people 140 | end 141 | 142 | #GET /person/1 returns that post as json 143 | get '/person/:id' do 144 | pp "GETTING PERSON" 145 | Person.find("id = ?", params[:id]).values.to_json 146 | #Person.find(params[:id]).values.to_json 147 | end 148 | 149 | #PUT /person/1 update that puts with json 150 | put '/person/:id' do 151 | person = Person.find("id = ?", params[:id]) 152 | pp person 153 | data = JSON.parse(request.body.read) 154 | if person.update(data) 155 | person.values.to_json 156 | end 157 | end 158 | 159 | #POST /post body with data field set to JSON: { "title": "test", "body": "body test" } 160 | post '/person' do 161 | data = JSON.parse(request.body.read) 162 | if p = Person.create(data) 163 | status 201 164 | p.values.to_json 165 | end 166 | end 167 | 168 | post '/person/form-data' do 169 | if p = Person.create(params) 170 | status 201 171 | end 172 | 173 | redirect "/people" 174 | end 175 | 176 | #DELETE /post/1 deletes post 177 | delete '/person/delete/:id' do 178 | person = Person.find("id = ?", params[:id]) 179 | if person.destroy 180 | status 200 181 | person.values.to_json 182 | end 183 | end 184 | 185 | # Timeout 186 | get '/timeout' do 187 | sleep 40 188 | end 189 | 190 | include Sinatra::Authorization 191 | #BASIC AUTH 192 | get '/auth' do 193 | login_required 194 | Person.first.values.to_json 195 | end 196 | 197 | def authorize(username, password) 198 | username == "username@email.com" && password == "test" 199 | end 200 | 201 | def authorization_realm 202 | "HTTPRiot Basic Auth Testser" 203 | end -------------------------------------------------------------------------------- /Source/iPhoneSampleApp/ISAPeopleTableViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ISAPeopleTableViewController.m 3 | // HTTPRiot 4 | // 5 | // Created by Justin Palmer on 6/24/09. 6 | // Copyright 2009 LabratRevenge LLC.. All rights reserved. 7 | // 8 | 9 | #import "ISAPeopleTableViewController.h" 10 | #import "ISAPeopleDetailController.h" 11 | #import "ISAAlertHelper.h" 12 | #import 13 | 14 | @implementation ISAPeopleTableViewController 15 | 16 | - (void)dealloc { 17 | _indexPathOfItemToDelete = nil; 18 | [_people release]; 19 | [super dealloc]; 20 | } 21 | 22 | - (id)initWithStyle:(UITableViewStyle)style { 23 | // Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. 24 | if (self = [super initWithStyle:style]) { 25 | _people = [[NSMutableArray alloc] init]; 26 | _indexPathOfItemToDelete = nil; 27 | _isDeleting = NO; 28 | } 29 | return self; 30 | } 31 | 32 | - (void)viewDidLoad { 33 | [super viewDidLoad]; 34 | self.title = @"People"; 35 | self.navigationItem.rightBarButtonItem = self.editButtonItem; 36 | } 37 | 38 | - (void)restConnection:(NSURLConnection *)connection didReturnResource:(id)resource object:(id)object { 39 | if(_isDeleting) { 40 | [_people removeObjectAtIndex:_indexPathOfItemToDelete.row]; 41 | [self.tableView beginUpdates]; 42 | [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:_indexPathOfItemToDelete, nil] withRowAnimation:YES]; 43 | [self.tableView endUpdates]; 44 | [self.tableView reloadData]; 45 | _isDeleting = false; 46 | _indexPathOfItemToDelete = nil; 47 | } else { 48 | [_people removeAllObjects]; 49 | [_people addObjectsFromArray:resource]; 50 | [self.tableView reloadData]; 51 | } 52 | } 53 | 54 | - (void)restConnection:(NSURLConnection *)connection didFailWithError:(NSError *)error object:(id)object { 55 | if([error code] == -1004) 56 | ISAAlertWithMessage([NSString stringWithFormat:@"%@: Start the test server `ruby Source/Tests/Server/testserver.rb`", [error localizedDescription]]); 57 | } 58 | 59 | - (void)restConnection:(NSURLConnection *)connection didReceiveParseError:(NSError *)error responseBody:(NSString *)body object:(id)object { 60 | ISAAlertWithMessage([error localizedDescription]); 61 | } 62 | 63 | - (void)restConnection:(NSURLConnection *)connection didReceiveError:(NSError *)error response:(NSHTTPURLResponse *)response object:(id)object { 64 | ISAAlertWithMessage([error localizedDescription]); 65 | } 66 | 67 | - (void)restConnection:(NSURLConnection *)connection didReceiveResponse:(NSHTTPURLResponse *)response object:(id)object { 68 | NSLog(@"RESPONSE STATUS WAS:%i", [response statusCode]); 69 | } 70 | 71 | - (void)viewWillAppear:(BOOL)animated { 72 | [super viewWillAppear:animated]; 73 | self.tableView.delegate = self; 74 | 75 | [HRRestModel setDelegate:self]; 76 | [HRRestModel getPath:@"/people" withOptions:nil object:self]; 77 | } 78 | 79 | - (void)didReceiveMemoryWarning { 80 | [super didReceiveMemoryWarning]; 81 | } 82 | 83 | 84 | #pragma mark Table view methods 85 | - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 86 | NSDictionary *person = [_people objectAtIndex:indexPath.row]; 87 | 88 | _indexPathOfItemToDelete = indexPath; 89 | _isDeleting = YES; 90 | 91 | [HRRestModel deletePath:[NSString stringWithFormat:@"person/delete/%@", [person valueForKey:@"id"]] withOptions:nil object:nil]; 92 | } 93 | 94 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 95 | return 1; 96 | } 97 | 98 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 99 | return [_people count]; 100 | } 101 | 102 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 103 | 104 | static NSString *CellIdentifier = @"Cell"; 105 | 106 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 107 | if (cell == nil) { 108 | cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 109 | cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 110 | } 111 | 112 | cell.textLabel.text = [[_people objectAtIndex:indexPath.row] valueForKey:@"name"]; 113 | return cell; 114 | } 115 | 116 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 117 | // Navigation logic may go here. Create and push another view controller. 118 | ISAPeopleDetailController *peopleDetailController = [[ISAPeopleDetailController alloc] init]; 119 | peopleDetailController.person = [_people objectAtIndex:indexPath.row]; 120 | [self.navigationController pushViewController:peopleDetailController animated:YES]; 121 | [peopleDetailController release]; 122 | } 123 | 124 | @end -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/gh-unit-iphone/GHTestGroup.h: -------------------------------------------------------------------------------- 1 | // 2 | // GHTestGroup.h 3 | // 4 | // Created by Gabriel Handford on 1/16/09. 5 | // Copyright 2009. All rights reserved. 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import "GHTest.h" 30 | #import "GHTestCase.h" 31 | 32 | /*! 33 | @brief Interface for a group of tests. 34 | 35 | This group conforms to the GHTest protocol as well (see Composite pattern). 36 | */ 37 | @protocol GHTestGroup 38 | - (NSString *)name; 39 | - (id)parent; 40 | - (NSArray *)children; 41 | @end 42 | 43 | /*! 44 | @brief A collection of tests (or test groups). 45 | 46 | A test group is a collection of id, that may represent a set of test case methods. 47 | 48 | For example, if you had the following GHTestCase. 49 | 50 | @code 51 | @interface FooTest : GHTestCase {} 52 | - (void)testFoo; 53 | - (void)testBar; 54 | @end 55 | @endcode 56 | 57 | The GHTestGroup would consist of and array of GHTest, [FooTest#testFoo and FooTest#testBar], 58 | each test being a target and selector pair. 59 | 60 | A test group may also consist of a group of groups (since GHTestGroup conforms to GHTest), 61 | and this might represent a GHTestSuite. 62 | */ 63 | @interface GHTestGroup : NSObject { 64 | 65 | NSObject *delegate_; // weak 66 | id parent_; // weak 67 | 68 | NSMutableArray */*of id*/children_; 69 | 70 | NSString *name_; // The name of the test group (usually the class name of the test case 71 | NSTimeInterval interval_; // Total time of child tests 72 | GHTestStatus status_; // Current status of the group (current status of running or completed child tests) 73 | GHTestStats stats_; // Current stats for the group (aggregate of child test stats) 74 | 75 | BOOL didSetUpClass_; 76 | 77 | GHTestOptions options_; 78 | 79 | // Set if test is created from initWithTestCase:delegate: 80 | // Allows use to perform setUpClass and tearDownClass (once per test case run) 81 | id testCase_; 82 | 83 | NSException *exception_; // If exception happens in group setUpClass/tearDownClass 84 | } 85 | 86 | @property (readonly, nonatomic) NSArray */*of id*/children; 87 | @property (assign, nonatomic) id parent; 88 | @property (readonly, nonatomic) id testCase; 89 | @property (assign, nonatomic) GHTestOptions options; 90 | 91 | /*! 92 | Create an empty test group. 93 | @param name The name of the test group 94 | @param delegate Delegate, notifies of test start and end 95 | @result New test group 96 | */ 97 | - (id)initWithName:(NSString *)name delegate:(id)delegate; 98 | 99 | /*! 100 | Create test group from a test case. 101 | @param testCase Test case, could be a subclass of SenTestCase or GHTestCase 102 | @param delegate Delegate, notifies of test start and end 103 | @result New test group 104 | */ 105 | - (id)initWithTestCase:(id)testCase delegate:(id)delegate; 106 | 107 | /*! 108 | Create test group from a single test. 109 | @param testCase 110 | @param selector Test to run 111 | @param delegate 112 | */ 113 | - (id)initWithTestCase:(id)testCase selector:(SEL)selector delegate:(id)delegate; 114 | 115 | /*! 116 | Create test group from a test case. 117 | @param testCase Test case, could be a subclass of SenTestCase or GHTestCase 118 | @param delegate Delegate, notifies of test start and end 119 | @result New test group 120 | */ 121 | + (GHTestGroup *)testGroupFromTestCase:(id)testCase delegate:(id)delegate; 122 | 123 | /*! 124 | Add a test case (or test group) to this test group. 125 | @param testCase Test case, could be a subclass of SenTestCase or GHTestCase 126 | */ 127 | - (void)addTestCase:(id)testCase; 128 | 129 | - (void)addTestGroup:(GHTestGroup *)testGroup; 130 | 131 | - (void)addTests:(NSArray */*of id*/)tests; 132 | 133 | - (void)addTest:(id)test; 134 | 135 | - (BOOL)shouldRunOnMainThread; 136 | 137 | /*! 138 | Get list of failed tests. 139 | @result Failed tests 140 | */ 141 | - (NSArray */*of id*/)failedTests; 142 | 143 | /*! 144 | Run in operation queue. 145 | Tests from the group are added and will block until they have completed. 146 | @param operationQueue If nil, then runs as is 147 | @param options Options 148 | */ 149 | - (void)runInOperationQueue:(NSOperationQueue *)operationQueue options:(GHTestOptions)options; 150 | 151 | @end 152 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/AIXMLSerialization/AIXMLElementSerialize.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSXMLElement+Serialize.m 3 | // AIXMLSerialize 4 | // 5 | // Created by Justin Palmer on 2/24/09. 6 | // Copyright 2009 LabratRevenge LLC.. All rights reserved. 7 | // 8 | 9 | #import "AIXMLElementSerialize.h" 10 | 11 | @implementation NSXMLElement (Serialize) 12 | 13 | // Should this be configurable? Ruby's XmlSimple handles nodes with 14 | // string values and attributes by assigning the string value to a 15 | // 'content' key, although that seems like a pretty generic key which 16 | // could cause collisions if an element has a 'content' attribute. 17 | static NSString *contentItem; 18 | + (void)initialize 19 | { 20 | if(!contentItem) 21 | contentItem = @"content"; 22 | } 23 | 24 | - (NSDictionary *)attributesAsDictionary 25 | { 26 | NSArray *attributes = [self attributes]; 27 | NSMutableDictionary *result = [NSMutableDictionary dictionaryWithCapacity:[attributes count]]; 28 | 29 | uint i; 30 | for(i = 0; i < [attributes count]; i++) 31 | { 32 | NSXMLNode *node = [attributes objectAtIndex:i]; 33 | [result setObject:[node stringValue] forKey:[node name]]; 34 | } 35 | return result; 36 | } 37 | 38 | - (NSMutableDictionary *)toDictionary 39 | { 40 | id out, rawObj, nodeObj; 41 | NSXMLNode *node; 42 | NSArray *nodes = [self children]; 43 | NSString *elName = [self name], *key; 44 | NSDictionary *attrs = [self attributesAsDictionary]; 45 | NSString *type = [attrs valueForKey:@"type"]; 46 | NSMutableDictionary *groups = [NSMutableDictionary dictionary]; 47 | NSMutableArray *objs; 48 | 49 | for(node in nodes) 50 | { 51 | // It's an element, lets create the proper groups for these elements 52 | // consolidating any duplicate elements at this level. 53 | if([node kind] == NSXMLElementKind) 54 | { 55 | NSString *childName = [node name]; 56 | NSMutableArray *group = [groups objectForKey:childName]; 57 | if(!group) 58 | { 59 | group = [NSMutableArray array]; 60 | [groups setObject:group forKey:childName]; 61 | } 62 | 63 | [group addObject:node]; 64 | } 65 | 66 | // We're on a text node so the parent node will be this nodes name. 67 | // Once we get done parsing this text node we can go ahead and return 68 | // its dictionary rep because there is no need for further processing. 69 | else if([node kind] == NSXMLTextKind) 70 | { 71 | NSXMLElement *containerObj = (NSXMLElement *)[node parent]; 72 | NSDictionary *nodeAttrs = [containerObj attributesAsDictionary]; 73 | NSString *contents = [node stringValue]; 74 | 75 | 76 | // If this node has attributes and content text we need to 77 | // create a dictionary for it and use the static contentItem 78 | // value as a place to store the stringValue. 79 | if([nodeAttrs count] > 0 && contents) 80 | { 81 | nodeObj = [NSMutableDictionary dictionaryWithObject:contents forKey:contentItem]; 82 | [nodeObj addEntriesFromDictionary:nodeAttrs]; 83 | } 84 | // Else this node only has a string value or is empty so we set 85 | // it's value to a string. 86 | else 87 | { 88 | nodeObj = contents; 89 | } 90 | 91 | return [NSMutableDictionary dictionaryWithObject:nodeObj forKey:[containerObj name]]; 92 | } 93 | } 94 | 95 | // Array 96 | // We have an element who says it's children should be treated as an array. 97 | // Instead of creating {:child_name => {:other, :attrs}} children, we create 98 | // an array of anonymous dictionaries. [{:other, :attrs}, {:other, :attrs}] 99 | if([type isEqualToString:@"array"]) 100 | { 101 | out = [NSMutableArray array]; 102 | for(key in groups) 103 | { 104 | NSMutableDictionary *dictRep; 105 | objs = [groups objectForKey:key]; 106 | for(rawObj in objs) 107 | { 108 | dictRep = [rawObj toDictionary]; 109 | [out addObject:[dictRep valueForKey:key]]; 110 | } 111 | } 112 | } 113 | 114 | // Dictionary 115 | else 116 | { 117 | out = [NSMutableDictionary dictionary]; 118 | for(key in groups) 119 | { 120 | NSMutableDictionary *dictRep; 121 | objs = [groups objectForKey:key]; 122 | if([objs count] == 1) 123 | { 124 | dictRep = [[objs objectAtIndex:0] toDictionary]; 125 | [out addEntriesFromDictionary:dictRep]; 126 | } 127 | else 128 | { 129 | NSMutableArray *dictCollection = [NSMutableArray array]; 130 | for(rawObj in objs) 131 | { 132 | dictRep = [rawObj toDictionary]; 133 | id finalItems = [dictRep valueForKey:key]; 134 | [dictCollection addObject:finalItems]; 135 | } 136 | 137 | [out setObject:dictCollection forKey:key]; 138 | } 139 | } 140 | 141 | if([attrs count] > 0) 142 | [out addEntriesFromDictionary:attrs]; 143 | } 144 | 145 | return [NSMutableDictionary dictionaryWithObject:out forKey:elName]; 146 | } 147 | @end 148 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/gh-unit-iphone/GHTestRunner.h: -------------------------------------------------------------------------------- 1 | // 2 | // GHTestRunner.h 3 | // 4 | // Created by Gabriel Handford on 1/16/09. 5 | // Copyright 2008 Gabriel Handford 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | // 30 | // Portions of this file fall under the following license, marked with: 31 | // GTM_BEGIN : GTM_END 32 | // 33 | // Copyright 2008 Google Inc. 34 | // 35 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not 36 | // use this file except in compliance with the License. You may obtain a copy 37 | // of the License at 38 | // 39 | // http://www.apache.org/licenses/LICENSE-2.0 40 | // 41 | // Unless required by applicable law or agreed to in writing, software 42 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 43 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 44 | // License for the specific language governing permissions and limitations under 45 | // the License. 46 | // 47 | 48 | #import "GHTestGroup.h" 49 | #import "GHTestSuite.h" 50 | 51 | @class GHTestRunner; 52 | 53 | // Delegates can be guaranteed to be notified on the main thread (using #delegateOnMainThread) 54 | @protocol GHTestRunnerDelegate 55 | @optional 56 | - (void)testRunnerDidStart:(GHTestRunner *)runner; 57 | - (void)testRunner:(GHTestRunner *)runner didStartTest:(id)test; // Test started 58 | - (void)testRunner:(GHTestRunner *)runner didUpdateTest:(id)test; // Test changed 59 | - (void)testRunner:(GHTestRunner *)runner didEndTest:(id)test; // Test finished 60 | - (void)testRunnerDidCancel:(GHTestRunner *)runner; 61 | - (void)testRunnerDidEnd:(GHTestRunner *)runner; 62 | 63 | - (void)testRunner:(GHTestRunner *)runner didLog:(NSString *)message; // Runner logged message 64 | - (void)testRunner:(GHTestRunner *)runner test:(id)test didLog:(NSString *)message; // Test logged message 65 | @end 66 | 67 | /*! 68 | Runs the tests. 69 | Tests are run a separate thread though delegates are called on the 70 | main thread by default (see #delegateOnMainThread). 71 | */ 72 | @interface GHTestRunner : NSObject { 73 | 74 | id test_; // The test to run; Could be a GHTestGroup (suite), GHTestGroup (test case), or GHTest (target/selector) 75 | 76 | NSObject *delegate_; // weak 77 | 78 | GHTestOptions options_; 79 | 80 | BOOL running_; 81 | BOOL cancelling_; 82 | 83 | NSTimeInterval startInterval_; 84 | 85 | NSOperationQueue *operationQueue_; //! If running a suite in operation queue 86 | } 87 | 88 | @property (retain) id test; 89 | @property (assign) NSObject *delegate; 90 | @property (assign) GHTestOptions options; 91 | @property (readonly) GHTestStats stats; 92 | @property (readonly, getter=isRunning) BOOL running; 93 | @property (readonly, getter=isCancelling) BOOL cancelling; 94 | @property (readonly) NSTimeInterval interval; 95 | @property (retain, nonatomic) NSOperationQueue *operationQueue; 96 | 97 | 98 | /*! 99 | Create runner for test. 100 | @param test 101 | */ 102 | - (id)initWithTest:(id)test; 103 | 104 | /*! 105 | Create runner for all tests. 106 | @see GHTesting#loadAllTestCases. 107 | @result Runner 108 | */ 109 | + (GHTestRunner *)runnerForAllTests; 110 | 111 | /*! 112 | Create runner for test suite. 113 | @param suite 114 | @result Runner 115 | */ 116 | + (GHTestRunner *)runnerForSuite:(GHTestSuite *)suite; 117 | 118 | /*! 119 | Create runner for class and method. 120 | @param testClassName 121 | @param methodName 122 | @result Runner 123 | */ 124 | + (GHTestRunner *)runnerForTestClassName:(NSString *)testClassName methodName:(NSString *)methodName; 125 | 126 | /*! 127 | Get the runner from the environment. 128 | If the TEST env is set, then we will only run that test case or test method. 129 | */ 130 | + (GHTestRunner *)runnerFromEnv; 131 | 132 | /*! 133 | Run the test runner. Usually called from the test main. 134 | Reads the TEST environment variable and filters on that; or all tests are run. 135 | @result 0 is success, otherwise the failure count 136 | */ 137 | + (int)run; 138 | 139 | - (void)runInBackground; 140 | 141 | /*! 142 | Start the test runner with the default test. 143 | @result 0 is success, otherwise the failure count 144 | */ 145 | - (int)runTests; 146 | 147 | - (void)cancel; 148 | 149 | - (void)setInParallel:(BOOL)inParallel; 150 | - (BOOL)isInParallel; 151 | 152 | /*! 153 | Write message to console. 154 | */ 155 | - (void)log:(NSString *)message; 156 | 157 | @end 158 | 159 | 160 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/KissXML/DDXMLNode.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | @class DDXMLDocument; 5 | 6 | 7 | enum { 8 | DDXMLInvalidKind = 0, 9 | DDXMLDocumentKind = XML_DOCUMENT_NODE, 10 | DDXMLElementKind = XML_ELEMENT_NODE, 11 | DDXMLAttributeKind = XML_ATTRIBUTE_NODE, 12 | DDXMLNamespaceKind = XML_NAMESPACE_DECL, 13 | DDXMLProcessingInstructionKind = XML_PI_NODE, 14 | DDXMLCommentKind = XML_COMMENT_NODE, 15 | DDXMLTextKind = XML_TEXT_NODE, 16 | DDXMLDTDKind = XML_DTD_NODE, 17 | DDXMLEntityDeclarationKind = XML_ENTITY_DECL, 18 | DDXMLAttributeDeclarationKind = XML_ATTRIBUTE_DECL, 19 | DDXMLElementDeclarationKind = XML_ELEMENT_DECL, 20 | DDXMLNotationDeclarationKind = XML_NOTATION_NODE 21 | }; 22 | typedef NSUInteger DDXMLNodeKind; 23 | 24 | enum { 25 | DDXMLNodeOptionsNone = 0, 26 | DDXMLNodeExpandEmptyElement = 1 << 1, 27 | DDXMLNodeCompactEmptyElement = 1 << 2, 28 | DDXMLNodePrettyPrint = 1 << 17, 29 | }; 30 | 31 | /** 32 | * DDXMLNode can represent several underlying types, such as xmlNodePtr, xmlDocPtr, xmlAttrPtr, xmlNsPtr, etc. 33 | * All of these are pointers to structures, and all of those structures start with a pointer, and a type. 34 | * The xmlKind struct is used as a generic structure, and a stepping stone. 35 | * We use it to check the type of a structure, and then perform the appropriate cast. 36 | * 37 | * For example: 38 | * if(genericPtr->type == XML_ATTRIBUTE_NODE) 39 | * { 40 | * xmlAttrPtr attr = (xmlAttrPtr)genericPtr; 41 | * // Do something with attr 42 | * } 43 | **/ 44 | struct _xmlKind { 45 | void * ignore; 46 | xmlElementType type; 47 | }; 48 | typedef struct _xmlKind *xmlKindPtr; 49 | 50 | /** 51 | * Most xml types all start with this standard structure. In fact, all do except the xmlNsPtr. 52 | * We will occasionally take advantage of this to simplify code when the code wouldn't vary from type to type. 53 | * Obviously, you cannnot cast a xmlNsPtr to a xmlStdPtr. 54 | **/ 55 | struct _xmlStd { 56 | void * _private; 57 | xmlElementType type; 58 | const xmlChar *name; 59 | struct _xmlNode *children; 60 | struct _xmlNode *last; 61 | struct _xmlNode *parent; 62 | struct _xmlStd *next; 63 | struct _xmlStd *prev; 64 | struct _xmlDoc *doc; 65 | }; 66 | typedef struct _xmlStd *xmlStdPtr; 67 | 68 | @interface DDXMLNode : NSObject 69 | { 70 | // Every DDXML object is simply a wrapper around an underlying libxml node 71 | xmlKindPtr genericPtr; 72 | 73 | // The xmlNsPtr type doesn't store a reference to it's parent 74 | // This is here to fix that problem, and make this class more compatible with the NSXML classes 75 | xmlNodePtr nsParentPtr; 76 | } 77 | 78 | //- (id)initWithKind:(DDXMLNodeKind)kind; 79 | 80 | //- (id)initWithKind:(DDXMLNodeKind)kind options:(NSUInteger)options; 81 | 82 | //+ (id)document; 83 | 84 | //+ (id)documentWithRootElement:(DDXMLElement *)element; 85 | 86 | + (id)elementWithName:(NSString *)name; 87 | 88 | + (id)elementWithName:(NSString *)name URI:(NSString *)URI; 89 | 90 | + (id)elementWithName:(NSString *)name stringValue:(NSString *)string; 91 | 92 | + (id)elementWithName:(NSString *)name children:(NSArray *)children attributes:(NSArray *)attributes; 93 | 94 | + (id)attributeWithName:(NSString *)name stringValue:(NSString *)stringValue; 95 | 96 | + (id)attributeWithName:(NSString *)name URI:(NSString *)URI stringValue:(NSString *)stringValue; 97 | 98 | + (id)namespaceWithName:(NSString *)name stringValue:(NSString *)stringValue; 99 | 100 | + (id)processingInstructionWithName:(NSString *)name stringValue:(NSString *)stringValue; 101 | 102 | + (id)commentWithStringValue:(NSString *)stringValue; 103 | 104 | + (id)textWithStringValue:(NSString *)stringValue; 105 | 106 | //+ (id)DTDNodeWithXMLString:(NSString *)string; 107 | 108 | #pragma mark --- Properties --- 109 | 110 | - (DDXMLNodeKind)kind; 111 | 112 | - (void)setName:(NSString *)name; 113 | - (NSString *)name; 114 | 115 | //- (void)setObjectValue:(id)value; 116 | //- (id)objectValue; 117 | 118 | - (void)setStringValue:(NSString *)string; 119 | //- (void)setStringValue:(NSString *)string resolvingEntities:(BOOL)resolve; 120 | - (NSString *)stringValue; 121 | 122 | #pragma mark --- Tree Navigation --- 123 | 124 | - (NSUInteger)index; 125 | 126 | - (NSUInteger)level; 127 | 128 | - (DDXMLDocument *)rootDocument; 129 | 130 | - (DDXMLNode *)parent; 131 | - (NSUInteger)childCount; 132 | - (NSArray *)children; 133 | - (DDXMLNode *)childAtIndex:(NSUInteger)index; 134 | 135 | - (DDXMLNode *)previousSibling; 136 | - (DDXMLNode *)nextSibling; 137 | 138 | - (DDXMLNode *)previousNode; 139 | - (DDXMLNode *)nextNode; 140 | 141 | - (void)detach; 142 | 143 | - (NSString *)XPath; 144 | 145 | #pragma mark --- QNames --- 146 | 147 | - (NSString *)localName; 148 | - (NSString *)prefix; 149 | 150 | - (void)setURI:(NSString *)URI; 151 | - (NSString *)URI; 152 | 153 | + (NSString *)localNameForName:(NSString *)name; 154 | + (NSString *)prefixForName:(NSString *)name; 155 | //+ (DDXMLNode *)predefinedNamespaceForPrefix:(NSString *)name; 156 | 157 | #pragma mark --- Output --- 158 | 159 | - (NSString *)description; 160 | - (NSString *)XMLString; 161 | - (NSString *)XMLStringWithOptions:(NSUInteger)options; 162 | //- (NSString *)canonicalXMLStringPreservingComments:(BOOL)comments; 163 | 164 | #pragma mark --- XPath/XQuery --- 165 | 166 | - (NSArray *)nodesForXPath:(NSString *)xpath error:(NSError **)error; 167 | //- (NSArray *)objectsForXQuery:(NSString *)xquery constants:(NSDictionary *)constants error:(NSError **)error; 168 | //- (NSArray *)objectsForXQuery:(NSString *)xquery error:(NSError **)error; 169 | 170 | @end 171 | -------------------------------------------------------------------------------- /Source/HTTPRiot/HRRestModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // HRRestModel.m 3 | // HTTPRiot 4 | // 5 | // Created by Justin Palmer on 1/28/09. 6 | // Copyright 2009 LabratRevenge LLC.. All rights reserved. 7 | // 8 | 9 | #import "HRRestModel.h" 10 | #import "HRRequestOperation.h" 11 | #import "HRGlobal.h" 12 | 13 | @interface HRRestModel (PrivateMethods) 14 | + (void)setAttributeValue:(id)attr forKey:(NSString *)key; 15 | + (NSMutableDictionary *)classAttributes; 16 | + (NSMutableDictionary *)mergedOptions:(NSDictionary *)options; 17 | + (NSOperation *)requestWithMethod:(HRRequestMethod)method path:(NSString *)path options:(NSDictionary *)options object:(id)obj; 18 | @end 19 | 20 | @implementation HRRestModel 21 | static NSMutableDictionary *attributes; 22 | + (void)initialize { 23 | if(!attributes) 24 | attributes = [[NSMutableDictionary alloc] init]; 25 | } 26 | 27 | //////////////////////////////////////////////////////////////////////////////////////////////////// 28 | #pragma mark - Class Attributes 29 | 30 | // Given that we want to allow classes to define default attributes we need to create 31 | // a classname-based dictionary store that maps a subclass name to a dictionary 32 | // containing its attributes. 33 | + (NSMutableDictionary *)classAttributes { 34 | NSString *className = NSStringFromClass([self class]); 35 | 36 | NSMutableDictionary *newDict; 37 | NSMutableDictionary *dict = [attributes objectForKey:className]; 38 | 39 | if(dict) { 40 | return dict; 41 | } else { 42 | newDict = [NSMutableDictionary dictionaryWithObject:[NSNumber numberWithInt:HRDataFormatJSON] forKey:@"format"]; 43 | [attributes setObject:newDict forKey:className]; 44 | } 45 | 46 | return newDict; 47 | } 48 | 49 | + (NSObject *)delegate { 50 | return [[self classAttributes] objectForKey:kHRClassAttributesDelegateKey]; 51 | } 52 | 53 | + (void)setDelegate:(NSObject *)del { 54 | [self setAttributeValue:[NSValue valueWithNonretainedObject:del] forKey:kHRClassAttributesDelegateKey]; 55 | } 56 | 57 | + (NSURL *)baseURL { 58 | return [[self classAttributes] objectForKey:kHRClassAttributesBaseURLKey]; 59 | } 60 | 61 | + (void)setBaseURL:(NSURL *)uri { 62 | [self setAttributeValue:uri forKey:kHRClassAttributesBaseURLKey]; 63 | } 64 | 65 | + (NSDictionary *)headers { 66 | return [[self classAttributes] objectForKey:kHRClassAttributesHeadersKey]; 67 | } 68 | 69 | + (void)setHeaders:(NSDictionary *)hdrs { 70 | [self setAttributeValue:hdrs forKey:kHRClassAttributesHeadersKey]; 71 | } 72 | 73 | + (NSDictionary *)basicAuth { 74 | return [[self classAttributes] objectForKey:kHRClassAttributesBasicAuthKey]; 75 | } 76 | 77 | + (void)setBasicAuthWithUsername:(NSString *)username password:(NSString *)password { 78 | NSDictionary *authDict = [NSDictionary dictionaryWithObjectsAndKeys:username, kHRClassAttributesUsernameKey, password, kHRClassAttributesPasswordKey, nil]; 79 | [self setAttributeValue:authDict forKey:kHRClassAttributesBasicAuthKey]; 80 | } 81 | 82 | + (HRDataFormat)format { 83 | return [[[self classAttributes] objectForKey:kHRClassAttributesFormatKey] intValue]; 84 | } 85 | 86 | + (void)setFormat:(HRDataFormat)format { 87 | [[self classAttributes] setValue:[NSNumber numberWithInt:format] forKey:kHRClassAttributesFormatKey]; 88 | } 89 | 90 | + (NSDictionary *)defaultParams { 91 | return [[self classAttributes] objectForKey:kHRClassAttributesDefaultParamsKey]; 92 | } 93 | 94 | + (void)setDefaultParams:(NSDictionary *)params { 95 | [self setAttributeValue:params forKey:kHRClassAttributesDefaultParamsKey]; 96 | } 97 | 98 | + (void)setAttributeValue:(id)attr forKey:(NSString *)key { 99 | [[self classAttributes] setObject:attr forKey:key]; 100 | } 101 | 102 | //////////////////////////////////////////////////////////////////////////////////////////////////// 103 | #pragma mark - REST Methods 104 | 105 | + (NSOperation *)getPath:(NSString *)path withOptions:(NSDictionary *)options object:(id)obj { 106 | return [self requestWithMethod:HRRequestMethodGet path:path options:options object:obj]; 107 | } 108 | 109 | + (NSOperation *)postPath:(NSString *)path withOptions:(NSDictionary *)options object:(id)obj { 110 | return [self requestWithMethod:HRRequestMethodPost path:path options:options object:obj]; 111 | } 112 | 113 | + (NSOperation *)putPath:(NSString *)path withOptions:(NSDictionary *)options object:(id)obj { 114 | return [self requestWithMethod:HRRequestMethodPut path:path options:options object:obj]; 115 | } 116 | 117 | + (NSOperation *)deletePath:(NSString *)path withOptions:(NSDictionary *)options object:(id)obj { 118 | return [self requestWithMethod:HRRequestMethodDelete path:path options:options object:obj]; 119 | } 120 | 121 | //////////////////////////////////////////////////////////////////////////////////////////////////// 122 | #pragma mark - Private 123 | 124 | + (NSOperation *)requestWithMethod:(HRRequestMethod)method path:(NSString *)path options:(NSDictionary *)options object:(id)obj { 125 | NSMutableDictionary *opts = [self mergedOptions:options]; 126 | return [HRRequestOperation requestWithMethod:method path:path options:opts object:obj]; 127 | } 128 | 129 | + (NSMutableDictionary *)mergedOptions:(NSDictionary *)options { 130 | NSMutableDictionary *defaultParams = [NSMutableDictionary dictionaryWithDictionary:[self defaultParams]]; 131 | [defaultParams addEntriesFromDictionary:[options valueForKey:kHRClassAttributesParamsKey]]; 132 | 133 | options = [NSMutableDictionary dictionaryWithDictionary:options]; 134 | [(NSMutableDictionary *)options setObject:defaultParams forKey:kHRClassAttributesParamsKey]; 135 | NSMutableDictionary *opts = [NSMutableDictionary dictionaryWithDictionary:[self classAttributes]]; 136 | [opts addEntriesFromDictionary:options]; 137 | [opts removeObjectForKey:kHRClassAttributesDefaultParamsKey]; 138 | 139 | return opts; 140 | } 141 | @end 142 | -------------------------------------------------------------------------------- /Source/Tests/HTTPRiotRequestTest.m: -------------------------------------------------------------------------------- 1 | // 2 | // HTTPRiotRequestOperationTest.m 3 | // HTTPRiot 4 | // 5 | // Created by Justin Palmer on 2/11/09. 6 | // Copyright 2009 Alternateidea. All rights reserved. 7 | // 8 | #import 9 | #import "HTTPRiotTestHelper.h" 10 | #import "HRFormatJSON.h" 11 | 12 | @interface HRRequestOperationTest : GHAsyncTestCase { 13 | } 14 | @end 15 | 16 | @implementation HRRequestOperationTest 17 | 18 | - (void)setUpClass { 19 | [HRTestPerson2 setDelegate:self]; 20 | } 21 | 22 | // - (void)testShouldHandleTimeout { 23 | // [self prepare]; 24 | // [HRTestPerson2 getPath:@"/timeout" withOptions:nil object:@"Timeout"]; 25 | // [self waitForStatus:kGHUnitWaitStatusFailure timeout:40.0]; 26 | // } 27 | 28 | - (void)testShouldHandleGET { 29 | [self prepare]; 30 | [HRTestPerson2 getPath:@"/people.json" withOptions:nil object:@"GET"]; 31 | [self waitForStatus:kGHUnitWaitStatusSuccess timeout:10.0]; 32 | } 33 | 34 | - (void)testShouldHandlePOST { 35 | [self prepare]; 36 | NSDictionary *body = [NSDictionary dictionaryWithObjectsAndKeys:@"bob", @"name", 37 | @"foo@email.com", @"email", 38 | @"101 Cherry Lane", @"address", nil]; 39 | HRFormatJSON *json = [[[HRFormatJSON alloc] init] autorelease]; 40 | id bodyData = [json encode:body error:nil]; 41 | NSDictionary *opts = [NSDictionary dictionaryWithObject:bodyData forKey:@"body"]; 42 | 43 | [HRTestPerson2 postPath:@"/person" withOptions:opts object:@"POST"]; 44 | [self waitForStatus:kGHUnitWaitStatusSuccess timeout:10.0]; 45 | } 46 | 47 | - (void)testShouldHandlePUT { 48 | [self prepare]; 49 | NSDictionary *body = [NSDictionary dictionaryWithObjectsAndKeys:@"bob", @"name", 50 | @"foo@email.com", @"email", 51 | @"101 Cherry Lane", @"address", nil]; 52 | HRFormatJSON *json = [[[HRFormatJSON alloc] init] autorelease]; 53 | NSString *bodyData = [[json encode:body error:nil] copy]; 54 | NSDictionary *opts = [[NSDictionary alloc ] initWithObjectsAndKeys:bodyData, @"body", nil]; 55 | [bodyData release]; 56 | 57 | [HRTestPerson2 putPath:@"/person/1" withOptions:opts object:@"PUT"]; 58 | [self waitForStatus:kGHUnitWaitStatusSuccess timeout:10.0]; 59 | [opts release]; 60 | } 61 | 62 | - (void)testShouldHandleDELETE { 63 | [self prepare]; 64 | [HRTestPerson2 deletePath:@"/person/delete/5" withOptions:nil object:@"DELETE"]; 65 | [self waitForStatus:kGHUnitWaitStatusSuccess timeout:10.0]; 66 | } 67 | 68 | - (void)testShouldHandleBasicAuth { 69 | [self prepare]; 70 | 71 | NSDictionary *auth = [NSDictionary dictionaryWithObjectsAndKeys:@"username@email.com", @"username", @"test", @"password", nil]; 72 | NSDictionary *opts = [NSDictionary dictionaryWithObject:auth forKey:@"basicAuth"]; 73 | 74 | [HRTestPerson2 getPath:@"/auth" withOptions:opts object:@"BasicAuth"]; 75 | [self waitForStatus:kGHUnitWaitStatusSuccess timeout:10.0]; 76 | } 77 | 78 | // TODO: Timeout-based tests seem to be having problems on the new GHUnit 79 | // - (void)testShouldHandleCanceledRequest { 80 | // NSOperation *op = [HRTestPerson2 getPath:@"/timeout" withOptions:nil object:@"CanceledRequest"]; 81 | // [op cancel]; 82 | // GHAssertTrue([op isCancelled], nil); 83 | // } 84 | 85 | // - (void)testShouldCancelAllRequests { 86 | // [HRTestPerson2 getPath:@"/timeout" withOptions:nil object:nil]; 87 | // [HRTestPerson2 getPath:@"/timeout" withOptions:nil object:nil]; 88 | // [HRTestPerson2 getPath:@"/timeout" withOptions:nil object:nil]; 89 | // 90 | // [[HROperationQueue sharedOperationQueue] cancelAllOperations]; 91 | // GHAssertTrue([[[HROperationQueue sharedOperationQueue] operations] count] == 0, nil); 92 | // } 93 | 94 | - (void)testShouldHandleFormattingXML { 95 | [self prepare]; 96 | NSDictionary *opts = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:1] forKey:@"format"]; 97 | [HRTestPerson2 getPath:@"/people.xml" withOptions:opts object:@"FormattingXML"]; 98 | [self waitForStatus:kGHUnitWaitStatusSuccess timeout:10.0]; 99 | } 100 | 101 | - (void)testShouldHandleFormattingJSON { 102 | [self prepare]; 103 | NSDictionary *opts = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:0] forKey:@"format"]; 104 | [HRTestPerson2 getPath:@"/people.json" withOptions:opts object:@"FormattingJSON"]; 105 | [self waitForStatus:kGHUnitWaitStatusSuccess timeout:10.0]; 106 | } 107 | 108 | - (void)restConnection:(NSURLConnection *)connection didReturnResource:(id)resource object:(id)method { 109 | NSString *prefix = @"testShouldHandle"; 110 | NSString *selector = [prefix stringByAppendingString:method]; 111 | [self notify:kGHUnitWaitStatusSuccess forSelector:NSSelectorFromString(selector)]; 112 | } 113 | 114 | - (void)restConnection:(NSURLConnection *)connection didFailWithError:(NSError *)error object:(id)method { 115 | if(method) { 116 | NSString *prefix = @"testShouldHandle"; 117 | NSString *selector = [prefix stringByAppendingString:method]; 118 | [self notify:kGHUnitWaitStatusFailure forSelector:NSSelectorFromString(selector)]; 119 | } 120 | } 121 | 122 | - (void)restConnection:(NSURLConnection *)connection didReceiveError:(NSError *)error response:(NSHTTPURLResponse *)response object:(id)method { 123 | NSString *prefix = @"testShouldHandle"; 124 | NSString *selector = [prefix stringByAppendingString:method]; 125 | [self notify:kGHUnitWaitStatusFailure forSelector:NSSelectorFromString(selector)]; 126 | } 127 | 128 | - (void)restConnection:(NSURLConnection *)connection didReceiveParseError:(NSError *)error responseBody:(NSString *)string object:(id)method { 129 | NSString *prefix = @"testShouldHandle"; 130 | NSString *selector = [prefix stringByAppendingString:method]; 131 | [self notify:kGHUnitWaitStatusFailure forSelector:NSSelectorFromString(selector)]; 132 | } 133 | @end 134 | -------------------------------------------------------------------------------- /Source/HTTPRiot/Vendor/gh-unit-iphone/GHTest.h: -------------------------------------------------------------------------------- 1 | // 2 | // GHTest.h 3 | // GHKit 4 | // 5 | // Created by Gabriel Handford on 1/18/09. 6 | // Copyright 2009. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | /*! 31 | Test status. 32 | */ 33 | typedef enum { 34 | GHTestStatusNone = 0, 35 | GHTestStatusRunning, // Test is running 36 | GHTestStatusCancelling, // Test is being cancelled 37 | GHTestStatusCancelled, // Test was cancelled 38 | GHTestStatusSucceeded, // Test finished and succeeded 39 | GHTestStatusErrored, // Test finished and errored 40 | } GHTestStatus; 41 | 42 | enum { 43 | GHTestOptionReraiseExceptions = 1 << 0, // Allows exceptions to be raised (so you can trigger the debugger) 44 | GHTestOptionForceSetUpTearDownClass = 1 << 1, // Runs setUpClass/tearDownClass for this (each) test; Used when re-running a single test in a group 45 | }; 46 | typedef NSInteger GHTestOptions; 47 | 48 | /*! 49 | Generate string from GHTestStatus 50 | @param status 51 | */ 52 | extern NSString* NSStringFromGHTestStatus(GHTestStatus status); 53 | 54 | /*! 55 | Check if test is running (or trying to cancel). 56 | */ 57 | extern BOOL GHTestStatusIsRunning(GHTestStatus status); 58 | 59 | /*! 60 | Check if test has succeeded, errored or cancelled. 61 | */ 62 | extern BOOL GHTestStatusEnded(GHTestStatus status); 63 | 64 | /*! 65 | Test stats. 66 | */ 67 | typedef struct { 68 | NSInteger succeedCount; // Number of succeeded tests 69 | NSInteger failureCount; // Number of failed tests 70 | NSInteger cancelCount; // Number of aborted tests 71 | NSInteger testCount; // Total number of tests 72 | } GHTestStats; 73 | 74 | /*! 75 | Create GHTestStats. 76 | */ 77 | extern GHTestStats GHTestStatsMake(NSInteger succeedCount, NSInteger failureCount, NSInteger cancelCount, NSInteger testCount); 78 | 79 | extern const GHTestStats GHTestStatsEmpty; 80 | 81 | extern NSString *NSStringFromGHTestStats(GHTestStats stats); 82 | 83 | @protocol GHTestDelegate; 84 | 85 | /*! 86 | The base interface for a runnable test. 87 | A runnable with a unique identifier, display name, stats, timer, delegate, log and error handling. 88 | */ 89 | @protocol GHTest 90 | 91 | - (void)run:(GHTestOptions)options; 92 | 93 | @property (readonly, nonatomic) NSString *identifier; // Unique identifier for test 94 | @property (readonly, nonatomic) NSString *name; 95 | @property (assign, nonatomic) NSTimeInterval interval; 96 | @property (assign, nonatomic) GHTestStatus status; 97 | @property (readonly, nonatomic) GHTestStats stats; 98 | @property (retain, nonatomic) NSException *exception; 99 | @property (assign, nonatomic, getter=isDisabled) BOOL disabled; 100 | @property (assign, nonatomic, getter=isHidden) BOOL hidden; 101 | @property (assign, nonatomic) id delegate; // weak 102 | 103 | - (NSArray *)log; 104 | 105 | - (void)reset; 106 | - (void)cancel; 107 | 108 | - (NSInteger)disabledCount; 109 | 110 | @end 111 | 112 | /*! 113 | Test delegate for notification when a test starts and ends. 114 | */ 115 | @protocol GHTestDelegate 116 | - (void)testDidStart:(id)test source:(id)source; 117 | - (void)testDidUpdate:(id)test source:(id)source; 118 | - (void)testDidEnd:(id)test source:(id)source; 119 | - (void)test:(id)test didLog:(NSString *)message source:(id)source; 120 | @end 121 | 122 | /*! 123 | Delegate which is notified of log messages from inside GHTestCase. 124 | */ 125 | @protocol GHTestCaseLogWriter 126 | - (void)log:(NSString *)message testCase:(id)testCase; 127 | @end 128 | 129 | /*! 130 | Default test implementation with a target/selector pair. 131 | - Tests a target and selector 132 | - Notifies a test delegate 133 | - Keeps track of status, running time and failures 134 | - Stores any test specific logging 135 | */ 136 | @interface GHTest : NSObject { 137 | 138 | NSObject *delegate_; // weak 139 | 140 | id target_; 141 | SEL selector_; 142 | 143 | NSString *identifier_; 144 | NSString *name_; 145 | GHTestStatus status_; 146 | NSTimeInterval interval_; 147 | BOOL disabled_; 148 | BOOL hidden_; 149 | NSException *exception_; // If failed 150 | 151 | NSMutableArray *log_; 152 | 153 | } 154 | 155 | @property (readonly, nonatomic) id target; 156 | @property (readonly, nonatomic) SEL selector; 157 | @property (readonly, nonatomic) NSArray *log; 158 | 159 | /*! 160 | Create test with identifier, name. 161 | @param identifier Unique identifier 162 | @param name Name 163 | */ 164 | - (id)initWithIdentifier:(NSString *)identifier name:(NSString *)name; 165 | 166 | /*! 167 | Create test with target/selector. 168 | @param target Target (usually a test case) 169 | @param selector Selector (usually a test method) 170 | */ 171 | - (id)initWithTarget:(id)target selector:(SEL)selector; 172 | 173 | /*! 174 | Create autoreleased test with target/selector. 175 | @param target Target (usually a test case) 176 | @param selector Selector (usually a test method) 177 | */ 178 | + (id)testWithTarget:(id)target selector:(SEL)selector; 179 | 180 | @end 181 | 182 | -------------------------------------------------------------------------------- /Source/HTTPRiot/HTTPRiot.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009 Justin Palmer , All Rights Reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | * 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the author nor the names of its contributors may be used 15 | * to endorse or promote products derived from this software without specific 16 | * prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | /** 31 | @mainpage HTTPRiot - A simple HTTP REST Library 32 | 33 | @image html httpriot.png 34 | 35 | @li HTTPRiot homepage 36 | @li Source Code 37 | @li Twitter 38 | 39 | HTTPRiot is a simple REST library designed to make interacting with REST services 40 | much easier. It supports GET, POST, PUSH and DELETE requests and HTTP Basic Authentication. 41 | HTTPRiot was inspired by John Nunemaker's excellent 42 | httparty Ruby library. 43 | 44 |
45 | Related Guides 46 |
    47 |
  • @subpage iphone-setup
  • 48 |
  • @subpage cocoa-setup
  • 49 |
50 |
51 | 52 |

Some Examples

53 | 54 |

Send a GET request

55 | @code 56 | [HRRestModel getPath:@"/person.json" withOptions:nil object:nil]; 57 | @endcode 58 | 59 |

Send a POST request with JSON body data

60 | @code 61 | NSDictionary *opts = [NSDictionary dictionaroyWithObject:[person JSONRepresentation] forKey:@"body"]; 62 | [HRRestModel postPath:@"/person" withOptions:opts object:nil]; 63 | @endcode 64 | 65 |

Send a PUT request

66 | @code 67 | NSDictionary *opts = [NSDictionary dictionaroyWithObject:[updatedPerson JSONRepresentation] forKey:@"body"]; 68 | [HRRestModel putPath:@"/person" withOptions:opts object:nil]; 69 | @endcode 70 | 71 |

Send a DELETE request

72 | @code 73 | [HRRestModel deletePath:@"/person/1" withOptions:nil object:nil]; 74 | @endcode 75 | 76 |

Subclassing HRRestModel

77 | Although you can use HTTPRiot straight out of the box by itself, this approach has some pitfals. 78 | Every request will share the same configuation options. By subclassing HRRestModel you can have 79 | per-class configuation options meaning that all requests generating from your subclass share a 80 | local set of configuation options and will not affect other requests not originating from your subclass. 81 | 82 | @include Tweet.m 83 | 84 | @page iphone-setup Using the HTTPRiot Framework in your iPhone Applications 85 | 86 | HTTPRiot comes with a simple SDK package that makes it very easy to get up and running quickly 87 | on the iphone. You'll need to put this SDK package somewhere where it won't get deleted and you 88 | can share it with all your iPhone projects. 89 | 90 |

NOTE: Make sure you select "All Configurations" in the Build tab before changing any settings.

91 | 92 | -# Move the httpriot-* directory to ~/Library/SDKs. You might need to create this directory. 93 | It's not mandatory that it lives in this location, but it's a good idea that you put it somewhere 94 | where it can be shared. 95 | -# Create a new project or open an existing project in XCode. Select your application's target and 96 | press ⌘i to bring up the properties window. Set the Additional SDKs 97 | property to ~/Library/SDKs/httpriot-0.6.10/\$(PLATFORM_NAME)\$(IPHONEOS_DEPLOYMENT_TARGET).sdk 98 | @image html additional-sdks.png 99 | -# Set the Other Linker Flags to -lhttpriot -lxml2 -ObjC -all_load 100 | @image html other-linker-flags.png 101 | -# Set Header Search Paths to /usr/include/libxml2/** 102 | -# If building for the iPad or iPhone 4 OS you'll need to set 'Architectures' to "Optimized" or "arm6,arm7" 103 | -# Use \#include in one of your application's files. 104 | That's it! Now you're ready to use HTTPRiot! 105 | 106 | @page cocoa-setup Using the HTTPRiot Framework in your Desktop Applications 107 | 108 | -# Right click Other Frameworks in XCode and select Add → Existing Frameworks. Select 109 | the HTTPRiot.framework and press Add. @image html httpriot-framework.png 110 | -# Include the framework \#include in your project. That's it! 111 | 112 |

Embedding HTTPRiot.framework in your application

113 | If you want to distribute HTTPRiot.framework with your application you'll need to do another step. 114 | 115 | -# Right click your target name and select "Add > New Build Phase > New Copy Files Build Phase". 116 | Set Frameworks as the destination path in the popup. @image html copy-files.png 117 | -# Drag the HTTPRiot.framework file to this new phase. 118 | */ 119 | 120 | #import 121 | 122 | #import "AIXMLSerialization.h" 123 | #import "JSON.h" 124 | 125 | #import "HROperationQueue.h" 126 | #import "HRRequestOperation.h" 127 | #import "HRRestModel.h" 128 | #import "HRResponseDelegate.h" -------------------------------------------------------------------------------- /Source/iPhoneSampleApp/ISAPeopleDetailController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ISAPeopleDetailController.m 3 | // HTTPRiot 4 | // 5 | // Created by Justin Palmer on 6/24/09. 6 | // Copyright 2009 LabratRevenge LLC.. All rights reserved. 7 | // 8 | 9 | #import "ISAPeopleDetailController.h" 10 | #import "ISAEditableTextFieldCell.h" 11 | #import "ISAAlertHelper.h" 12 | #import 13 | 14 | @implementation ISAPeopleDetailController 15 | @synthesize person = _person; 16 | 17 | 18 | - (void)dealloc { 19 | [_saveButton release]; 20 | [_person release]; 21 | [super dealloc]; 22 | } 23 | 24 | - (id)initWithStyle:(UITableViewStyle)style { 25 | // Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. 26 | if (self = [super initWithStyle:UITableViewStyleGrouped]) { 27 | self.tableView.allowsSelection = NO; 28 | _saveButton = [[UIBarButtonItem alloc] initWithTitle:@"Save" style:UIBarButtonItemStyleDone target:self action:@selector(save)]; 29 | } 30 | return self; 31 | } 32 | 33 | - (void)save 34 | { 35 | NSMutableDictionary *params = [[NSMutableDictionary alloc] init]; 36 | NSArray *cells = [[self.tableView visibleCells] retain]; 37 | 38 | [params setObject:[[cells objectAtIndex:0] valueField].text forKey:@"name"]; 39 | [params setObject:[[cells objectAtIndex:1] valueField].text forKey:@"email"]; 40 | [params setObject:[[cells objectAtIndex:2] valueField].text forKey:@"address"]; 41 | [params setObject:[[cells objectAtIndex:3] valueField].text forKey:@"telephone"]; 42 | 43 | NSDictionary *bodyData = [NSDictionary dictionaryWithObjectsAndKeys:[params JSONRepresentation], @"body", nil]; 44 | [HRRestModel putPath:[NSString stringWithFormat:@"/person/%@", [self.person valueForKey:@"id"]] withOptions:bodyData object:nil]; 45 | } 46 | 47 | 48 | #pragma mark - HRResponseDelegate Methods 49 | - (void)restConnection:(NSURLConnection *)connection didReceiveError:(NSError *)error response:(NSHTTPURLResponse *)response object:(id)object { 50 | NSLog(@"RESPONSE:%@", response); 51 | ISAAlertWithMessage([error localizedDescription]); 52 | } 53 | 54 | - (void)restConnection:(NSURLConnection *)connection didReturnResource:(id)resource object:(id)object { 55 | [resource retain]; 56 | [_person release]; 57 | _person = resource; 58 | [self.tableView reloadData]; 59 | } 60 | 61 | #pragma mark - Other 62 | - (void)prepareCell:(ISAEditableTextFieldCell *)cell forIndexPath:(NSIndexPath *)ipath { 63 | NSInteger row = ipath.row; 64 | NSString *label = @""; 65 | NSString *value = @""; 66 | 67 | switch(row) { 68 | case 0: 69 | label = @"Name:"; 70 | value = [self.person valueForKey:@"name"]; 71 | break; 72 | case 1: 73 | label = @"Email:"; 74 | value = [self.person valueForKey:@"email"]; 75 | break; 76 | case 2: 77 | label = @"Address:"; 78 | value = [self.person valueForKey:@"address"]; 79 | break; 80 | case 3: 81 | label = @"Telephone:"; 82 | value = [self.person valueForKey:@"telephone"]; 83 | break; 84 | 85 | } 86 | 87 | cell.labelField.text = label; 88 | cell.valueField.text = value; 89 | } 90 | 91 | 92 | 93 | - (void)viewDidLoad { 94 | [super viewDidLoad]; 95 | // Uncomment the following line to display an Edit button in the navigation bar for this view controller. 96 | //self.navigationItem.rightBarButtonItem = self.editButtonItem; 97 | 98 | } 99 | 100 | 101 | 102 | - (void)viewWillAppear:(BOOL)animated { 103 | [HRRestModel setDelegate:self]; 104 | [super viewWillAppear:animated]; 105 | } 106 | 107 | /* 108 | - (void)viewDidAppear:(BOOL)animated { 109 | [super viewDidAppear:animated]; 110 | } 111 | */ 112 | 113 | - (void)viewWillDisappear:(BOOL)animated { 114 | [super viewWillDisappear:animated]; 115 | self.navigationItem.rightBarButtonItem = nil; 116 | } 117 | 118 | /* 119 | - (void)viewDidDisappear:(BOOL)animated { 120 | [super viewDidDisappear:animated]; 121 | } 122 | */ 123 | 124 | /* 125 | // Override to allow orientations other than the default portrait orientation. 126 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 127 | // Return YES for supported orientations 128 | return (interfaceOrientation == UIInterfaceOrientationPortrait); 129 | } 130 | */ 131 | 132 | - (void)didReceiveMemoryWarning { 133 | // Releases the view if it doesn't have a superview. 134 | [super didReceiveMemoryWarning]; 135 | 136 | // Release any cached data, images, etc that aren't in use. 137 | } 138 | 139 | - (void)viewDidUnload { 140 | // Release any retained subviews of the main view. 141 | // e.g. self.myOutlet = nil; 142 | } 143 | 144 | 145 | #pragma mark Table view methods 146 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 147 | return 1; 148 | } 149 | 150 | 151 | // Customize the number of rows in the table view. 152 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 153 | return 4; 154 | } 155 | 156 | 157 | // Customize the appearance of table view cells. 158 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 159 | 160 | static NSString *CellIdentifier = @"Cell"; 161 | 162 | ISAEditableTextFieldCell *cell = (ISAEditableTextFieldCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 163 | if (cell == nil) { 164 | cell = [[[ISAEditableTextFieldCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 165 | cell.valueField.delegate = self; 166 | } 167 | 168 | [self prepareCell:cell forIndexPath:indexPath]; 169 | return cell; 170 | } 171 | 172 | 173 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 174 | 175 | } 176 | 177 | - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { 178 | return UITableViewCellEditingStyleNone; 179 | } 180 | 181 | #pragma mark - Value Field Delegate Methods 182 | - (BOOL)textFieldShouldReturn:(UITextField *)textField { 183 | [textField resignFirstResponder]; 184 | 185 | 186 | return YES; 187 | } 188 | 189 | - (void)textFieldDidBeginEditing:(UITextField *)textField { 190 | self.navigationItem.rightBarButtonItem = _saveButton; 191 | } 192 | 193 | @end 194 | 195 | --------------------------------------------------------------------------------