diff --git a/MKNetworkKit/MKNetworkEngine.m b/MKNetworkKit/MKNetworkEngine.m index a1cef9a..10e5ce8 100644 --- a/MKNetworkKit/MKNetworkEngine.m +++ b/MKNetworkKit/MKNetworkEngine.m @@ -334,7 +334,14 @@ -(MKNetworkOperation*) operationWithPath:(NSString*) path if(self.apiPath) [urlString appendFormat:@"/%@", self.apiPath]; - [urlString appendFormat:@"/%@", path]; + if(![path isEqualToString:@"/"]) { // fetch for root? + + if(path.length > 0 && [path characterAtIndex:0] == '/') // if user passes /, don't prefix a slash + [urlString appendFormat:@"%@", path]; + else if (path != nil) + [urlString appendFormat:@"/%@", path]; + } + return [self operationWithURLString:urlString params:body httpMethod:method]; } diff --git a/MKNetworkKit/MKNetworkOperation.m b/MKNetworkKit/MKNetworkOperation.m index 55eaa02..7cc9c31 100644 --- a/MKNetworkKit/MKNetworkOperation.m +++ b/MKNetworkKit/MKNetworkOperation.m @@ -110,7 +110,13 @@ @implementation MKNetworkOperation -(BOOL) isCacheable { - return [self.request.HTTPMethod isEqualToString:@"GET"]; + if(self.username != nil) return NO; + if(self.password != nil) return NO; + if(self.clientCertificate != nil) return NO; + if(self.clientCertificatePassword != nil) return NO; + if(![self.request.HTTPMethod isEqualToString:@"GET"]) return NO; + if([self.request.URL.scheme.lowercaseString isEqualToString:@"https"]) return NO; + return YES; } @@ -408,6 +414,7 @@ - (id)copyWithZone:(NSZone *)zone [theCopy setUsername:[self.username copy]]; [theCopy setPassword:[self.password copy]]; [theCopy setClientCertificate:[self.clientCertificate copy]]; + [theCopy setClientCertificatePassword:[self.clientCertificatePassword copy]]; [theCopy setResponseBlocks:[self.responseBlocks copy]]; [theCopy setErrorBlocks:[self.errorBlocks copy]]; [theCopy setErrorBlocksType2:[self.errorBlocksType2 copy]]; @@ -546,6 +553,8 @@ - (id)initWithURLString:(NSString *)aURLString self.stringEncoding = NSUTF8StringEncoding; // use a delegate to get these values later + if(!method) method = @"GET"; + if ([method isEqualToString:@"GET"]) self.cacheHeaders = [NSMutableDictionary dictionary]; diff --git a/iOS-Demo/MKNetworkKit-iOS-Demo.xcodeproj/project.pbxproj b/iOS-Demo/MKNetworkKit-iOS-Demo.xcodeproj/project.pbxproj index a259937..44ba058 100644 --- a/iOS-Demo/MKNetworkKit-iOS-Demo.xcodeproj/project.pbxproj +++ b/iOS-Demo/MKNetworkKit-iOS-Demo.xcodeproj/project.pbxproj @@ -7,9 +7,8 @@ objects = { /* Begin PBXBuildFile section */ - AB148FD2147F4EF8001F4A86 /* ExampleUploader.m in Sources */ = {isa = PBXBuildFile; fileRef = AB148FD1147F4EF8001F4A86 /* ExampleUploader.m */; }; - AB148FD6147F5167001F4A86 /* ExampleDownloader.m in Sources */ = {isa = PBXBuildFile; fileRef = AB148FD5147F5167001F4A86 /* ExampleDownloader.m */; }; - AB20C3401487C854004B0825 /* ExamplePost.m in Sources */ = {isa = PBXBuildFile; fileRef = AB20C33F1487C854004B0825 /* ExamplePost.m */; }; + AB2B455716916A44004470F9 /* TestsEngine.m in Sources */ = {isa = PBXBuildFile; fileRef = AB2B455616916A44004470F9 /* TestsEngine.m */; }; + AB2B455F16916F45004470F9 /* HTTPSTestEngine.m in Sources */ = {isa = PBXBuildFile; fileRef = AB2B455E16916F45004470F9 /* HTTPSTestEngine.m */; }; AB3A3090148F09AE00D06246 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB3A308F148F09AE00D06246 /* Security.framework */; }; AB480DFF168F1D520017D04B /* client.p12 in Resources */ = {isa = PBXBuildFile; fileRef = AB480DFE168F1D520017D04B /* client.p12 */; }; AB6E44DB14CBA3CC0089D19C /* FlickrTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AB6E44DA14CBA3CC0089D19C /* FlickrTableViewController.m */; }; @@ -20,7 +19,6 @@ AB74B0C61467CC120088BF09 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB74B0C51467CC120088BF09 /* CoreGraphics.framework */; }; AB74B1111467E5790088BF09 /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB74B1101467E5790088BF09 /* CFNetwork.framework */; }; AB74B1131467E5850088BF09 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB74B1121467E5850088BF09 /* SystemConfiguration.framework */; }; - AB80BBB6148B672100B6DC2A /* AuthTestEngine.m in Sources */ = {isa = PBXBuildFile; fileRef = AB80BBB5148B672100B6DC2A /* AuthTestEngine.m */; }; AB94373616411E0A0002299C /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = AB94373516411E0A0002299C /* Default-568h@2x.png */; }; ABB5C2C8148B3E230056D3E9 /* SampleImage.jpg in Resources */ = {isa = PBXBuildFile; fileRef = ABB5C2C7148B3E230056D3E9 /* SampleImage.jpg */; }; ABB5C2CA148B3F370056D3E9 /* libMKNetworkKit-iOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = ABB5C2C9148B3F370056D3E9 /* libMKNetworkKit-iOS.a */; }; @@ -33,12 +31,10 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ - AB148FD0147F4EF8001F4A86 /* ExampleUploader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = ExampleUploader.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; - AB148FD1147F4EF8001F4A86 /* ExampleUploader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = ExampleUploader.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; - AB148FD4147F5166001F4A86 /* ExampleDownloader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExampleDownloader.h; sourceTree = ""; }; - AB148FD5147F5167001F4A86 /* ExampleDownloader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ExampleDownloader.m; sourceTree = ""; }; - AB20C33E1487C854004B0825 /* ExamplePost.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExamplePost.h; sourceTree = ""; }; - AB20C33F1487C854004B0825 /* ExamplePost.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = ExamplePost.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + AB2B455516916A44004470F9 /* TestsEngine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestsEngine.h; sourceTree = ""; }; + AB2B455616916A44004470F9 /* TestsEngine.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TestsEngine.m; sourceTree = ""; }; + AB2B455D16916F45004470F9 /* HTTPSTestEngine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTTPSTestEngine.h; sourceTree = ""; }; + AB2B455E16916F45004470F9 /* HTTPSTestEngine.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HTTPSTestEngine.m; sourceTree = ""; }; AB3A308F148F09AE00D06246 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; }; AB480DFE168F1D520017D04B /* client.p12 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = client.p12; sourceTree = ""; }; AB6E44D914CBA3CC0089D19C /* FlickrTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FlickrTableViewController.h; sourceTree = ""; }; @@ -53,8 +49,6 @@ AB74B0C51467CC120088BF09 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; AB74B1101467E5790088BF09 /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; }; AB74B1121467E5850088BF09 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; }; - AB80BBB4148B672100B6DC2A /* AuthTestEngine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = AuthTestEngine.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; - AB80BBB5148B672100B6DC2A /* AuthTestEngine.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = AuthTestEngine.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; AB94373516411E0A0002299C /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = ""; }; ABB5C2C7148B3E230056D3E9 /* SampleImage.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; name = SampleImage.jpg; path = ../SampleImage.jpg; sourceTree = ""; }; ABB5C2C9148B3F370056D3E9 /* libMKNetworkKit-iOS.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libMKNetworkKit-iOS.a"; path = "../MKNetworkKit-iOS/build/Release-iphoneos/libMKNetworkKit-iOS.a"; sourceTree = ""; }; @@ -137,20 +131,16 @@ ABF149C41467F312008B20C9 /* ViewController.m */, ABC25177146802B900264474 /* YahooEngine.h */, ABC25178146802B900264474 /* YahooEngine.m */, - AB148FD0147F4EF8001F4A86 /* ExampleUploader.h */, - AB148FD1147F4EF8001F4A86 /* ExampleUploader.m */, - AB148FD4147F5166001F4A86 /* ExampleDownloader.h */, - AB148FD5147F5167001F4A86 /* ExampleDownloader.m */, - AB20C33E1487C854004B0825 /* ExamplePost.h */, - AB20C33F1487C854004B0825 /* ExamplePost.m */, - AB80BBB4148B672100B6DC2A /* AuthTestEngine.h */, - AB80BBB5148B672100B6DC2A /* AuthTestEngine.m */, AB6E44D914CBA3CC0089D19C /* FlickrTableViewController.h */, AB6E44DA14CBA3CC0089D19C /* FlickrTableViewController.m */, AB6E44DC14CBA43F0089D19C /* FlickrCell.h */, AB6E44DD14CBA43F0089D19C /* FlickrCell.m */, AB6E44DF14CBA62B0089D19C /* FlickrEngine.h */, AB6E44E014CBA62B0089D19C /* FlickrEngine.m */, + AB2B455D16916F45004470F9 /* HTTPSTestEngine.h */, + AB2B455E16916F45004470F9 /* HTTPSTestEngine.m */, + AB2B455516916A44004470F9 /* TestsEngine.h */, + AB2B455616916A44004470F9 /* TestsEngine.m */, ); name = "MKNetworkKit-iOS-Demo"; path = MKNetworkKitDemo; @@ -243,13 +233,11 @@ ABF149CB1467F312008B20C9 /* main.m in Sources */, ABF149CD1467F312008B20C9 /* ViewController.m in Sources */, ABC25179146802B900264474 /* YahooEngine.m in Sources */, - AB148FD2147F4EF8001F4A86 /* ExampleUploader.m in Sources */, - AB148FD6147F5167001F4A86 /* ExampleDownloader.m in Sources */, - AB20C3401487C854004B0825 /* ExamplePost.m in Sources */, - AB80BBB6148B672100B6DC2A /* AuthTestEngine.m in Sources */, AB6E44DB14CBA3CC0089D19C /* FlickrTableViewController.m in Sources */, AB6E44DE14CBA43F0089D19C /* FlickrCell.m in Sources */, AB6E44E114CBA62B0089D19C /* FlickrEngine.m in Sources */, + AB2B455716916A44004470F9 /* TestsEngine.m in Sources */, + AB2B455F16916F45004470F9 /* HTTPSTestEngine.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/iOS-Demo/MKNetworkKitDemo/AppDelegate.h b/iOS-Demo/MKNetworkKitDemo/AppDelegate.h index 585551c..56d676a 100644 --- a/iOS-Demo/MKNetworkKitDemo/AppDelegate.h +++ b/iOS-Demo/MKNetworkKitDemo/AppDelegate.h @@ -24,13 +24,15 @@ // THE SOFTWARE. #import + #import "YahooEngine.h" -#import "ExampleUploader.h" -#import "ExampleDownloader.h" -#import "ExamplePost.h" -#import "AuthTestEngine.h" + +#import "TestsEngine.h" + #import "FlickrEngine.h" +#import "HTTPSTestEngine.h" + #define ApplicationDelegate ((AppDelegate *)[UIApplication sharedApplication].delegate) @interface AppDelegate : UIResponder @@ -38,13 +40,8 @@ @property (strong, nonatomic) UIWindow *window; @property (strong, nonatomic) YahooEngine *yahooEngine; -@property (strong, nonatomic) ExampleUploader *twitPicUploader; -@property (strong, nonatomic) ExampleDownloader *sampleDownloader; -@property (strong, nonatomic) ExamplePost *samplePoster; -@property (strong, nonatomic) AuthTestEngine *sampleAuth; @property (strong, nonatomic) FlickrEngine *flickrEngine; -@end - -#define kTwitterUserName @"" -#define kTwitterPassword @"" \ No newline at end of file +@property (strong, nonatomic) TestsEngine *testsEngine; +@property (strong, nonatomic) HTTPSTestEngine *httpsTestsEngine; +@end \ No newline at end of file diff --git a/iOS-Demo/MKNetworkKitDemo/AppDelegate.m b/iOS-Demo/MKNetworkKitDemo/AppDelegate.m index 54554f0..8648876 100644 --- a/iOS-Demo/MKNetworkKitDemo/AppDelegate.m +++ b/iOS-Demo/MKNetworkKitDemo/AppDelegate.m @@ -29,27 +29,18 @@ @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - // Override point for customization after application launch. - NSString *str = @"TEST"; - [str md5]; - - NSMutableDictionary *headerFields = [NSMutableDictionary dictionary]; - [headerFields setValue:@"iOS" forKey:@"x-client-identifier"]; - - self.yahooEngine = [[YahooEngine alloc] initWithHostName:@"download.finance.yahoo.com" - customHeaderFields:headerFields]; - // not that these header fields are mandated by yahoo. This line is to show the feature of MKNetworkKit - [self.yahooEngine useCache]; - - self.twitPicUploader = [[ExampleUploader alloc] initWithHostName:@"twitpic.com" - customHeaderFields:nil]; - - self.sampleDownloader = [[ExampleDownloader alloc] initWithHostName:nil customHeaderFields:nil]; - self.samplePoster = [[ExamplePost alloc] initWithHostName:@"stockfresh.com" customHeaderFields:nil]; - self.sampleAuth = [[AuthTestEngine alloc] initWithHostName:@"api.mk.sg" customHeaderFields:nil]; - [self.sampleAuth useCache]; - self.flickrEngine = [[FlickrEngine alloc] initWithHostName:@"api.flickr.com" customHeaderFields:nil]; + self.yahooEngine = [[YahooEngine alloc] initWithHostName:@"download.finance.yahoo.com"]; + [self.yahooEngine useCache]; + + // you can initialize an engine in your app delegate like the previous Yahoo engine or + // write a method like initWithDefaultSettings in your subclass and initialize there like the tests engine + + self.testsEngine = [[TestsEngine alloc] initWithDefaultSettings]; + self.httpsTestsEngine = [[HTTPSTestEngine alloc] initWithDefaultSettings]; + + self.flickrEngine = [[FlickrEngine alloc] initWithHostName:@"api.flickr.com"]; [self.flickrEngine useCache]; + return YES; } diff --git a/iOS-Demo/MKNetworkKitDemo/AuthTestEngine.h b/iOS-Demo/MKNetworkKitDemo/AuthTestEngine.h deleted file mode 100644 index da0e0e8..0000000 --- a/iOS-Demo/MKNetworkKitDemo/AuthTestEngine.h +++ /dev/null @@ -1,21 +0,0 @@ -// -// AuthTestEngine.h -// MKNetworkKit-iOS-Demo -// -// Created by Mugunth Kumar on 4/12/11. -// Copyright (c) 2011 Steinlogic. All rights reserved. -// - -@interface AuthTestEngine : MKNetworkEngine - --(void) basicAuthTest; --(void) digestAuthTest; --(void)digestAuthTestWithUser:(NSString*)username password:(NSString*)password; --(void) serverTrustTest; --(void) clientCertTest; --(int) cacheMemoryCost; - --(MKNetworkOperation*) uploadImageFromFile:(NSString*) file - completionHandler:(TwitPicBlock) completionBlock - errorHandler:(MKNKErrorBlock) errorBlock; -@end diff --git a/iOS-Demo/MKNetworkKitDemo/AuthTestEngine.m b/iOS-Demo/MKNetworkKitDemo/AuthTestEngine.m deleted file mode 100644 index 88f2431..0000000 --- a/iOS-Demo/MKNetworkKitDemo/AuthTestEngine.m +++ /dev/null @@ -1,134 +0,0 @@ -// -// AuthTestEngine.m -// MKNetworkKit-iOS-Demo -// -// Created by Mugunth Kumar on 4/12/11. -// Copyright (c) 2011 Steinlogic. All rights reserved. -// - -#import "AuthTestEngine.h" - -@implementation AuthTestEngine - --(void) basicAuthTest { - - MKNetworkOperation *op = [self operationWithPath:@"mknetworkkit/basic_auth.php" - params:nil - httpMethod:@"GET"]; - - [op setUsername:@"admin" password:@"password" basicAuth:YES]; - - [op addCompletionHandler:^(MKNetworkOperation *operation) { - - DLog(@"%@", [operation responseString]); - } errorHandler:^(MKNetworkOperation *errorOp, NSError* error) { - - DLog(@"%@", [error localizedDescription]); - }]; - [self enqueueOperation:op]; -} - - --(void) digestAuthTest { - - MKNetworkOperation *op = [self operationWithPath:@"mknetworkkit/digest_auth.php" - params:nil - httpMethod:@"GET"]; - - [op setUsername:@"admin" password:@"password"]; - - [op addCompletionHandler:^(MKNetworkOperation *operation) { - - DLog(@"%@", [operation responseString]); - } errorHandler:^(MKNetworkOperation *errorOp, NSError* error) { - - DLog(@"%@", [error localizedDescription]); - }]; - [self enqueueOperation:op]; -} - --(void)digestAuthTestWithUser:(NSString*)username password:(NSString*)password { - MKNetworkOperation *op = [self operationWithPath:@"mknetworkkit/digest_auth.php" - params:nil - httpMethod:@"GET"]; - - [op setUsername:username password:password]; - [op setCredentialPersistence:NSURLCredentialPersistenceNone]; - - [op addCompletionHandler:^(MKNetworkOperation *operation) { - - DLog(@"%@", [operation responseString]); - } errorHandler:^(MKNetworkOperation *errorOp, NSError* error) { - - DLog(@"%@", [error localizedDescription]); - }]; - [self enqueueOperation:op]; -} - - --(void) serverTrustTest { - - MKNetworkOperation *op = [self operationWithURLString:@"https://testbed.mknetworkkit.com"]; - - [op addCompletionHandler:^(MKNetworkOperation *operation) { - - DLog(@"%@", [operation responseString]); - } errorHandler:^(MKNetworkOperation *errorOp, NSError* error) { - - DLog(@"%@", [error localizedDescription]); - }]; - [self enqueueOperation:op]; -} - --(void) clientCertTest { - - MKNetworkOperation *op = [self operationWithURLString:@"https://testbed.mknetworkkit.com"]; - op.clientCertificate = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"client.p12"]; - op.clientCertificatePassword = @"test"; - - [op addCompletionHandler:^(MKNetworkOperation *operation) { - - DLog(@"%@", [operation responseString]); - } errorHandler:^(MKNetworkOperation *errorOp, NSError* error) { - - DLog(@"%@", [error localizedDescription]); - }]; - [self enqueueOperation:op]; -} - --(MKNetworkOperation*) uploadImageFromFile:(NSString*) file - completionHandler:(TwitPicBlock) completionBlock - errorHandler:(MKNKErrorBlock) errorBlock { - - MKNetworkOperation *op = [self operationWithPath:@"mknetworkkit/upload.php" - params:@{@"Submit": @"YES"} - httpMethod:@"POST"]; - - [op addFile:file forKey:@"image"]; - - // setFreezable uploads your images after connection is restored! - [op setFreezable:YES]; - - [op addCompletionHandler:^(MKNetworkOperation* completedOperation) { - - NSString *xmlString = [completedOperation responseString]; - - DLog(@"%@", xmlString); - completionBlock(xmlString); - } - errorHandler:^(MKNetworkOperation *errorOp, NSError* error) { - - errorBlock(error); - }]; - - [self enqueueOperation:op]; - - - return op; -} - --(int) cacheMemoryCost { - return 0; -} - -@end diff --git a/iOS-Demo/MKNetworkKitDemo/ExampleDownloader.h b/iOS-Demo/MKNetworkKitDemo/ExampleDownloader.h deleted file mode 100644 index fb18d1a..0000000 --- a/iOS-Demo/MKNetworkKitDemo/ExampleDownloader.h +++ /dev/null @@ -1,29 +0,0 @@ -// -// ExampleDownloader.h -// MKNetworkKitDemo -// -// Created by Mugunth Kumar (@mugunthkumar) on 11/11/11. -// Copyright (C) 2011-2020 by Steinlogic - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -@interface ExampleDownloader : MKNetworkEngine - --(MKNetworkOperation*) downloadFatAssFileFrom:(NSString*) remoteURL toFile:(NSString*) fileName; -@end diff --git a/iOS-Demo/MKNetworkKitDemo/ExampleDownloader.m b/iOS-Demo/MKNetworkKitDemo/ExampleDownloader.m deleted file mode 100644 index 6d01488..0000000 --- a/iOS-Demo/MKNetworkKitDemo/ExampleDownloader.m +++ /dev/null @@ -1,43 +0,0 @@ -// -// ExampleDownloader.m -// MKNetworkKitDemo -// -// Created by Mugunth Kumar (@mugunthkumar) on 11/11/11. -// Copyright (C) 2011-2020 by Steinlogic - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -#import "ExampleDownloader.h" - -@implementation ExampleDownloader - - --(MKNetworkOperation*) downloadFatAssFileFrom:(NSString*) remoteURL toFile:(NSString*) filePath { - - MKNetworkOperation *op = [self operationWithURLString:remoteURL - params:nil - httpMethod:@"GET"]; - - [op addDownloadStream:[NSOutputStream outputStreamToFileAtPath:filePath - append:YES]]; - - [self enqueueOperation:op]; - return op; -} -@end diff --git a/iOS-Demo/MKNetworkKitDemo/ExamplePost.h b/iOS-Demo/MKNetworkKitDemo/ExamplePost.h deleted file mode 100644 index a5920a4..0000000 --- a/iOS-Demo/MKNetworkKitDemo/ExamplePost.h +++ /dev/null @@ -1,12 +0,0 @@ -// -// ExamplePost.h -// MKNetworkKitDemo -// -// Created by Mugunth Kumar on 1/12/11. -// Copyright (c) 2011 Steinlogic. All rights reserved. -// - -@interface ExamplePost : MKNetworkEngine - --(MKNetworkOperation*) postDataToServer; -@end diff --git a/iOS-Demo/MKNetworkKitDemo/ExamplePost.m b/iOS-Demo/MKNetworkKitDemo/ExamplePost.m deleted file mode 100644 index 679f0d0..0000000 --- a/iOS-Demo/MKNetworkKitDemo/ExamplePost.m +++ /dev/null @@ -1,34 +0,0 @@ -// -// ExamplePost.m -// MKNetworkKitDemo -// -// Created by Mugunth Kumar on 1/12/11. -// Copyright (c) 2011 Steinlogic. All rights reserved. -// - -#import "ExamplePost.h" - -@implementation ExamplePost - --(MKNetworkOperation*) postDataToServer { - - MKNetworkOperation *op = [self operationWithPath:@"index.php" - params:@{@"email": @"stock_user", - @"password": @"stock_pass", - @"where":@"/", @"f":@"signin"} - httpMethod:@"POST"]; - - [op addCompletionHandler:^(MKNetworkOperation *operation) { - - DLog(@"%@", operation); - } errorHandler:^(MKNetworkOperation *errorOp, NSError* error) { - - DLog(@"%@", error); - }]; - - [self enqueueOperation:op]; - - return op; -} - -@end diff --git a/iOS-Demo/MKNetworkKitDemo/ExampleUploader.h b/iOS-Demo/MKNetworkKitDemo/ExampleUploader.h deleted file mode 100644 index 7f8edc1..0000000 --- a/iOS-Demo/MKNetworkKitDemo/ExampleUploader.h +++ /dev/null @@ -1,33 +0,0 @@ -// -// ExampleUploader.h -// MKNetworkKitDemo -// -// Created by Mugunth Kumar (@mugunthkumar) on 11/11/11. -// Copyright (C) 2011-2020 by Steinlogic - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -@interface ExampleUploader : MKNetworkEngine -typedef void (^TwitPicBlock)(NSString *twitPicURL); - --(MKNetworkOperation*) uploadImageFromFile:(NSString*) file - addCompletionHandler:(TwitPicBlock) completionBlock - onError:(MKNKErrorBlock) errorBlock; - -@end diff --git a/iOS-Demo/MKNetworkKitDemo/ExampleUploader.m b/iOS-Demo/MKNetworkKitDemo/ExampleUploader.m deleted file mode 100644 index bd705d4..0000000 --- a/iOS-Demo/MKNetworkKitDemo/ExampleUploader.m +++ /dev/null @@ -1,70 +0,0 @@ -// -// ExampleUploader.m -// MKNetworkKitDemo -// -// Created by Mugunth Kumar (@mugunthkumar) on 11/11/11. -// Copyright (C) 2011-2020 by Steinlogic - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -#import "ExampleUploader.h" - -@implementation ExampleUploader - --(MKNetworkOperation*) uploadImageFromFile:(NSString*) file - addCompletionHandler:(TwitPicBlock) completionBlock - onError:(MKNKErrorBlock) errorBlock { - - MKNetworkOperation *op = [self operationWithPath:@"api/upload" - params:@{@"username": kTwitterUserName, - @"password": kTwitterPassword} - httpMethod:@"POST"]; - - [op addFile:file forKey:@"media"]; - - // setFreezable uploads your images after connection is restored! - [op setFreezable:YES]; - - [op addCompletionHandler:^(MKNetworkOperation* completedOperation) { - - NSString *xmlString = [completedOperation responseString]; - NSUInteger start = [xmlString rangeOfString:@""].location; - if(start == NSNotFound) { - - DLog(@"%@", xmlString); - errorBlock(nil); - return; - } - xmlString = [xmlString substringFromIndex:start + @"".length]; - NSUInteger end = [xmlString rangeOfString:@""].location; - xmlString = [xmlString substringToIndex:end]; - completionBlock(xmlString); - } - errorHandler:^(MKNetworkOperation *errorOp, NSError* error) { - - errorBlock(error); - }]; - - [self enqueueOperation:op]; - - - return op; -} - -@end diff --git a/iOS-Demo/MKNetworkKitDemo/FlickrCell.m b/iOS-Demo/MKNetworkKitDemo/FlickrCell.m index 2f3fe15..6d430e6 100644 --- a/iOS-Demo/MKNetworkKitDemo/FlickrCell.m +++ b/iOS-Demo/MKNetworkKitDemo/FlickrCell.m @@ -63,10 +63,12 @@ -(void) setFlickrData:(NSDictionary*) thisFlickrImage { completionHandler:^(UIImage *fetchedImage, NSURL *url, BOOL isInCache) { if([self.loadingImageURLString isEqualToString:[url absoluteString]]) { - - [UIView animateWithDuration:isInCache?0.0f:0.4f delay:0 options:UIViewAnimationOptionShowHideTransitionViews animations:^{ - self.thumbnailImage.image = fetchedImage; - } completion:nil]; + + [UIView transitionWithView:self.contentView + duration:isInCache?0.1f:0.4f + options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ + self.thumbnailImage.image = fetchedImage; + } completion:nil]; } } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) { diff --git a/iOS-Demo/MKNetworkKitDemo/HTTPSTestEngine.h b/iOS-Demo/MKNetworkKitDemo/HTTPSTestEngine.h new file mode 100644 index 0000000..b799600 --- /dev/null +++ b/iOS-Demo/MKNetworkKitDemo/HTTPSTestEngine.h @@ -0,0 +1,15 @@ +// +// AuthTestEngine.h +// MKNetworkKit-iOS-Demo +// +// Created by Mugunth Kumar on 4/12/11. +// Copyright (c) 2011 Steinlogic. All rights reserved. +// + +@interface HTTPSTestEngine : MKNetworkEngine + +-(id) initWithDefaultSettings; +-(void) serverTrustTest; +-(void) clientCertTest; + +@end diff --git a/iOS-Demo/MKNetworkKitDemo/HTTPSTestEngine.m b/iOS-Demo/MKNetworkKitDemo/HTTPSTestEngine.m new file mode 100644 index 0000000..14474c7 --- /dev/null +++ b/iOS-Demo/MKNetworkKitDemo/HTTPSTestEngine.m @@ -0,0 +1,51 @@ +// +// AuthTestEngine.m +// MKNetworkKit-iOS-Demo +// +// Created by Mugunth Kumar on 4/12/11. +// Copyright (c) 2011 Steinlogic. All rights reserved. +// + +#import "HTTPSTestEngine.h" + +@implementation HTTPSTestEngine + +-(id) initWithDefaultSettings { + + if(self = [super initWithHostName:@"testbed1.mknetworkkit.com" customHeaderFields:@{@"x-client-identifier" : @"iOS"}]) { + + } + return self; +} + +-(void) serverTrustTest { + + MKNetworkOperation *op = [self operationWithPath:@"/" params:nil httpMethod:nil ssl:YES]; + + [op addCompletionHandler:^(MKNetworkOperation *operation) { + + DLog(@"%@", [operation responseString]); + } errorHandler:^(MKNetworkOperation *errorOp, NSError* error) { + + DLog(@"%@", [error localizedDescription]); + }]; + [self enqueueOperation:op]; +} + +-(void) clientCertTest { + + MKNetworkOperation *op = [self operationWithPath:@"/" params:nil httpMethod:nil ssl:YES]; + op.clientCertificate = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"client.p12"]; + op.clientCertificatePassword = @"test"; + + [op addCompletionHandler:^(MKNetworkOperation *operation) { + + DLog(@"%@", [operation responseString]); + } errorHandler:^(MKNetworkOperation *errorOp, NSError* error) { + + DLog(@"%@", [error localizedDescription]); + }]; + [self enqueueOperation:op]; +} + +@end diff --git a/iOS-Demo/MKNetworkKitDemo/TestsEngine.h b/iOS-Demo/MKNetworkKitDemo/TestsEngine.h new file mode 100644 index 0000000..90d4902 --- /dev/null +++ b/iOS-Demo/MKNetworkKitDemo/TestsEngine.h @@ -0,0 +1,23 @@ +// +// TestsEngine.h +// MKNetworkKit-iOS-Demo +// +// Created by Mugunth on 31/12/12. +// Copyright (c) 2012 Steinlogic. All rights reserved. +// + +typedef void (^IDBlock)(id object); + +@interface TestsEngine : MKNetworkEngine + +-(id) initWithDefaultSettings; +-(void) basicAuthTest; +-(void) digestAuthTest; + +-(MKNetworkOperation*) downloadFatAssFileFrom:(NSString*) remoteURL toFile:(NSString*) filePath; + +-(MKNetworkOperation*) uploadImageFromFile:(NSString*) file + completionHandler:(IDBlock) completionBlock + errorHandler:(MKNKErrorBlock) errorBlock; + +@end diff --git a/iOS-Demo/MKNetworkKitDemo/TestsEngine.m b/iOS-Demo/MKNetworkKitDemo/TestsEngine.m new file mode 100644 index 0000000..daf4998 --- /dev/null +++ b/iOS-Demo/MKNetworkKitDemo/TestsEngine.m @@ -0,0 +1,100 @@ +// +// TestsEngine.m +// MKNetworkKit-iOS-Demo +// +// Created by Mugunth on 31/12/12. +// Copyright (c) 2012 Steinlogic. All rights reserved. +// + +#import "TestsEngine.h" + +@implementation TestsEngine + +-(id) initWithDefaultSettings { + + if(self = [super initWithHostName:@"testbed2.mknetworkkit.com" customHeaderFields:@{@"x-client-identifier" : @"iOS"}]) { + + } + + return self; +} + +-(void) basicAuthTest { + + MKNetworkOperation *op = [self operationWithPath:@"basic_auth.php" + params:nil + httpMethod:@"GET"]; + + [op setUsername:@"admin" password:@"password" basicAuth:YES]; + + [op addCompletionHandler:^(MKNetworkOperation *operation) { + + DLog(@"%@", [operation responseString]); + } errorHandler:^(MKNetworkOperation *errorOp, NSError* error) { + + DLog(@"%@", [error localizedDescription]); + }]; + [self enqueueOperation:op]; +} + +-(void) digestAuthTest { + + MKNetworkOperation *op = [self operationWithPath:@"digest_auth.php" + params:nil + httpMethod:@"GET"]; + + [op setUsername:@"admin" password:@"password"]; + [op setCredentialPersistence:NSURLCredentialPersistenceNone]; + + [op addCompletionHandler:^(MKNetworkOperation *operation) { + + DLog(@"%@", [operation responseString]); + } errorHandler:^(MKNetworkOperation *errorOp, NSError* error) { + + DLog(@"%@", [error localizedDescription]); + }]; + [self enqueueOperation:op]; +} + +-(MKNetworkOperation*) downloadFatAssFileFrom:(NSString*) remoteURL toFile:(NSString*) filePath { + + MKNetworkOperation *op = [self operationWithURLString:remoteURL]; + + [op addDownloadStream:[NSOutputStream outputStreamToFileAtPath:filePath + append:YES]]; + + [self enqueueOperation:op]; + return op; +} + +-(MKNetworkOperation*) uploadImageFromFile:(NSString*) file + completionHandler:(IDBlock) completionBlock + errorHandler:(MKNKErrorBlock) errorBlock { + + MKNetworkOperation *op = [self operationWithPath:@"upload.php" + params:@{@"Submit": @"YES"} + httpMethod:@"POST"]; + + [op addFile:file forKey:@"image"]; + + // setFreezable uploads your images after connection is restored! + [op setFreezable:YES]; + + [op addCompletionHandler:^(MKNetworkOperation* completedOperation) { + + NSString *xmlString = [completedOperation responseString]; + + DLog(@"%@", xmlString); + completionBlock(xmlString); + } + errorHandler:^(MKNetworkOperation *errorOp, NSError* error) { + + errorBlock(error); + }]; + + [self enqueueOperation:op]; + + + return op; +} +@end diff --git a/iOS-Demo/MKNetworkKitDemo/ViewController.m b/iOS-Demo/MKNetworkKitDemo/ViewController.m index 3d41781..5b90095 100644 --- a/iOS-Demo/MKNetworkKitDemo/ViewController.m +++ b/iOS-Demo/MKNetworkKitDemo/ViewController.m @@ -61,11 +61,6 @@ -(void) viewDidDisappear:(BOOL)animated { // upload and download operations are expected to run in background even when view disappears } --(IBAction)postDataToServer:(id)sender { - - [ApplicationDelegate.samplePoster postDataToServer]; -} - -(IBAction)convertCurrencyTapped:(id)sender { self.currencyOperation = [ApplicationDelegate.yahooEngine currencyRateFor:@"SGD" @@ -88,19 +83,12 @@ -(IBAction)convertCurrencyTapped:(id)sender { -(IBAction)uploadImageTapped:(id)sender { - if([kTwitterUserName length] == 0) { - - [[[UIAlertView alloc] initWithTitle:@"Twitter Account Not Set" - message:@"Set your twitter name/password in AppDelegate.h and try again" - delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles: nil] show]; - return; - } NSString *uploadPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingFormat:@"/SampleImage.jpg"]; - self.uploadOperation = [ApplicationDelegate.sampleAuth uploadImageFromFile:uploadPath - completionHandler:^(NSString *twitPicURL) { + self.uploadOperation = [ApplicationDelegate.testsEngine uploadImageFromFile:uploadPath + completionHandler:^(id twitPicURL) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Uploaded to" - message:twitPicURL + message:(NSString*) twitPicURL delegate:nil cancelButtonTitle:NSLocalizedString(@"Dismiss", @"") otherButtonTitles:nil]; @@ -126,7 +114,7 @@ -(IBAction)downloadFileTapped:(id)sender { NSString *cachesDirectory = paths[0]; NSString *downloadPath = [cachesDirectory stringByAppendingPathComponent:@"DownloadedFile.pdf"]; - self.downloadOperation = [ApplicationDelegate.sampleDownloader downloadFatAssFileFrom:@"http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURLRequest_Class/NSURLRequest_Class.pdf" + self.downloadOperation = [ApplicationDelegate.testsEngine downloadFatAssFileFrom:@"http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURLRequest_Class/NSURLRequest_Class.pdf" toFile:downloadPath]; [self.downloadOperation onDownloadProgressChanged:^(double progress) { @@ -166,12 +154,11 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); } -- (IBAction)testAuthTapped:(id)sender { - - //[ApplicationDelegate.sampleAuth basicAuthTest]; - //[ApplicationDelegate.sampleAuth digestAuthTest]; - //[ApplicationDelegate.sampleAuth digestAuthTestWithUser:self.userTextField.text password:self.passwordTextField.text]; - //[ApplicationDelegate.sampleAuth serverTrustTest]; - [ApplicationDelegate.sampleAuth clientCertTest]; +- (IBAction)runTestsTapped:(id)sender { + + [ApplicationDelegate.testsEngine basicAuthTest]; + [ApplicationDelegate.testsEngine digestAuthTest]; + [ApplicationDelegate.httpsTestsEngine serverTrustTest]; + [ApplicationDelegate.httpsTestsEngine clientCertTest]; } @end diff --git a/iOS-Demo/MKNetworkKitDemo/en.lproj/MainStoryboard.storyboard b/iOS-Demo/MKNetworkKitDemo/en.lproj/MainStoryboard.storyboard index c29b3a9..e82ff58 100644 --- a/iOS-Demo/MKNetworkKitDemo/en.lproj/MainStoryboard.storyboard +++ b/iOS-Demo/MKNetworkKitDemo/en.lproj/MainStoryboard.storyboard @@ -1,7 +1,7 @@ - + - + @@ -13,159 +13,149 @@ - + - + - - + - - - + @@ -206,14 +196,14 @@ - + @@ -237,7 +227,7 @@ - +