Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
BB9z committed Sep 13, 2021
2 parents 381904a + 59e5704 commit dd6e376
Show file tree
Hide file tree
Showing 16 changed files with 71 additions and 64 deletions.
2 changes: 1 addition & 1 deletion Example/iOS-Swift/Scenes/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="FPp-Vf-YK5" userLabel="Response Area">
<rect key="frame" x="180" y="0.0" width="325" height="623"/>
<subviews>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" text="Resopnse" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="VNd-yL-ZI4">
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" text="Response" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="VNd-yL-ZI4">
<rect key="frame" x="8" y="8" width="309" height="607"/>
<color key="textColor" systemColor="labelColor" cocoaTouchSystemColor="darkTextColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
Expand Down
2 changes: 1 addition & 1 deletion Example/iOS-Swift/Scenes/zh-Hans.lproj/Main.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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"; */
Expand Down
2 changes: 1 addition & 1 deletion Example/iOS-Swift/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion Example/iOS-Swift/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"HUDState.Loadding" = "载入中...";
"HUDState.Uploading" = "上传中...";

/// - RFAPI Build-in
/// - RFAPI Built-in

"RFAPI.Error.GeneralFailureReasonApp" = "很可能是应用 bug";
"RFAPI.Error.GeneralFailureReasonServer" = "可能服务器正在升级或者维护,也可能是应用 bug";
Expand Down
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 => '.'
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions README.zh-hans.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -130,7 +130,7 @@ defineManager.setDefinesWithRulesInfo(rules)
{
"FormUpload": {
"Method": "POST",
"Path": "commom/formupload",
"Path": "common/formupload",
"Serializer": "AFHTTPRequestSerializer",
"Response Serializer": "AFPropertyListResponseSerializer",
"Response Type": 1
Expand Down
2 changes: 1 addition & 1 deletion RFAPI.podspec
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion Sources/RFAPI/Define/RFAPIDefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
22 changes: 13 additions & 9 deletions Sources/RFAPI/RFAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ typedef void(^RFAPIRequestCombinedCompletionCallback)(id<RFAPITask> __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
Expand All @@ -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<NSString *, id> *parameters;

Expand All @@ -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;

Expand Down Expand Up @@ -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.
Expand All @@ -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<RFAPITask> __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<RFAPITask> __nullable task, BOOL success))finished NS_SWIFT_NAME(finished(_:));

/// Set callback to be executed when the request is complated.
- (void)setComplationCallback:(nullable void (^)(id<RFAPITask> __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<RFAPITask> __nullable task, id __nullable responseObject, NSError *__nullable error))completion NS_SWIFT_NAME(completion(_:));

- (void)setComplationCallback:(nullable void (^)(id<RFAPITask> __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
37 changes: 20 additions & 17 deletions Sources/RFAPI/RFAPI.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -242,11 +242,11 @@ - (nullable NSMutableURLRequest *)_RFAPI_makeURLRequestWithDefine:(RFAPIDefine *
NSMutableDictionary *headers = [NSMutableDictionary.alloc initWithCapacity:4];
[self preprocessingRequestParameters:&parameters 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<AFURLRequestSerialization> serializer = [self.defineManager requestSerializerForDefine:define];
Expand Down Expand Up @@ -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, ^{
Expand Down Expand Up @@ -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);
}
});
Expand Down Expand Up @@ -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"];
Expand All @@ -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);
}
});
Expand All @@ -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);
}
Expand Down Expand Up @@ -535,8 +535,11 @@ - (void)setFailureCallback:(void (^)(id<RFAPITask> _Nullable, NSError * _Nonnull
- (void)setFinishedCallback:(void (^)(id<RFAPITask> _Nullable, BOOL))finished {
self.finished = finished;
}
- (void)setComplationCallback:(void (^)(id<RFAPITask> _Nullable, id _Nullable, NSError * _Nullable))complation {
self.combinedComplation = complation;
- (void)setCompletionCallback:(void (^)(id<RFAPITask> _Nullable, id _Nullable, NSError * _Nullable))completion {
self.combinedCompletion = completion;
}
- (void)setComplationCallback:(void (^)(id<RFAPITask> _Nullable, id _Nullable, NSError * _Nullable))completion {
self.combinedCompletion = completion;
}

@end
Expand Down
6 changes: 3 additions & 3 deletions Sources/RFAPI/URLSession/RFAPISessionTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions Tests/Shared/TestConvention.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private class TestConvention: XCTestCase {
c.finished { _, _ in
expFinsh1.fulfill()
}
c.complation { _, _, _ in
c.completion { _, _, _ in
expComplete1.fulfill()
}
}
Expand All @@ -53,7 +53,7 @@ private class TestConvention: XCTestCase {
c.finished { _, _ in
expFinsh2.fulfill()
}
c.complation { _, _, _ in
c.completion { _, _, _ in
expComplete2.fulfill()
}
}
Expand All @@ -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)
}
}
Expand All @@ -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")

Expand All @@ -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()
}
Expand Down
Loading

0 comments on commit dd6e376

Please sign in to comment.