Skip to content

Commit

Permalink
-- Added option to start the data tasks automatically (for functions …
Browse files Browse the repository at this point in the history
…that returned them via pointers) for AFHTTPSessionManager
  • Loading branch information
csotiriou committed Oct 10, 2015
1 parent 81e625f commit 17fc38e
Show file tree
Hide file tree
Showing 7 changed files with 332 additions and 213 deletions.
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
platform :ios, '8.0'

pod 'AFNetworking', '~> 2.5'
pod 'PromiseKit/CorePromise', :git => 'https://github.com/mxcl/PromiseKit', :branch => 'swift-2.0-beta5'
pod 'PromiseKit/CorePromise', :git => 'https://github.com/mxcl/PromiseKit'

use_frameworks!

Expand Down
13 changes: 8 additions & 5 deletions PromiseKit+AFNetworking.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
0666CC97192961BC00110C1B /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 0666CC95192961BC00110C1B /* InfoPlist.strings */; };
0666CC99192961BC00110C1B /* AFHTTPRequestOperation+PromiseTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 0666CC98192961BC00110C1B /* AFHTTPRequestOperation+PromiseTests.m */; };
06B81A8E19F3F18C00A8CF14 /* AFNetworking+PromiseKit.m in Sources */ = {isa = PBXBuildFile; fileRef = 06B81A8D19F3F18C00A8CF14 /* AFNetworking+PromiseKit.m */; };
22B9056872DCCD914800BCCD /* Pods.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E48D58E13F4BD8C3756975FE /* Pods.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
5A0FC94829A17322C5D1F8D7 /* Pods_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 240DBD0C20C6C4AC011A16AB /* Pods_Tests.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
22B9056872DCCD914800BCCD /* Pods.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E48D58E13F4BD8C3756975FE /* Pods.framework */; };
5A0FC94829A17322C5D1F8D7 /* Pods_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 240DBD0C20C6C4AC011A16AB /* Pods_Tests.framework */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -239,7 +239,7 @@
0666CC62192961BC00110C1B /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0510;
LastUpgradeCheck = 0700;
ORGANIZATIONNAME = Oramind;
TargetAttributes = {
0666CC8A192961BC00110C1B = {
Expand Down Expand Up @@ -458,6 +458,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
Expand Down Expand Up @@ -516,11 +517,11 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "PromiseKit+AFNetworking/PromiseKit+AFNetworking-Prefix.pch";
INFOPLIST_FILE = "PromiseKit+AFNetworking/PromiseKit+AFNetworking-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.oramind.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
Expand All @@ -532,11 +533,11 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "PromiseKit+AFNetworking/PromiseKit+AFNetworking-Prefix.pch";
INFOPLIST_FILE = "PromiseKit+AFNetworking/PromiseKit+AFNetworking-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.oramind.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
Expand All @@ -563,6 +564,7 @@
"$(inherited)",
"$(PROJECT_DIR)/Pods/build/Debug-iphoneos",
);
PRODUCT_BUNDLE_IDENTIFIER = "com.oramind.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUNDLE_LOADER)";
WRAPPER_EXTENSION = xctest;
Expand All @@ -586,6 +588,7 @@
"$(inherited)",
"$(PROJECT_DIR)/Pods/build/Debug-iphoneos",
);
PRODUCT_BUNDLE_IDENTIFIER = "com.oramind.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUNDLE_LOADER)";
WRAPPER_EXTENSION = xctest;
Expand Down
80 changes: 80 additions & 0 deletions PromiseKit+AFNetworking/AFNetworking+PromiseKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ FOUNDATION_EXPORT const NSString *AFHTTPRequestOperationErrorKey;

@interface AFHTTPSessionManager (Promises)

@property (nonatomic, assign) BOOL startTasksImmediately;

- (AFPromise *)POST:(NSString *)urlString parameters:(id)parameters;
- (AFPromise *)POST:(NSString *)urlString parameters:(id)parameters constructingBodyWithBlock:(void (^)(id<AFMultipartFormData>))block;
Expand All @@ -177,25 +178,103 @@ FOUNDATION_EXPORT const NSString *AFHTTPRequestOperationErrorKey;
- (AFPromise *)DELETE:(NSString *)urlString parameters:(id)parameters;


/**
* Returns a Promise, with a ready-to-use data task, by performing the corresponding operation to the default AFHTTPSessionManager.
* WARNING: The default behaviour of the task is NOT to run immediately.
* You must call '-resume' to the pointer in order to actually make the request. If you want to change this behaviour, set
* 'startTasksImmediately' to YES
*
* @param request the request to perform
* @param task Pass a pointer to the task, in order to have the task returned to this pointer.
*
* @return a Promise.
*/
- (AFPromise *)dataTaskWithRequest:(NSURLRequest *)request
task:(NSURLSessionTask * __autoreleasing *)task;

/**
* Returns a Promise, with a ready-to-use data task, by performing the corresponding operation to the default AFHTTPSessionManager.
* WARNING: The default behaviour of the task is NOT to run immediately.
* You must call '-resume' to the pointer in order to actually make the request. If you want to change this behaviour, set
* 'startTasksImmediately' to YES
*
* @param request
* @param fileURL
* @param progress
* @param uploadTask
*
* @return a Promise
*/
- (AFPromise *)uploadTaskWithRequest:(NSURLRequest *)request
fromFile:(NSURL *)fileURL
progress:(NSProgress * __autoreleasing *)progress
uploadTask:(NSURLSessionTask * __autoreleasing *)uploadTask;

/**
* Returns a Promise, with a ready-to-use data task, by performing the corresponding operation to the default AFHTTPSessionManager.
* WARNING: The default behaviour of the task is NOT to run immediately.
* You must call '-resume' to the pointer in order to actually make the request. If you want to change this behaviour, set
* 'startTasksImmediately' to YES
*
* @param request
* @param bodyData
* @param progress
* @param uploadTask
*
* @return
*/
- (AFPromise *)uploadTaskWithRequest:(NSURLRequest *)request
fromData:(NSData *)bodyData
progress:(NSProgress * __autoreleasing *)progress
uploadTask:(NSURLSessionTask * __autoreleasing *)uploadTask;

/**
* Returns a Promise, with a ready-to-use data task, by performing the corresponding operation to the default AFHTTPSessionManager.
* WARNING: The default behaviour of the task is NOT to run immediately.
* You must call '-resume' to the pointer in order to actually make the request. If you want to change this behaviour, set
* 'startTasksImmediately' to YES
*
* @param request
* @param progress
* @param uploadTask
*
* @return
*/
- (AFPromise *)uploadTaskWithStreamedRequest:(NSURLRequest *)request
progress:(NSProgress * __autoreleasing *)progress
uploadTask:(NSURLSessionTask * __autoreleasing *)uploadTask;

/**
* Returns a Promise, with a ready-to-use data task, by performing the corresponding operation to the default AFHTTPSessionManager.
* WARNING: The default behaviour of the task is NOT to run immediately.
* You must call '-resume' to the pointer in order to actually make the request. If you want to change this behaviour, set
* 'startTasksImmediately' to YES
*
* @param request
* @param progress
* @param destination
* @param downloadTask
*
* @return
*/
- (AFPromise *)downloadTaskWithRequest:(NSURLRequest *)request
progress:(NSProgress * __autoreleasing *)progress
destination:(NSURL * (^)(NSURL *targetPath, NSURLResponse *response))destination
downloadTask:(NSURLSessionTask * __autoreleasing *)downloadTask;

/**
* Returns a Promise, with a ready-to-use data task, by performing the corresponding operation to the default AFHTTPSessionManager.
* WARNING: The default behaviour of the task is NOT to run immediately.
* You must call '-resume' to the pointer in order to actually make the request. If you want to change this behaviour, set
* 'startTasksImmediately' to YES
*
* @param resumeData
* @param progress
* @param destination
* @param downloadTask
*
* @return
*/
- (AFPromise *)downloadTaskWithResumeData:(NSData *)resumeData
progress:(NSProgress * __autoreleasing *)progress
destination:(NSURL * (^)(NSURL *targetPath, NSURLResponse *response))destination
Expand Down Expand Up @@ -284,4 +363,5 @@ FOUNDATION_EXPORT const NSString *AFHTTPRequestOperationErrorKey;
* URL strings (will be associated by their position in the array, so make sure they match)
*/
- (AFPromise *)DELETEMultiple:(NSArray *)urlStringsArray parameters:(NSArray *)parametersArray;

@end
Loading

0 comments on commit 17fc38e

Please sign in to comment.