Skip to content
Browse files

- Added support for query parameters

- Added preliminary support for POST operations
  • Loading branch information...
1 parent 2591ca1 commit 06dfd42a32fd17e15c64dd3e4a073b1941f64a3f @mtabini mtabini committed Oct 6, 2010
View
135 AFKLoadManager.xcodeproj/marcot.pbxuser
@@ -9,9 +9,9 @@
};
1D3623250D0F684500981E51 /* AFKLoadManagerAppDelegate.m */ = {
uiCtxt = {
- sepNavIntBoundsRect = "{{0, 0}, {2244, 1232}}";
+ sepNavIntBoundsRect = "{{0, 0}, {2244, 1360}}";
sepNavSelRange = "{536, 0}";
- sepNavVisRange = "{0, 2229}";
+ sepNavVisRange = "{98, 2253}";
};
};
1D6058900D05DD3D006BFB54 /* AFKLoadManager */ = {
@@ -157,21 +157,20 @@
PBXFileDataSource_Warnings_ColumnID,
);
};
- PBXPerProjectTemplateStateSaveDate = 307589999;
- PBXWorkspaceStateSaveDate = 307589999;
+ PBXPerProjectTemplateStateSaveDate = 308115622;
+ PBXWorkspaceStateSaveDate = 308115622;
};
perUserProjectItems = {
- 8F862F3912556C27005D8CB9 = 8F862F3912556C27005D8CB9 /* PBXTextBookmark */;
- 8F862F4812556C4D005D8CB9 = 8F862F4812556C4D005D8CB9 /* PlistBookmark */;
- 8F862F5912556DEB005D8CB9 = 8F862F5912556DEB005D8CB9 /* PBXTextBookmark */;
- 8F862F5B12556DEB005D8CB9 = 8F862F5B12556DEB005D8CB9 /* PBXTextBookmark */;
- 8F862F5D12556DEB005D8CB9 = 8F862F5D12556DEB005D8CB9 /* PBXTextBookmark */;
- 8F862F5E12556DEB005D8CB9 = 8F862F5E12556DEB005D8CB9 /* PBXTextBookmark */;
- 8F862F6D12556E1E005D8CB9 = 8F862F6D12556E1E005D8CB9 /* PBXTextBookmark */;
- 8F862F8E12557078005D8CB9 = 8F862F8E12557078005D8CB9 /* PBXTextBookmark */;
- 8F862F8F12557078005D8CB9 = 8F862F8F12557078005D8CB9 /* PBXTextBookmark */;
- 8F862FA212557229005D8CB9 = 8F862FA212557229005D8CB9 /* PBXTextBookmark */;
- 8F862FB412557385005D8CB9 /* PBXTextBookmark */ = 8F862FB412557385005D8CB9 /* PBXTextBookmark */;
+ 8F862F3912556C27005D8CB9 /* PBXTextBookmark */ = 8F862F3912556C27005D8CB9 /* PBXTextBookmark */;
+ 8F862F4812556C4D005D8CB9 /* PlistBookmark */ = 8F862F4812556C4D005D8CB9 /* PlistBookmark */;
+ 8F862F5E12556DEB005D8CB9 /* PBXTextBookmark */ = 8F862F5E12556DEB005D8CB9 /* PBXTextBookmark */;
+ 8F862F6D12556E1E005D8CB9 /* PBXTextBookmark */ = 8F862F6D12556E1E005D8CB9 /* PBXTextBookmark */;
+ 8F862F8E12557078005D8CB9 /* PBXTextBookmark */ = 8F862F8E12557078005D8CB9 /* PBXTextBookmark */;
+ 8F862FB812557E0E005D8CB9 /* PBXTextBookmark */ = 8F862FB812557E0E005D8CB9 /* PBXTextBookmark */;
+ 8FCDFBAD125D78C3003EB5FF /* PBXTextBookmark */ = 8FCDFBAD125D78C3003EB5FF /* PBXTextBookmark */;
+ 8FCDFBAE125D78C3003EB5FF /* PBXTextBookmark */ = 8FCDFBAE125D78C3003EB5FF /* PBXTextBookmark */;
+ 8FCDFBAF125D78C3003EB5FF /* PBXTextBookmark */ = 8FCDFBAF125D78C3003EB5FF /* PBXTextBookmark */;
+ 8FCDFBB0125D78C3003EB5FF /* PBXTextBookmark */ = 8FCDFBB0125D78C3003EB5FF /* PBXTextBookmark */;
};
sourceControlManager = 8F862F081255672E005D8CB9 /* Source Control */;
userBuildSettings = {
@@ -230,23 +229,23 @@
};
8F862F141255680C005D8CB9 /* AFKDownloadWorker.h */ = {
uiCtxt = {
- sepNavIntBoundsRect = "{{0, 0}, {1859, 816}}";
+ sepNavIntBoundsRect = "{{0, 0}, {1652, 1041}}";
sepNavSelRange = "{609, 0}";
- sepNavVisRange = "{476, 413}";
+ sepNavVisRange = "{0, 1075}";
};
};
8F862F151255680C005D8CB9 /* AFKDownloadManager.m */ = {
uiCtxt = {
- sepNavIntBoundsRect = "{{0, 0}, {1652, 2192}}";
+ sepNavIntBoundsRect = "{{0, 0}, {1964, 2176}}";
sepNavSelRange = "{1404, 0}";
- sepNavVisRange = "{211, 1123}";
+ sepNavVisRange = "{1281, 1633}";
};
};
8F862F161255680C005D8CB9 /* AFKDownloadManager.h */ = {
uiCtxt = {
- sepNavIntBoundsRect = "{{0, 0}, {1652, 624}}";
- sepNavSelRange = "{401, 0}";
- sepNavVisRange = "{0, 440}";
+ sepNavIntBoundsRect = "{{0, 0}, {1652, 1041}}";
+ sepNavSelRange = "{592, 167}";
+ sepNavVisRange = "{0, 820}";
};
};
8F862F1A1255688D005D8CB9 /* DemoImageLoaderController.h */ = {
@@ -258,9 +257,9 @@
};
8F862F1B1255688D005D8CB9 /* DemoImageLoaderController.m */ = {
uiCtxt = {
- sepNavIntBoundsRect = "{{0, 0}, {1652, 2112}}";
- sepNavSelRange = "{3649, 245}";
- sepNavVisRange = "{1990, 2118}";
+ sepNavIntBoundsRect = "{{0, 0}, {1652, 2128}}";
+ sepNavSelRange = "{1282, 39}";
+ sepNavVisRange = "{7, 2003}";
};
};
8F862F3912556C27005D8CB9 /* PBXTextBookmark */ = {
@@ -285,36 +284,6 @@
rLen = 0;
rLoc = 9223372036854775808;
};
- 8F862F5912556DEB005D8CB9 /* PBXTextBookmark */ = {
- isa = PBXTextBookmark;
- fRef = 1D3623250D0F684500981E51 /* AFKLoadManagerAppDelegate.m */;
- name = "AFKLoadManagerAppDelegate.m: 23";
- rLen = 0;
- rLoc = 536;
- rType = 0;
- vrLen = 2229;
- vrLoc = 0;
- };
- 8F862F5B12556DEB005D8CB9 /* PBXTextBookmark */ = {
- isa = PBXTextBookmark;
- fRef = 8F862F151255680C005D8CB9 /* AFKDownloadManager.m */;
- name = "AFKDownloadManager.m: 81";
- rLen = 0;
- rLoc = 1404;
- rType = 0;
- vrLen = 1123;
- vrLoc = 211;
- };
- 8F862F5D12556DEB005D8CB9 /* PBXTextBookmark */ = {
- isa = PBXTextBookmark;
- fRef = 8F862F161255680C005D8CB9 /* AFKDownloadManager.h */;
- name = "AFKDownloadManager.h: 17";
- rLen = 0;
- rLoc = 401;
- rType = 0;
- vrLen = 440;
- vrLoc = 0;
- };
8F862F5E12556DEB005D8CB9 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 8F862F131255680C005D8CB9 /* AFKDownloadWorker.m */;
@@ -345,34 +314,54 @@
vrLen = 377;
vrLoc = 0;
};
- 8F862F8F12557078005D8CB9 /* PBXTextBookmark */ = {
+ 8F862FB812557E0E005D8CB9 /* PBXTextBookmark */ = {
+ isa = PBXTextBookmark;
+ fRef = 8F862F161255680C005D8CB9 /* AFKDownloadManager.h */;
+ name = "AFKDownloadManager.h: 32";
+ rLen = 167;
+ rLoc = 592;
+ rType = 0;
+ vrLen = 820;
+ vrLoc = 0;
+ };
+ 8FCDFBAD125D78C3003EB5FF /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 8F862F1B1255688D005D8CB9 /* DemoImageLoaderController.m */;
- name = "DemoImageLoaderController.m: 72";
+ name = "DemoImageLoaderController.m: 36";
+ rLen = 39;
+ rLoc = 1282;
+ rType = 0;
+ vrLen = 2003;
+ vrLoc = 7;
+ };
+ 8FCDFBAE125D78C3003EB5FF /* PBXTextBookmark */ = {
+ isa = PBXTextBookmark;
+ fRef = 8F862F151255680C005D8CB9 /* AFKDownloadManager.m */;
+ name = "AFKDownloadManager.m: 73";
rLen = 0;
- rLoc = 2792;
+ rLoc = 1404;
rType = 0;
- vrLen = 2217;
- vrLoc = 507;
+ vrLen = 1633;
+ vrLoc = 1281;
};
- 8F862FA212557229005D8CB9 /* PBXTextBookmark */ = {
+ 8FCDFBAF125D78C3003EB5FF /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
- fRef = 8F862F1B1255688D005D8CB9 /* DemoImageLoaderController.m */;
- name = "DemoImageLoaderController.m: 100";
+ fRef = 1D3623250D0F684500981E51 /* AFKLoadManagerAppDelegate.m */;
+ name = "AFKLoadManagerAppDelegate.m: 23";
rLen = 0;
- rLoc = 3432;
+ rLoc = 536;
rType = 0;
- vrLen = 2296;
- vrLoc = 1760;
+ vrLen = 2253;
+ vrLoc = 98;
};
- 8F862FB412557385005D8CB9 /* PBXTextBookmark */ = {
+ 8FCDFBB0125D78C3003EB5FF /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
- fRef = 8F862F1B1255688D005D8CB9 /* DemoImageLoaderController.m */;
- name = "DemoImageLoaderController.m: 107";
- rLen = 245;
- rLoc = 3649;
+ fRef = 8F862F141255680C005D8CB9 /* AFKDownloadWorker.h */;
+ name = "AFKDownloadWorker.h: 38";
+ rLen = 0;
+ rLoc = 609;
rType = 0;
- vrLen = 2118;
- vrLoc = 1990;
+ vrLen = 1075;
+ vrLoc = 0;
};
}
View
29 AFKLoadManager.xcodeproj/marcot.perspectivev3
@@ -231,6 +231,8 @@
<key>Layout</key>
<array>
<dict>
+ <key>BecomeActive</key>
+ <true/>
<key>ContentConfiguration</key>
<dict>
<key>PBXBottomSmartGroupGIDs</key>
@@ -276,6 +278,9 @@
<key>PBXSmartGroupTreeModuleOutlineStateSelectionKey</key>
<array>
<array>
+ <integer>7</integer>
+ <integer>5</integer>
+ <integer>1</integer>
<integer>0</integer>
</array>
</array>
@@ -308,37 +313,35 @@
<key>Dock</key>
<array>
<dict>
- <key>BecomeActive</key>
- <true/>
<key>ContentConfiguration</key>
<dict>
<key>PBXProjectModuleGUID</key>
<string>8F862F0A1255674F005D8CB9</string>
<key>PBXProjectModuleLabel</key>
- <string>DemoImageLoaderController.m</string>
+ <string>AFKDownloadWorker.h</string>
<key>PBXSplitModuleInNavigatorKey</key>
<dict>
<key>Split0</key>
<dict>
<key>PBXProjectModuleGUID</key>
<string>8F862F0B1255674F005D8CB9</string>
<key>PBXProjectModuleLabel</key>
- <string>DemoImageLoaderController.m</string>
+ <string>AFKDownloadWorker.h</string>
<key>_historyCapacity</key>
<integer>0</integer>
<key>bookmark</key>
- <string>8F862FB412557385005D8CB9</string>
+ <string>8FCDFBB0125D78C3003EB5FF</string>
<key>history</key>
<array>
<string>8F862F3912556C27005D8CB9</string>
<string>8F862F4812556C4D005D8CB9</string>
- <string>8F862F5912556DEB005D8CB9</string>
- <string>8F862F5B12556DEB005D8CB9</string>
- <string>8F862F5D12556DEB005D8CB9</string>
<string>8F862F5E12556DEB005D8CB9</string>
- <string>8F862F6D12556E1E005D8CB9</string>
<string>8F862F8E12557078005D8CB9</string>
- <string>8F862FA212557229005D8CB9</string>
+ <string>8F862FB812557E0E005D8CB9</string>
+ <string>8FCDFBAD125D78C3003EB5FF</string>
+ <string>8FCDFBAE125D78C3003EB5FF</string>
+ <string>8FCDFBAF125D78C3003EB5FF</string>
+ <string>8F862F6D12556E1E005D8CB9</string>
</array>
</dict>
<key>SplitCount</key>
@@ -461,11 +464,11 @@
</array>
<key>TableOfContents</key>
<array>
- <string>8F862FB512557385005D8CB9</string>
+ <string>8FCDFBB1125D78C3003EB5FF</string>
<string>1CA23ED40692098700951B8B</string>
- <string>8F862FB612557385005D8CB9</string>
+ <string>8FCDFBB2125D78C3003EB5FF</string>
<string>8F862F0A1255674F005D8CB9</string>
- <string>8F862FB712557385005D8CB9</string>
+ <string>8FCDFBB3125D78C3003EB5FF</string>
<string>1CA23EDF0692099D00951B8B</string>
<string>1CA23EE00692099D00951B8B</string>
<string>1CA23EE10692099D00951B8B</string>
View
1 Classes/AFKDownloadManager.h
@@ -30,6 +30,7 @@
+ (AFKDownloadManager *) defaultManager;
+ (void) queueDownloadFromURL:(NSURL *) url withHTTPParameters:(NSDictionary *) parameters target:(id) target selector:(SEL) selector atTopOfQueue:(BOOL) atTopOfQueue;
++ (void) queueDownloadFromURL:(NSURL *) url method:(NSString *) method queryParameters:(NSDictionary *) queryParameters HTTPParameters:(NSDictionary *) HTTPParameters target:(id) target selector:(SEL) selector atTopOfQueue:(BOOL) atTopOfQueue;
- (void) workerIsDone:(AFKDownloadWorker *) worker;
View
33 Classes/AFKDownloadManager.m
@@ -19,7 +19,6 @@ @implementation AFKDownloadManager
- (void) processQueue {
-
if (liveWorkers.count < self.maximumWorkers) {
if (queue.count) {
@@ -39,38 +38,31 @@ - (void) processQueue {
} else {
[[NSNotificationCenter defaultCenter] postNotificationName:kAFKDownloadManagerActivityEnded object:self];
}
-
}
- (void) workerIsDone:(AFKDownloadWorker *) worker {
-
worker.downloadManager = Nil;
[liveWorkers removeObject:worker];
[self processQueue];
-
}
- (void) enqueueWorker:(AFKDownloadWorker *) worker atTopOfQueue:(BOOL) atTopOfQueue {
-
if (atTopOfQueue) {
[queue insertObject:worker atIndex:0];
} else {
[queue addObject:worker];
}
[self processQueue];
-
}
- (void) setMaximumWorkers:(int) value {
-
maximumWorkers = value;
[self processQueue];
-
}
@@ -79,20 +71,17 @@ - (void) setMaximumWorkers:(int) value {
+ (AFKDownloadManager *) defaultManager {
-
static AFKDownloadManager *globalInstance;
if (!globalInstance) {
globalInstance = [AFKDownloadManager new];
}
return globalInstance;
-
}
+ (void) queueDownloadFromURL:(NSURL *) url withHTTPParameters:(NSDictionary *) parameters target:(id) target selector:(SEL) selector atTopOfQueue:(BOOL) atTopOfQueue {
-
AFKDownloadManager *manager = [AFKDownloadManager defaultManager];
AFKDownloadWorker *worker = [[AFKDownloadWorker new] autorelease];
@@ -106,30 +95,44 @@ + (void) queueDownloadFromURL:(NSURL *) url withHTTPParameters:(NSDictionary *)
worker.selector = selector;
[manager enqueueWorker:worker atTopOfQueue:atTopOfQueue];
+}
+
+
++ (void) queueDownloadFromURL:(NSURL *) url method:(NSString *) method queryParameters:(NSDictionary *) queryParameters HTTPParameters:(NSDictionary *) HTTPParameters target:(id) target selector:(SEL) selector atTopOfQueue:(BOOL) atTopOfQueue {
+ AFKDownloadManager *manager = [AFKDownloadManager defaultManager];
+ AFKDownloadWorker *worker = [[AFKDownloadWorker new] autorelease];
+
+ worker.url = url;
+ worker.method = method;
+ worker.queryParameters = queryParameters;
+ worker.HTTPParameters = HTTPParameters;
+
+ worker.downloadManager = manager;
+
+ worker.target = target;
+ worker.selector = selector;
+
+ [manager enqueueWorker:worker atTopOfQueue:atTopOfQueue];
}
- (id) init {
-
if (self = [super init]) {
queue = [NSMutableArray new];
liveWorkers = [NSMutableArray new];
maximumWorkers = 5;
}
return self;
-
}
- (void) dealloc {
-
[queue release];
[liveWorkers release];
[super dealloc];
-
}
View
7 Classes/AFKDownloadWorker.h
@@ -12,7 +12,10 @@
@interface AFKDownloadWorker : NSObject {
+ NSString *method;
NSURL *url;
+ NSDictionary *queryParameters;
+
NSDictionary *HTTPParameters;
AFKDownloadManager *downloadManager;
@@ -30,7 +33,11 @@
}
+@property (nonatomic,retain) NSString *method;
+
@property (nonatomic,retain) NSURL *url;
+@property (nonatomic,retain) NSDictionary *queryParameters;
+
@property (nonatomic,retain) NSDictionary *HTTPParameters;
@property (nonatomic,retain) AFKDownloadManager *downloadManager;
View
47 Classes/AFKDownloadWorker.m
@@ -12,17 +12,46 @@
@implementation AFKDownloadWorker
-@synthesize url, HTTPParameters, downloadManager, target, selector, running, urlConnection, content;
+@synthesize method, url, queryParameters, HTTPParameters, downloadManager, target, selector, running, urlConnection, content;
#pragma mark -
#pragma mark Download Management
- (void) start {
-
- NSMutableURLRequest *urlRequest = [[[NSMutableURLRequest alloc] initWithURL:self.url] autorelease];
+ NSString *urlPayload;
+
+ if (self.queryParameters && self.queryParameters.count) {
+ urlPayload = [[NSMutableString new] autorelease];
+
+ NSMutableArray *parameters = [[[NSMutableArray alloc] initWithCapacity:queryParameters.count] autorelease];
+
+ for (NSString *key in self.queryParameters) {
+ [parameters addObject:[NSString stringWithFormat:@"%@=%@",
+ [key stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
+ [[((NSString *) [self.queryParameters objectForKey:key]) stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] stringByReplacingOccurrencesOfString:@" " withString:@"+"]]];
+ }
+
+ urlPayload = [parameters componentsJoinedByString:@"&"];
+ }
+
+ NSMutableURLRequest *urlRequest;
+
+ if (urlPayload) {
+ if ([self.method isEqualToString:@"GET"]) {
+ NSString *urlString = [self.url absoluteString];
+ NSString *actualURL = [NSString stringWithFormat:([urlString rangeOfString:@"?"].location == NSNotFound) ? @"%@?%@" : @"%@&%@",
+ urlString, urlPayload];
+
+ urlRequest = [[[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:actualURL]] autorelease];
+ } else {
+ urlRequest = [[[NSMutableURLRequest alloc] initWithURL:self.url] autorelease];
+ }
+ }
+ [urlRequest setHTTPMethod:self.method];
+
for (NSString *key in self.HTTPParameters) {
[urlRequest setValue:[self.HTTPParameters objectForKey:key] forHTTPHeaderField:key];
}
@@ -67,9 +96,21 @@ - (void) connectionDidFinishLoading:(NSURLConnection *)connection {
#pragma mark -
#pragma mark Initialization and Management
+
+- (id) init {
+ if ((self = [super init])) {
+ self.method = @"GET";
+ }
+
+ return self;
+}
+
+
- (void) dealloc {
+ self.method = Nil;
self.url = Nil;
+ self.queryParameters = Nil;
self.HTTPParameters = Nil;
self.target = Nil;
self.downloadManager = Nil;

0 comments on commit 06dfd42

Please sign in to comment.
Something went wrong with that request. Please try again.