diff --git a/Example/iOS-Swift/Scenes/Base.lproj/Main.storyboard b/Example/iOS-Swift/Scenes/Base.lproj/Main.storyboard index 3cf16df..04bd1f5 100644 --- a/Example/iOS-Swift/Scenes/Base.lproj/Main.storyboard +++ b/Example/iOS-Swift/Scenes/Base.lproj/Main.storyboard @@ -137,7 +137,7 @@ - + diff --git a/Example/iOS-Swift/Scenes/zh-Hans.lproj/Main.strings b/Example/iOS-Swift/Scenes/zh-Hans.lproj/Main.strings index 38b9703..51b284a 100644 --- a/Example/iOS-Swift/Scenes/zh-Hans.lproj/Main.strings +++ b/Example/iOS-Swift/Scenes/zh-Hans.lproj/Main.strings @@ -17,7 +17,7 @@ /* Class = "UIButton"; normalTitle = "Start"; ObjectID = "TWh-Mz-u8r"; */ "TWh-Mz-u8r.normalTitle" = "开始"; -/* Class = "UITextView"; text = "Resopnse"; ObjectID = "VNd-yL-ZI4"; */ +/* Class = "UITextView"; text = "Response"; ObjectID = "VNd-yL-ZI4"; */ "VNd-yL-ZI4.text" = "请求响应"; /* Class = "UILabel"; text = "Title"; ObjectID = "XT4-OY-1f4"; */ diff --git a/Example/iOS-Swift/en.lproj/Localizable.strings b/Example/iOS-Swift/en.lproj/Localizable.strings index 29223af..ab8f2e1 100644 --- a/Example/iOS-Swift/en.lproj/Localizable.strings +++ b/Example/iOS-Swift/en.lproj/Localizable.strings @@ -7,7 +7,7 @@ "HUDState.Loadding" = "Loadding..."; "HUDState.Uploading" = "Uploading..."; -/// - RFAPI Build-in +/// - RFAPI Built-in "RFAPI.Error.GeneralFailureReasonApp" = "It seems to be an application bug"; "RFAPI.Error.GeneralFailureReasonServer" = "It may be the server being upgraded or maintained, or it may be an application bug"; diff --git a/Example/iOS-Swift/zh-Hans.lproj/Localizable.strings b/Example/iOS-Swift/zh-Hans.lproj/Localizable.strings index 5d905d7..61dbabf 100644 --- a/Example/iOS-Swift/zh-Hans.lproj/Localizable.strings +++ b/Example/iOS-Swift/zh-Hans.lproj/Localizable.strings @@ -7,7 +7,7 @@ "HUDState.Loadding" = "载入中..."; "HUDState.Uploading" = "上传中..."; -/// - RFAPI Build-in +/// - RFAPI Built-in "RFAPI.Error.GeneralFailureReasonApp" = "很可能是应用 bug"; "RFAPI.Error.GeneralFailureReasonServer" = "可能服务器正在升级或者维护,也可能是应用 bug"; diff --git a/Podfile b/Podfile index 359dda7..fae8fab 100644 --- a/Podfile +++ b/Podfile @@ -3,7 +3,7 @@ source 'https://github.com/PBPods/PBFlex.git' source 'https://cdn.cocoapods.org/' target 'Example-iOS' do - platform :ios, '8.0' + platform :ios, '9.0' pod 'RFMessageManager', :subspecs => ['SVProgressHUD'] pod 'RFAPI', :path => '.' diff --git a/README.md b/README.md index a05ee53..788c5dd 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ Only integration through CocoaPods is supported due to dependent factors. There pod 'RFAPI' ``` -Specify develop branch to install the lastest version: +Specify develop branch to install the latest version: ```ruby pod 'RFAPI', @@ -59,7 +59,7 @@ Unlike most network libraries, you cannot make a request with a url object. Inst ```swift let define = RFAPIDefine() define.name = RFAPIName(rawValue: "TopicListRecommended") -define.path = "https://exapmle.com/api/v2/topics/recommended" +define.path = "https://example.com/api/v2/topics/recommended" define.method = "GET" define.needsAuthorization = true define.responseExpectType = .objects @@ -71,7 +71,7 @@ Generally, a default define should be created. After that, you only need to prov ```swift let api = ... // RFAPI instance let defaultDefine = RFAPIDefine() -defaultDefine.baseURL = URL(string: "https://exapmle.com/") +defaultDefine.baseURL = URL(string: "https://example.com/") defaultDefine.pathPrefix = "api/v2/" defaultDefine.method = "GET" defaultDefine.needsAuthorization = true @@ -93,7 +93,7 @@ The more recommended way is to load the defines from the configuration file. You ```json { "DEFAULT": { - "Base": "https://exapmle.com/", + "Base": "https://example.com/", "Path Prefix": "api/v2/", "Method": "GET", "Authorization": true @@ -128,7 +128,7 @@ By default, the content format of request and response are both JSON. You can mo { "FormUpload": { "Method": "POST", - "Path": "commom/formupload", + "Path": "common/formupload", "Serializer": "AFHTTPRequestSerializer", "Response Serializer": "AFPropertyListResponseSerializer", "Response Type": 1 @@ -162,7 +162,7 @@ For more usage, checkout [Cookbook](Documents/Cookbook.md) When a request is cancelled, the failure callback will not be called. Also a failure callback will never be called with an `NSURLErrorCancelled` error parameter. - But you could get an `NSURLErrorCancelled` error from a RFAPITask object in the finished or complation callback. + But you could get an `NSURLErrorCancelled` error from a RFAPITask object in the finished or completion callback. * Most parameters are mutable diff --git a/README.zh-hans.md b/README.zh-hans.md index fcb752e..f120419 100644 --- a/README.zh-hans.md +++ b/README.zh-hans.md @@ -61,7 +61,7 @@ pod 'RFAPI', ```swift let define = RFAPIDefine() define.name = RFAPIName(rawValue: "TopicListRecommended") -define.path = "https://exapmle.com/api/v2/topics/recommended" +define.path = "https://example.com/api/v2/topics/recommended" define.method = "GET" define.needsAuthorization = true define.responseExpectType = .objects @@ -73,7 +73,7 @@ define.responseClass = "TopicEntity" ```swift let api = ... // RFAPI 实例 let defaultDefine = RFAPIDefine() -defaultDefine.baseURL = URL(string: "https://exapmle.com/") +defaultDefine.baseURL = URL(string: "https://example.com/") defaultDefine.pathPrefix = "api/v2/" defaultDefine.method = "GET" defaultDefine.needsAuthorization = true @@ -95,7 +95,7 @@ define.responseClass = "TopicEntity" ```json { "DEFAULT": { - "Base": "https://exapmle.com/", + "Base": "https://example.com/", "Path Prefix": "api/v2/", "Method": "GET", "Authorization": true @@ -130,7 +130,7 @@ defineManager.setDefinesWithRulesInfo(rules) { "FormUpload": { "Method": "POST", - "Path": "commom/formupload", + "Path": "common/formupload", "Serializer": "AFHTTPRequestSerializer", "Response Serializer": "AFPropertyListResponseSerializer", "Response Type": 1 diff --git a/RFAPI.podspec b/RFAPI.podspec index 73d25b8..2dae821 100644 --- a/RFAPI.podspec +++ b/RFAPI.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'RFAPI' - s.version = '2.1.0' + s.version = '2.1.1' s.summary = 'RFAPI is a network request library specially designed for API requests. It is a URL session wrapper base on AFNetworking.' s.homepage = 'https://github.com/RFUI/RFAPI' diff --git a/Sources/RFAPI/Define/RFAPIDefine.h b/Sources/RFAPI/Define/RFAPIDefine.h index 3dc2d64..45e8f94 100644 --- a/Sources/RFAPI/Define/RFAPIDefine.h +++ b/Sources/RFAPI/Define/RFAPIDefine.h @@ -19,7 +19,7 @@ typedef NSString * RFAPIName NS_EXTENSIBLE_STRING_ENUM; NSCopying, NSSecureCoding > -/// Used to get a deine from a RFAPIDefineManager +/// Used to get a define from a RFAPIDefineManager @property (copy, nullable) RFAPIName name; /** diff --git a/Sources/RFAPI/RFAPI.h b/Sources/RFAPI/RFAPI.h index 92b267f..ffddc9c 100644 --- a/Sources/RFAPI/RFAPI.h +++ b/Sources/RFAPI/RFAPI.h @@ -200,7 +200,7 @@ typedef void(^RFAPIRequestCombinedCompletionCallback)(id __nullable t /// Send array parameters FOUNDATION_EXTERN NSString *__nonnull const RFAPIRequestArrayParameterKey; -/// Sent parameters throgh qury string +/// Sent parameters through qury string FOUNDATION_EXTERN NSString *__nonnull const RFAPIRequestForceQuryStringParametersKey; /// Errors generated inside RFAPI @@ -217,7 +217,7 @@ FOUNDATION_EXTERN NSErrorDomain __nonnull const RFAPIErrorDomain; The parameters to be encoded. If you want to send an array parameters, set `RFAPIRequestArrayParameterKey` key with the array. - If you want some parameters sent throgh qury string of the URL, set `RFAPIRequestForceQuryStringParametersKey` with a dictionary contains these parameters. + If you want some parameters sent through qury string of the URL, set `RFAPIRequestForceQuryStringParametersKey` with a dictionary contains these parameters. */ @property (nullable) NSDictionary *parameters; @@ -239,7 +239,7 @@ FOUNDATION_EXTERN NSErrorDomain __nonnull const RFAPIErrorDomain; /// Group identifier for request. @property (nullable) NSString *groupIdentifier; -/// An activity message to be displayed durning the request executing. +/// An activity message to be displayed during the request executing. /// If the request is finished right after been make, eg. it has been already cached, the message will not be displayed. @property (nullable) RFNetworkActivityMessage *activityMessage; @@ -271,12 +271,14 @@ FOUNDATION_EXTERN NSErrorDomain __nonnull const RFAPIErrorDomain; /// It will not be called if the request is cancelled. @property (nullable) RFAPIRequestFailureCallback failure NS_SWIFT_NAME(failureCallback); -/// A block object to be executed when the request is complated. +/// A block object to be executed when the request is completed. @property (nullable) RFAPIRequestFinishedCallback finished NS_SWIFT_NAME(finishedCallback); -/// A block object to be executed when the request is complated. +/// A block object to be executed when the request is completed. /// Error will be nil if the request is cancelled. At this time, you could get the error object on the task object. -@property (nullable) RFAPIRequestCombinedCompletionCallback combinedComplation NS_SWIFT_NAME(complationCallback); +@property (nullable) RFAPIRequestCombinedCompletionCallback combinedCompletion NS_SWIFT_NAME(completionCallback); + +@property (nullable) RFAPIRequestCombinedCompletionCallback combinedComplation API_DEPRECATED_WITH_REPLACEMENT("combinedCompletion", macos(10.10, 10.10), ios(8.0, 8.0), tvos(9.0, 9.0)) NS_SWIFT_NAME(complationCallback); /// For debugging purposes, delaying the sending of network requests. /// This may be used to test whether the UI is in a proper state when network latency. @@ -298,10 +300,12 @@ FOUNDATION_EXTERN NSErrorDomain __nonnull const RFAPIErrorDomain; /// Set callback to be executed when the request finishes unsuccessfully. - (void)setFailureCallback:(nullable void (^)(id __nullable task, NSError *__nonnull error))failure NS_SWIFT_NAME(failure(_:)); -/// Set callback to be executed when the request is complated. +/// Set callback to be executed when the request is completed. - (void)setFinishedCallback:(nullable void (^)(id __nullable task, BOOL success))finished NS_SWIFT_NAME(finished(_:)); -/// Set callback to be executed when the request is complated. -- (void)setComplationCallback:(nullable void (^)(id __nullable task, id __nullable responseObject, NSError *__nullable error))complation NS_SWIFT_NAME(complation(_:)); +/// Set callback to be executed when the request is completed. +- (void)setCompletionCallback:(nullable void (^)(id __nullable task, id __nullable responseObject, NSError *__nullable error))completion NS_SWIFT_NAME(completion(_:)); + +- (void)setComplationCallback:(nullable void (^)(id __nullable task, id __nullable responseObject, NSError *__nullable error))complation API_DEPRECATED_WITH_REPLACEMENT("-setCompletionCallback:", macos(10.10, 10.10), ios(8.0, 8.0), tvos(9.0, 9.0)) NS_SWIFT_NAME(complation(_:)); @end diff --git a/Sources/RFAPI/RFAPI.m b/Sources/RFAPI/RFAPI.m index 4f25214..7e42fb9 100644 --- a/Sources/RFAPI/RFAPI.m +++ b/Sources/RFAPI/RFAPI.m @@ -223,8 +223,8 @@ - (void)transferContext:(RFAPIRequestConext *)context toTask:(_RFAPISessionTask task.bindControls = context.bindControls; task.success = context.success; task.failure = context.failure; - task.complation = context.finished; - task.combinedComplation = context.combinedComplation; + task.completion = context.finished; + task.combinedCompletion = context.combinedCompletion; task.responseObjectTransformer = context.responseObjectTransformer; task.debugDelayRequestSend = context.debugDelayRequestSend; task.userInfo = context.userInfo; @@ -242,11 +242,11 @@ - (nullable NSMutableURLRequest *)_RFAPI_makeURLRequestWithDefine:(RFAPIDefine * NSMutableDictionary *headers = [NSMutableDictionary.alloc initWithCapacity:4]; [self preprocessingRequestParameters:¶meters HTTPHeaders:&headers withParameters:context.parameters define:define context:context]; - // Creat URL + // Create URL NSURL *url = [self.defineManager requestURLForDefine:define parameters:parameters error:error]; if (!url) return nil; - // Creat URLRequest + // Create URLRequest NSMutableURLRequest *mutableRequest = nil; id serializer = [self.defineManager requestSerializerForDefine:define]; @@ -313,7 +313,7 @@ - (NSMutableURLRequest *)finalizeSerializedRequest:(NSMutableURLRequest *)reques return request; } -#pragma mark - Handel Response +#pragma mark - Handle Response - (void)_RFAPI_handleTaskComplete:(_RFAPISessionTask *)task response:(NSURLResponse *)response data:(NSData *)data error:(NSError *)error { dispatch_async(self.processingQueue, ^{ @@ -402,14 +402,14 @@ - (void)_RFAPI_executeTaskCallback:(nonnull _RFAPISessionTask *)task success:(nu scb(task, responseObject); } task.failure = nil; - RFAPIRequestFinishedCallback ccb = task.complation; + RFAPIRequestFinishedCallback ccb = task.completion; if (ccb) { - task.complation = nil; + task.completion = nil; ccb(task, YES); } - RFAPIRequestCombinedCompletionCallback cbcb = task.combinedComplation; + RFAPIRequestCombinedCompletionCallback cbcb = task.combinedCompletion; if (cbcb) { - task.combinedComplation = nil; + task.combinedCompletion = nil; cbcb(task, responseObject, nil); } }); @@ -437,7 +437,7 @@ - (void)_RFAPI_executeTaskCallback:(nonnull _RFAPISessionTask *)task failure:(no if (fcb) { fcb(task, error); } - else if (!task.combinedComplation) { + else if (!task.combinedCompletion) { if (messageManager) { dispatch_sync_on_main(^{ [messageManager alertError:error title:nil fallbackMessage:@"Request Failed"]; @@ -447,14 +447,14 @@ - (void)_RFAPI_executeTaskCallback:(nonnull _RFAPISessionTask *)task failure:(no } } task.failure = nil; - RFAPIRequestFinishedCallback ccb = task.complation; + RFAPIRequestFinishedCallback ccb = task.completion; if (ccb) { - task.complation = nil; + task.completion = nil; ccb(task, NO); } - RFAPIRequestCombinedCompletionCallback cbcb = task.combinedComplation; + RFAPIRequestCombinedCompletionCallback cbcb = task.combinedCompletion; if (cbcb) { - task.combinedComplation = nil; + task.combinedCompletion = nil; cbcb(task, nil, isCancel ? nil : error); } }); @@ -471,7 +471,7 @@ - (void)_RFAPI_executeContext:(nonnull RFAPIRequestConext *)context failure:(non if (ccb) { ccb(nil, NO); } - RFAPIRequestCombinedCompletionCallback cbcb = context.combinedComplation; + RFAPIRequestCombinedCompletionCallback cbcb = context.combinedCompletion; if (cbcb) { cbcb(nil, nil, error); } @@ -535,8 +535,11 @@ - (void)setFailureCallback:(void (^)(id _Nullable, NSError * _Nonnull - (void)setFinishedCallback:(void (^)(id _Nullable, BOOL))finished { self.finished = finished; } -- (void)setComplationCallback:(void (^)(id _Nullable, id _Nullable, NSError * _Nullable))complation { - self.combinedComplation = complation; +- (void)setCompletionCallback:(void (^)(id _Nullable, id _Nullable, NSError * _Nullable))completion { + self.combinedCompletion = completion; +} +- (void)setComplationCallback:(void (^)(id _Nullable, id _Nullable, NSError * _Nullable))completion { + self.combinedCompletion = completion; } @end diff --git a/Sources/RFAPI/URLSession/RFAPISessionTask.h b/Sources/RFAPI/URLSession/RFAPISessionTask.h index cb53bcd..98db929 100644 --- a/Sources/RFAPI/URLSession/RFAPISessionTask.h +++ b/Sources/RFAPI/URLSession/RFAPISessionTask.h @@ -14,7 +14,7 @@ The MIT License (MIT) @class _RFURLSessionManager; @class RFNetworkActivityMessage; -typedef void(^RFAPITaskComplation)(id __nullable responseObject, NSURLResponse *__nullable response, NSError *__nullable error); +typedef void(^RFAPITaskCompletion)(id __nullable responseObject, NSURLResponse *__nullable response, NSError *__nullable error); /** Private object manage status. @@ -73,9 +73,9 @@ typedef void(^RFAPITaskComplation)(id __nullable responseObject, NSURLResponse * /// Reset after use @property (nullable) RFAPIRequestFailureCallback failure; /// Reset after use -@property (nullable) RFAPIRequestFinishedCallback complation; +@property (nullable) RFAPIRequestFinishedCallback completion; /// Reset after use -@property (nullable) RFAPIRequestCombinedCompletionCallback combinedComplation; +@property (nullable) RFAPIRequestCombinedCompletionCallback combinedCompletion; // NO implementation diff --git a/Tests/Shared/TestConvention.swift b/Tests/Shared/TestConvention.swift index b07ccdd..e6af5e7 100644 --- a/Tests/Shared/TestConvention.swift +++ b/Tests/Shared/TestConvention.swift @@ -33,7 +33,7 @@ private class TestConvention: XCTestCase { c.finished { _, _ in expFinsh1.fulfill() } - c.complation { _, _, _ in + c.completion { _, _, _ in expComplete1.fulfill() } } @@ -53,7 +53,7 @@ private class TestConvention: XCTestCase { c.finished { _, _ in expFinsh2.fulfill() } - c.complation { _, _, _ in + c.completion { _, _, _ in expComplete2.fulfill() } } @@ -64,14 +64,14 @@ private class TestConvention: XCTestCase { let cannotMakeDefine = RFAPIDefine() cannotMakeDefine.name = RFAPIName(rawValue: "") var request = api.request(define: cannotMakeDefine) { c in - c.complation { task, _, _ in + c.completion { task, _, _ in XCTAssertNil(task) } } XCTAssertNil(request) request = api.request(name: "Anything"){ c in - c.complation { task, _, _ in + c.completion { task, _, _ in XCTAssertNotNil(task) } } @@ -98,7 +98,7 @@ private class TestConvention: XCTestCase { wait(for: [cannotMakeEndExpectation, cannotMakeCallbackExpectation], timeout: 0.1, enforceOrder: true) } - func testKeepInstanceBeforeTaskComplation() { + func testKeepInstanceBeforeTaskcompletion() { let requestComplateExpectation = expectation(description: "Request Complate") let managerDeallocExpectation = expectation(description: "Manager Dealloc") @@ -111,7 +111,7 @@ private class TestConvention: XCTestCase { api.deallocExpectation = managerDeallocExpectation api.request(define: define) { c in c.identifier = "" - c.complation { _, _, error in + c.completion { _, _, error in XCTAssertNil(error) requestComplateExpectation.fulfill() } diff --git a/Tests/Shared/TestRequest.swift b/Tests/Shared/TestRequest.swift index e330c5c..60cbe3f 100644 --- a/Tests/Shared/TestRequest.swift +++ b/Tests/Shared/TestRequest.swift @@ -52,13 +52,13 @@ private class TestRequest: XCTestCase { let successRequestFinishExpectation = expectation(description: "successRequest finish") let failureRequsetFinishExpectation = expectation(description: "failureRequset finish") let successRequest = api.request(name: "IsSuccess") { c in - c.complation { task, _, _ in + c.completion { task, _, _ in XCTAssertTrue(task!.isSuccess) successRequestFinishExpectation.fulfill() } } let failureRequset = api.request(name: "IsFailure") { c in - c.complation { task, _, _ in + c.completion { task, _, _ in XCTAssertFalse(task!.isSuccess) failureRequsetFinishExpectation.fulfill() } @@ -101,7 +101,7 @@ private class TestRequest: XCTestCase { XCTAssertNil(task.response) XCTAssertNil(task.responseObject) } - c.complation { task, rsp, error in + c.completion { task, rsp, error in XCTAssertNotNil(task) XCTAssertNil(rsp) XCTAssertNil(error) @@ -133,7 +133,7 @@ private class TestRequest: XCTestCase { XCTAssertNil(task.response) XCTAssertNil(task.responseObject) } - c.complation { task, rsp, error in + c.completion { task, rsp, error in XCTAssertNotNil(task) XCTAssertNil(rsp) XCTAssertNil(error) @@ -167,7 +167,7 @@ private class TestRequest: XCTestCase { XCTAssertNotNil(task) XCTAssertFalse(s) } - c.complation { task, rsp, error in + c.completion { task, rsp, error in XCTAssertNotNil(task) XCTAssertNil(rsp) XCTAssertNotNil(error) @@ -194,7 +194,7 @@ private class TestRequest: XCTestCase { XCTAssertNotNil(task) XCTAssertFalse(s) } - c.complation { task, rsp, error in + c.completion { task, rsp, error in debugPrint(error!) XCTAssertNotNil(task) XCTAssertNil(rsp) diff --git a/Tests/Shared/TestSubclass.swift b/Tests/Shared/TestSubclass.swift index 973e174..ad7d654 100644 --- a/Tests/Shared/TestSubclass.swift +++ b/Tests/Shared/TestSubclass.swift @@ -58,13 +58,13 @@ private class TestSubclass: XCTestCase { sendQueue.async { api.request(name: "IsSuccess") { c in c.userInfo = ["QueueName": sendQueue.label] - c.complation { _, _, _ in + c.completion { _, _, _ in completeExpectation.fulfill() } } api.request(name: "404") { c in c.userInfo = ["QueueName": sendQueue.label] - c.complation { _, _, _ in + c.completion { _, _, _ in completeExpectation2.fulfill() } } @@ -134,19 +134,19 @@ private class TestSubclass: XCTestCase { XCTAssertNil(activity.displayingMessage, "Custom failure should not display default error message") } - func testFailureRequestWithComplationCallback() { + func testFailureRequestWithCompletionCallback() { let activity = TestActivityManager() let api = Sub1API() api.networkActivityIndicatorManager = activity api.loadTestDefines() let finishExpectation = expectation(description: "Request finished") api.request(name: "IsFailure") { c in - c.complation({ _, _, _ in + c.completion({ _, _, _ in finishExpectation.fulfill() }) } wait(for: [finishExpectation], timeout: 5) XCTAssert(api.errorHandlerCalledCount == 1) - XCTAssertNil(activity.displayingMessage, "Custom complation should not display default error message") + XCTAssertNil(activity.displayingMessage, "Custom completion should not display default error message") } } diff --git a/Tests/iOS/TestControlBinding.swift b/Tests/iOS/TestControlBinding.swift index 0e82c91..78a745e 100644 --- a/Tests/iOS/TestControlBinding.swift +++ b/Tests/iOS/TestControlBinding.swift @@ -42,7 +42,7 @@ private class TestControlBinding: XCTestCase { c.timeoutInterval = 1 c.parameters = ["time": 10] c.bindControls = [button, barItem, activityIndicator, refreshControl, customControl] - c.complation { _, _, _ in + c.completion { _, _, _ in XCTAssertTrue(button.isEnabled) XCTAssertTrue(barItem.isEnabled) XCTAssertFalse(activityIndicator.isAnimating)