Skip to content

Commit

Permalink
Cleaned up Demo code
Browse files Browse the repository at this point in the history
  • Loading branch information
MKSG-MugunthKumar committed Dec 31, 2012
1 parent 49bd000 commit 08faaee
Show file tree
Hide file tree
Showing 20 changed files with 312 additions and 528 deletions.
9 changes: 8 additions & 1 deletion MKNetworkKit/MKNetworkEngine.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
11 changes: 10 additions & 1 deletion MKNetworkKit/MKNetworkOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down Expand Up @@ -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]];
Expand Down Expand Up @@ -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];

Expand Down
36 changes: 12 additions & 24 deletions iOS-Demo/MKNetworkKit-iOS-Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand All @@ -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 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = AB94373516411E0A0002299C /* [email protected] */; };
ABB5C2C8148B3E230056D3E9 /* SampleImage.jpg in Resources */ = {isa = PBXBuildFile; fileRef = ABB5C2C7148B3E230056D3E9 /* SampleImage.jpg */; };
ABB5C2CA148B3F370056D3E9 /* libMKNetworkKit-iOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = ABB5C2C9148B3F370056D3E9 /* libMKNetworkKit-iOS.a */; };
Expand All @@ -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 = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
AB148FD1147F4EF8001F4A86 /* ExampleUploader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = ExampleUploader.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
AB148FD4147F5166001F4A86 /* ExampleDownloader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExampleDownloader.h; sourceTree = "<group>"; };
AB148FD5147F5167001F4A86 /* ExampleDownloader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ExampleDownloader.m; sourceTree = "<group>"; };
AB20C33E1487C854004B0825 /* ExamplePost.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExamplePost.h; sourceTree = "<group>"; };
AB20C33F1487C854004B0825 /* ExamplePost.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = ExamplePost.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
AB2B455516916A44004470F9 /* TestsEngine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestsEngine.h; sourceTree = "<group>"; };
AB2B455616916A44004470F9 /* TestsEngine.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TestsEngine.m; sourceTree = "<group>"; };
AB2B455D16916F45004470F9 /* HTTPSTestEngine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTTPSTestEngine.h; sourceTree = "<group>"; };
AB2B455E16916F45004470F9 /* HTTPSTestEngine.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HTTPSTestEngine.m; sourceTree = "<group>"; };
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 = "<group>"; };
AB6E44D914CBA3CC0089D19C /* FlickrTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FlickrTableViewController.h; sourceTree = "<group>"; };
Expand All @@ -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 = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
AB80BBB5148B672100B6DC2A /* AuthTestEngine.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = AuthTestEngine.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
AB94373516411E0A0002299C /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
ABB5C2C7148B3E230056D3E9 /* SampleImage.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; name = SampleImage.jpg; path = ../SampleImage.jpg; sourceTree = "<group>"; };
ABB5C2C9148B3F370056D3E9 /* libMKNetworkKit-iOS.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libMKNetworkKit-iOS.a"; path = "../MKNetworkKit-iOS/build/Release-iphoneos/libMKNetworkKit-iOS.a"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};
Expand Down
21 changes: 9 additions & 12 deletions iOS-Demo/MKNetworkKitDemo/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,24 @@
// THE SOFTWARE.

#import <UIKit/UIKit.h>

#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 <UIApplicationDelegate>

@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 @""
@property (strong, nonatomic) TestsEngine *testsEngine;
@property (strong, nonatomic) HTTPSTestEngine *httpsTestsEngine;
@end
31 changes: 11 additions & 20 deletions iOS-Demo/MKNetworkKitDemo/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
21 changes: 0 additions & 21 deletions iOS-Demo/MKNetworkKitDemo/AuthTestEngine.h

This file was deleted.

134 changes: 0 additions & 134 deletions iOS-Demo/MKNetworkKitDemo/AuthTestEngine.m

This file was deleted.

29 changes: 0 additions & 29 deletions iOS-Demo/MKNetworkKitDemo/ExampleDownloader.h

This file was deleted.

Loading

0 comments on commit 08faaee

Please sign in to comment.