diff --git a/Podfile b/Podfile index 6cfabc4..7097c7a 100644 --- a/Podfile +++ b/Podfile @@ -2,7 +2,7 @@ platform :ios, '8.0' target 'PromiseKit+AFNetworking' do -pod 'AFNetworking', '~> 2.0' +pod 'AFNetworking', '~> 3.1.0' pod 'PromiseKit/CorePromise', '~>3.0' end diff --git a/PromiseKit+AFNetworking.xcodeproj/project.pbxproj b/PromiseKit+AFNetworking.xcodeproj/project.pbxproj index 47e2996..889acf3 100644 --- a/PromiseKit+AFNetworking.xcodeproj/project.pbxproj +++ b/PromiseKit+AFNetworking.xcodeproj/project.pbxproj @@ -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 */; }; 5A0FC94829A17322C5D1F8D7 /* Pods_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 240DBD0C20C6C4AC011A16AB /* Pods_Tests.framework */; }; + B0214F66B71CED6A5736EDDF /* Pods_PromiseKit_AFNetworking.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B0C33A15B665F3F4C42F5003 /* Pods_PromiseKit_AFNetworking.framework */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -63,9 +63,12 @@ 0666CC98192961BC00110C1B /* AFHTTPRequestOperation+PromiseTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "AFHTTPRequestOperation+PromiseTests.m"; sourceTree = ""; }; 06B81A8C19F3F18C00A8CF14 /* AFNetworking+PromiseKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "AFNetworking+PromiseKit.h"; sourceTree = ""; }; 06B81A8D19F3F18C00A8CF14 /* AFNetworking+PromiseKit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "AFNetworking+PromiseKit.m"; sourceTree = ""; }; + 0F4227DEF417C6F618D5918D /* Pods-PromiseKit+AFNetworking.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PromiseKit+AFNetworking.release.xcconfig"; path = "Pods/Target Support Files/Pods-PromiseKit+AFNetworking/Pods-PromiseKit+AFNetworking.release.xcconfig"; sourceTree = ""; }; 240DBD0C20C6C4AC011A16AB /* Pods_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 468E42E9FFEFCB6B8583FCEE /* Pods-Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Tests/Pods-Tests.debug.xcconfig"; sourceTree = ""; }; 8AEAB2E2EA0C34F16181045F /* Pods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.release.xcconfig; path = "Pods/Target Support Files/Pods/Pods.release.xcconfig"; sourceTree = ""; }; + 9FCCE12EF63ECDDA86B9B74D /* Pods-PromiseKit+AFNetworking.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PromiseKit+AFNetworking.debug.xcconfig"; path = "Pods/Target Support Files/Pods-PromiseKit+AFNetworking/Pods-PromiseKit+AFNetworking.debug.xcconfig"; sourceTree = ""; }; + B0C33A15B665F3F4C42F5003 /* Pods_PromiseKit_AFNetworking.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_PromiseKit_AFNetworking.framework; sourceTree = BUILT_PRODUCTS_DIR; }; E48D58E13F4BD8C3756975FE /* Pods.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods.framework; sourceTree = BUILT_PRODUCTS_DIR; }; E9A299DE9A54CE253A26E387 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = ""; }; F0855C7DD91C82C533ABE940 /* Pods-Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-Tests/Pods-Tests.release.xcconfig"; sourceTree = ""; }; @@ -79,7 +82,7 @@ 0666CC70192961BC00110C1B /* CoreGraphics.framework in Frameworks */, 0666CC72192961BC00110C1B /* UIKit.framework in Frameworks */, 0666CC6E192961BC00110C1B /* Foundation.framework in Frameworks */, - 22B9056872DCCD914800BCCD /* Pods.framework in Frameworks */, + B0214F66B71CED6A5736EDDF /* Pods_PromiseKit_AFNetworking.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -127,6 +130,7 @@ 0666CC8C192961BC00110C1B /* XCTest.framework */, E48D58E13F4BD8C3756975FE /* Pods.framework */, 240DBD0C20C6C4AC011A16AB /* Pods_Tests.framework */, + B0C33A15B665F3F4C42F5003 /* Pods_PromiseKit_AFNetworking.framework */, ); name = Frameworks; sourceTree = ""; @@ -185,6 +189,8 @@ 8AEAB2E2EA0C34F16181045F /* Pods.release.xcconfig */, 468E42E9FFEFCB6B8583FCEE /* Pods-Tests.debug.xcconfig */, F0855C7DD91C82C533ABE940 /* Pods-Tests.release.xcconfig */, + 9FCCE12EF63ECDDA86B9B74D /* Pods-PromiseKit+AFNetworking.debug.xcconfig */, + 0F4227DEF417C6F618D5918D /* Pods-PromiseKit+AFNetworking.release.xcconfig */, ); name = Pods; sourceTree = ""; @@ -196,12 +202,12 @@ isa = PBXNativeTarget; buildConfigurationList = 0666CC9C192961BC00110C1B /* Build configuration list for PBXNativeTarget "PromiseKit+AFNetworking" */; buildPhases = ( - 2EB4A77038C243E695F8FB55 /* Check Pods Manifest.lock */, + 2EB4A77038C243E695F8FB55 /* 📦 Check Pods Manifest.lock */, 0666CC66192961BC00110C1B /* Sources */, 0666CC67192961BC00110C1B /* Frameworks */, 0666CC68192961BC00110C1B /* Resources */, - F80E4859162947088BD37311 /* Copy Pods Resources */, - E1C9D1B04F115DD76A28C31F /* Embed Pods Frameworks */, + F80E4859162947088BD37311 /* 📦 Copy Pods Resources */, + E1C9D1B04F115DD76A28C31F /* 📦 Embed Pods Frameworks */, ); buildRules = ( ); @@ -216,12 +222,12 @@ isa = PBXNativeTarget; buildConfigurationList = 0666CC9F192961BC00110C1B /* Build configuration list for PBXNativeTarget "Tests" */; buildPhases = ( - 1F0DA65DEF5603F8D6F8B6F5 /* Check Pods Manifest.lock */, + 1F0DA65DEF5603F8D6F8B6F5 /* 📦 Check Pods Manifest.lock */, 0666CC87192961BC00110C1B /* Sources */, 0666CC88192961BC00110C1B /* Frameworks */, 0666CC89192961BC00110C1B /* Resources */, - 96CEB63E63B1122B0A17A290 /* Copy Pods Resources */, - 3361F322409B62D1038B54F3 /* Embed Pods Frameworks */, + 96CEB63E63B1122B0A17A290 /* 📦 Copy Pods Resources */, + 3361F322409B62D1038B54F3 /* 📦 Embed Pods Frameworks */, ); buildRules = ( ); @@ -288,14 +294,14 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 1F0DA65DEF5603F8D6F8B6F5 /* Check Pods Manifest.lock */ = { + 1F0DA65DEF5603F8D6F8B6F5 /* 📦 Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); - name = "Check Pods Manifest.lock"; + name = "📦 Check Pods Manifest.lock"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; @@ -303,14 +309,14 @@ shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; showEnvVarsInLog = 0; }; - 2EB4A77038C243E695F8FB55 /* Check Pods Manifest.lock */ = { + 2EB4A77038C243E695F8FB55 /* 📦 Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); - name = "Check Pods Manifest.lock"; + name = "📦 Check Pods Manifest.lock"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; @@ -318,14 +324,14 @@ shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; showEnvVarsInLog = 0; }; - 3361F322409B62D1038B54F3 /* Embed Pods Frameworks */ = { + 3361F322409B62D1038B54F3 /* 📦 Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); - name = "Embed Pods Frameworks"; + name = "📦 Embed Pods Frameworks"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; @@ -333,14 +339,14 @@ shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Tests/Pods-Tests-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; - 96CEB63E63B1122B0A17A290 /* Copy Pods Resources */ = { + 96CEB63E63B1122B0A17A290 /* 📦 Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); - name = "Copy Pods Resources"; + name = "📦 Copy Pods Resources"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; @@ -348,34 +354,34 @@ shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Tests/Pods-Tests-resources.sh\"\n"; showEnvVarsInLog = 0; }; - E1C9D1B04F115DD76A28C31F /* Embed Pods Frameworks */ = { + E1C9D1B04F115DD76A28C31F /* 📦 Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); - name = "Embed Pods Frameworks"; + name = "📦 Embed Pods Frameworks"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods/Pods-frameworks.sh\"\n"; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-PromiseKit+AFNetworking/Pods-PromiseKit+AFNetworking-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; - F80E4859162947088BD37311 /* Copy Pods Resources */ = { + F80E4859162947088BD37311 /* 📦 Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); - name = "Copy Pods Resources"; + name = "📦 Copy Pods Resources"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods/Pods-resources.sh\"\n"; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-PromiseKit+AFNetworking/Pods-PromiseKit+AFNetworking-resources.sh\"\n"; showEnvVarsInLog = 0; }; /* End PBXShellScriptBuildPhase section */ @@ -513,7 +519,7 @@ }; 0666CC9D192961BC00110C1B /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = E9A299DE9A54CE253A26E387 /* Pods.debug.xcconfig */; + baseConfigurationReference = 9FCCE12EF63ECDDA86B9B74D /* Pods-PromiseKit+AFNetworking.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; @@ -529,7 +535,7 @@ }; 0666CC9E192961BC00110C1B /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 8AEAB2E2EA0C34F16181045F /* Pods.release.xcconfig */; + baseConfigurationReference = 0F4227DEF417C6F618D5918D /* Pods-PromiseKit+AFNetworking.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; diff --git a/PromiseKit+AFNetworking/AFNetworking+PromiseKit.h b/PromiseKit+AFNetworking/AFNetworking+PromiseKit.h index bf45fe8..f50b66d 100644 --- a/PromiseKit+AFNetworking/AFNetworking+PromiseKit.h +++ b/PromiseKit+AFNetworking/AFNetworking+PromiseKit.h @@ -33,138 +33,6 @@ FOUNDATION_EXPORT const NSString *AFHTTPRequestOperationErrorKey; #define kPMKAFResponseTaskKey @"task" #define kPMKAFResponseOperationKey @"operation" - -@interface AFHTTPRequestOperation (Promises) -/** - @brief Returns a new Promise with a ready to use AFHTTPRequestOperation inside. - - Returned objects in the Promise Completion: - id responseObject, AFHTTPRequestOperation *operation - */ -- (AFPromise *)promise; - -/** - @brief Returns a new Promise with a ready to use AFHTTPRequestOperation inside. The operation will immediately start - */ -- (AFPromise *)promiseAndStartImmediately; - - -/** - @brief Returns a new Promise with a ready to use AFHTTPRequestOperation inside - - If 'startImmediately is 'YES' then the operation will start immediately - */ -- (AFPromise *)promiseByStartingImmediately:(BOOL)startImmediately; - -/** - @brief Executes immediately an AFHTTPRequestOperation by adding an operation set up with a NSURLRequest - to the current queue (or to the main queue if there is no current queue - */ -+ (AFPromise *)request:(NSURLRequest *)request; - -/** - @brief Executes immediately an AFHTTPRequestOperation by adding an operation set up with a NSURLRequest - to the queue passed as the argument - */ -+ (AFPromise *)request:(NSURLRequest *)request queue:(NSOperationQueue *)queue; -@end - - -@interface AFHTTPRequestOperationManager (Promises) - -- (AFPromise *)GET:(NSString *)URLString parameters:(id)parameters; -- (AFPromise *)POST:(NSString *)URLString parameters:(id)parameters; -- (AFPromise *)POST:(NSString *)URLString parameters:(id)parameters constructingBodyWithBlock:(void (^)(id))block; -- (AFPromise *)PUT:(NSString *)URLString parameters:(id)parameters; -- (AFPromise *)DELETE:(NSString *)URLString parameters:(id)parameters; -- (AFPromise *)HEAD:(NSString *)URLString parameters:(id)parameters; - - - -/** -* @brief Performs a GET request on multiple URLs. It uses 'when' under the hood -* -* The parameters to be passed on URLs are given using an the associative array in 'parametersArray'. If you want to pass 'nil' as parameters, pass -* an empty NSDictionary instead. -* -* When all requests are finished a 'then(^(NSArray *responsesArray){})' will return an array with NSDictionaries. Each one will have two values: -* -- kPMKAFResponseObjectKey --> The response Object of the request -* -- kPMKAFResponseTaskKey --> The task that initiated the request -* -* @param urlStringsArray an array of relative URL Strings -* @param parametersArray an associative array of parameters to be passed to their corresponding -* URL strings (will be associated by their position in the array, so make sure they match) -*/ -- (AFPromise *)GETMultiple:(NSArray *)urlStringsArray parameters:(NSArray *)parametersArray; - - -/** -* @brief Performs a PUT request on multiple URLs. It uses 'when' under the hood -* -* The parameters to be passed on URLs are given using an the associative array in 'parametersArray'. If you want to pass 'nil' as parameters, pass -* an empty NSDictionary instead. -* -* When all requests are finished a 'then(^(NSArray *responsesArray){})' will return an array with NSDictionaries. Each one will have two values: -* -- kPMKAFResponseObjectKey --> The response Object of the request -* -- kPMKAFResponseTaskKey --> The task that initiated the request -* -* @param urlStringsArray an array of relative URL Strings -* @param parametersArray an associative array of parameters to be passed to their corresponding -* URL strings (will be associated by their position in the array, so make sure they match) -*/ -- (AFPromise *)PUTMultiple:(NSArray *)urlStringsArray parameters:(NSArray *)parametersArray; - -/** -* @brief Performs a HEAD request on multiple URLs. It uses 'when' under the hood -* -* The parameters to be passed on URLs are given using an the associative array in 'parametersArray'. If you want to pass 'nil' as parameters, pass -* an empty NSDictionary instead. -* -* When all requests are finished a 'then(^(NSArray *responsesArray){})' will return an array with NSDictionaries. Each one will have two values: -* -- kPMKAFResponseObjectKey --> The response Object of the request -* -- kPMKAFResponseTaskKey --> The task that initiated the request -* -* @param urlStringsArray an array of relative URL Strings -* @param parametersArray an associative array of parameters to be passed to their corresponding -* URL strings (will be associated by their position in the array, so make sure they match) -*/ -- (AFPromise *)HEADMultiple:(NSArray *)urlStringsArray parameters:(NSArray *)parametersArray; - -/** -* @brief Performs a PATCH request on multiple URLs. It uses 'when' under the hood -* -* The parameters to be passed on URLs are given using an the associative array in 'parametersArray'. If you want to pass 'nil' as parameters, pass -* an empty NSDictionary instead. -* -* When all requests are finished a 'then(^(NSArray *responsesArray){})' will return an array with NSDictionaries. Each one will have two values: -* -- kPMKAFResponseObjectKey --> The response Object of the request -* -- kPMKAFResponseTaskKey --> The task that initiated the request -* -* @param urlStringsArray an array of relative URL Strings -* @param parametersArray an associative array of parameters to be passed to their corresponding -* URL strings (will be associated by their position in the array, so make sure they match) -*/ -- (AFPromise *)PATCHMultiple:(NSArray *)urlStringsArray parameters:(NSArray *)parametersArray; - - -/** -* @brief Performs a DELETE request on multiple URLs. It uses 'when' under the hood -* -* The parameters to be passed on URLs are given using an the associative array in 'parametersArray'. If you want to pass 'nil' as parameters, pass -* an empty NSDictionary instead. -* -* When all requests are finished a 'then(^(NSArray *responsesArray){})' will return an array with NSDictionaries. Each one will have two values: -* -- kPMKAFResponseObjectKey --> The response Object of the request -* -- kPMKAFResponseTaskKey --> The task that initiated the request -* -* @param urlStringsArray an array of relative URL Strings -* @param parametersArray an associative array of parameters to be passed to their corresponding -* URL strings (will be associated by their position in the array, so make sure they match) -*/ -- (AFPromise *)DELETEMultiple:(NSArray *)urlStringsArray parameters:(NSArray *)parametersArray; -@end - - @interface AFHTTPSessionManager (Promises) @property (nonatomic, assign) BOOL startTasksImmediately; @@ -207,7 +75,7 @@ FOUNDATION_EXPORT const NSString *AFHTTPRequestOperationErrorKey; */ - (AFPromise *)uploadTaskWithRequest:(NSURLRequest *)request fromFile:(NSURL *)fileURL - progress:(NSProgress * __autoreleasing *)progress + progress:(void (^)(NSProgress *uploadProgress)) uploadProgressBlock uploadTask:(NSURLSessionTask * __autoreleasing *)uploadTask; /** @@ -225,7 +93,7 @@ FOUNDATION_EXPORT const NSString *AFHTTPRequestOperationErrorKey; */ - (AFPromise *)uploadTaskWithRequest:(NSURLRequest *)request fromData:(NSData *)bodyData - progress:(NSProgress * __autoreleasing *)progress + progress:(void (^)(NSProgress *uploadProgress)) uploadProgressBlock uploadTask:(NSURLSessionTask * __autoreleasing *)uploadTask; /** @@ -241,7 +109,7 @@ FOUNDATION_EXPORT const NSString *AFHTTPRequestOperationErrorKey; * @return */ - (AFPromise *)uploadTaskWithStreamedRequest:(NSURLRequest *)request - progress:(NSProgress * __autoreleasing *)progress + progress:(void (^)(NSProgress *uploadProgress)) uploadProgressBlock uploadTask:(NSURLSessionTask * __autoreleasing *)uploadTask; /** @@ -258,7 +126,7 @@ FOUNDATION_EXPORT const NSString *AFHTTPRequestOperationErrorKey; * @return */ - (AFPromise *)downloadTaskWithRequest:(NSURLRequest *)request - progress:(NSProgress * __autoreleasing *)progress + progress:(void (^)(NSProgress *uploadProgress)) uploadProgressBlock destination:(NSURL * (^)(NSURL *targetPath, NSURLResponse *response))destination downloadTask:(NSURLSessionTask * __autoreleasing *)downloadTask; @@ -276,7 +144,7 @@ FOUNDATION_EXPORT const NSString *AFHTTPRequestOperationErrorKey; * @return */ - (AFPromise *)downloadTaskWithResumeData:(NSData *)resumeData - progress:(NSProgress * __autoreleasing *)progress + progress:(void (^)(NSProgress *uploadProgress)) uploadProgressBlock destination:(NSURL * (^)(NSURL *targetPath, NSURLResponse *response))destination downloadTask:(NSURLSessionTask * __autoreleasing *)downloadTask; diff --git a/PromiseKit+AFNetworking/AFNetworking+PromiseKit.m b/PromiseKit+AFNetworking/AFNetworking+PromiseKit.m index 13c0231..0962b59 100644 --- a/PromiseKit+AFNetworking/AFNetworking+PromiseKit.m +++ b/PromiseKit+AFNetworking/AFNetworking+PromiseKit.m @@ -38,169 +38,6 @@ of this software and associated documentation files (the "Software"), to deal AF_OPERATION_PUT } AF_OPERATION_KIND; -@implementation AFHTTPRequestOperation (Promises) - -- (AFPromise *)promise -{ - return [self promiseByStartingImmediately:NO]; -} - -- (AFPromise *)promiseAndStartImmediately -{ - return [self promiseByStartingImmediately:YES]; -} - -- (AFPromise *)promiseByStartingImmediately:(BOOL)startImmediately -{ - return [AFPromise promiseWithResolverBlock:^(PMKResolver resolver){ - [self setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { - resolver(PMKManifold(responseObject, operation)); - } failure:^(AFHTTPRequestOperation *operation, NSError *error) { - id info = error.userInfo.mutableCopy; - info[AFHTTPRequestOperationErrorKey] = operation; - id newerror = [NSError errorWithDomain:error.domain code:error.code userInfo:info]; - resolver(newerror); - }]; - if (startImmediately) { - [self start]; - } - }]; -} - -+ (AFPromise *)request:(NSURLRequest *)request -{ - NSOperationQueue *q = [NSOperationQueue currentQueue] ? : [NSOperationQueue mainQueue]; - return [self request:request queue:q]; -} - -+ (AFPromise *)request:(NSURLRequest *)request queue:(NSOperationQueue *)queue -{ - AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; - [queue addOperation:operation]; - return [operation promise]; -} - -@end - - - -@implementation AFHTTPRequestOperationManager (Promises) - -- (AFPromise *)POST:(NSString *)URLString parameters:(id)parameters -{ - return [[self POST:URLString parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {} failure:^(AFHTTPRequestOperation *operation, NSError *error) {}] promise]; -} - -- (AFPromise *)POSTMultiple:(NSArray *)urlStringsArray parameters:(NSArray *)parametersArray -{ - return [self operationSequenceWithType:AF_OPERATION_POST urls:urlStringsArray parameters:parametersArray]; -} - - -- (AFPromise *)POST:(NSString *)URLString parameters:(id)parameters constructingBodyWithBlock:(void (^)(id))block -{ - return [[self POST:URLString parameters:parameters constructingBodyWithBlock:block success:nil failure:nil] promise]; -} - -- (AFPromise *)GET:(NSString *)URLString parameters:(id)parameters -{ - return [[self GET:URLString parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {} failure:^(AFHTTPRequestOperation *operation, NSError *error) {}] promise]; -} - -- (AFPromise *)GETMultiple:(NSArray *)urlStringsArray parameters:(NSArray *)parametersArray -{ - return [self operationSequenceWithType:AF_OPERATION_GET urls:urlStringsArray parameters:parametersArray]; -} - -- (AFPromise *)PUT:(NSString *)URLString parameters:(id)parameters; -{ - return [[self PUT:URLString parameters:parameters success:nil failure:nil] promise]; -} - -- (AFPromise *)PUTMultiple:(NSArray *)urlStringsArray parameters:(NSArray *)parametersArray -{ - return [self operationSequenceWithType:AF_OPERATION_PUT urls:urlStringsArray parameters:parametersArray]; -} - -- (AFPromise *)DELETE:(NSString *)URLString parameters:(id)parameters -{ - return [[self DELETE:URLString parameters:parameters success:nil failure:nil] promise]; -} - -- (AFPromise *)DELETEMultiple:(NSArray *)urlStringsArray parameters:(NSArray *)parametersArray -{ - return [self operationSequenceWithType:AF_OPERATION_DELETE urls:urlStringsArray parameters:parametersArray]; -} - - -- (AFPromise *)PATCH:(NSString *)URLString parameters:(id)parameters -{ - return [[self PATCH:URLString parameters:parameters success:nil failure:nil] promise]; -} - -- (AFPromise *)PATCHMultiple:(NSArray *)urlStringsArray parameters:(NSArray *)parametersArray -{ - return [self operationSequenceWithType:AF_OPERATION_PATCH urls:urlStringsArray parameters:parametersArray]; -} - - -- (AFPromise *)HEAD:(NSString *)URLString parameters:(id)parameters -{ - return [[self HEAD:URLString parameters:parameters success:nil failure:nil] promise]; -} - -- (AFPromise *)HEADMultiple:(NSArray *)urlStringsArray parameters:(NSArray *)parametersArray -{ - return [self operationSequenceWithType:AF_OPERATION_HEAD urls:urlStringsArray parameters:parametersArray]; -} - - -- (AFPromise *)operationSequenceWithType:(AF_OPERATION_KIND)operationKind urls:(NSArray *)urlStringsArray parameters:(NSArray *)parametersArray -{ - assert (urlStringsArray.count == parametersArray.count); - NSMutableArray *operations = [NSMutableArray array]; - - for (int i=0; i))block { return [AFPromise promiseWithResolverBlock:^(PMKResolver resolve) { - [[self POST:urlString parameters:parameters constructingBodyWithBlock:block success:^(NSURLSessionDataTask *task, id responseObject) { + [[self POST:urlString parameters:parameters constructingBodyWithBlock:block progress:nil success:^(NSURLSessionDataTask *task, id responseObject) { resolve(PMKManifold(responseObject, task)); } failure:^(NSURLSessionDataTask *task, NSError *error) { resolve(error); @@ -368,7 +205,8 @@ - (AFPromise *)POST:(NSString *)urlString parameters:(id)parameters constructing - (AFPromise *)GET:(NSString *)urlString parameters:(id)parameters { return [AFPromise promiseWithResolverBlock:^(PMKResolver resolve) { - [[self GET:urlString parameters:parameters success:^(NSURLSessionDataTask *task, id responseObject) { + + [[self GET:urlString parameters:parameters progress:nil success:^(NSURLSessionDataTask *task, id responseObject) { resolve(PMKManifold(responseObject, task)); } failure:^(NSURLSessionDataTask *task, NSError *error) { resolve(error); diff --git a/PromiseKit+AFNetworking/ViewController.m b/PromiseKit+AFNetworking/ViewController.m index 3bbde20..07df216 100644 --- a/PromiseKit+AFNetworking/ViewController.m +++ b/PromiseKit+AFNetworking/ViewController.m @@ -12,7 +12,6 @@ @interface ViewController () -@property (nonatomic, strong) AFHTTPRequestOperationManager *operationManager; @property (nonatomic, strong) AFHTTPSessionManager *sessionManager; @end @@ -32,18 +31,6 @@ - (void)viewDidLoad } }); - - self.operationManager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:[[NSURL alloc] initWithString:@"http://oramind.com"]]; - self.operationManager.responseSerializer = [AFHTTPResponseSerializer serializer]; - - [self.operationManager GETMultiple:@[@"/", @"/", @"/", @"/"] parameters:@[@{},@{},@{},@{}]].then(^(NSArray * responsesArray){ - for (NSDictionary *responseDictionary in responsesArray){ - NSLog(@"operation description: %@", responseDictionary[kPMKAFResponseOperationKey]); - NSLog(@"response object description: %@", responseDictionary[kPMKAFResponseObjectKey]); - } - }); - - //get the task NSURLSessionTask *task;