Skip to content

Commit 381904a

Browse files
committed
Merge branch 'develop'
2 parents cffaca5 + 9e1c2b5 commit 381904a

5 files changed

Lines changed: 23 additions & 4 deletions

File tree

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2014-2016, 2018-2020 RFUI.
3+
Copyright (c) 2014-2016, 2018-2021 RFUI.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

RFAPI.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'RFAPI'
3-
s.version = '2.0.0'
3+
s.version = '2.1.0'
44
s.summary = 'RFAPI is a network request library specially designed for API requests. It is a URL session wrapper base on AFNetworking.'
55

66
s.homepage = 'https://github.com/RFUI/RFAPI'

Sources/RFAPI/RFAPI.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
RFAPI
33
4-
Copyright © 2014-2016, 2018-2020 BB9z
4+
Copyright © 2014-2016, 2018-2021 BB9z
55
https://github.com/RFUI/RFAPI
66
77
The MIT License (MIT)
@@ -230,6 +230,9 @@ FOUNDATION_EXTERN NSErrorDomain __nonnull const RFAPIErrorDomain;
230230
/// Customization URL request object
231231
@property (nullable) NSMutableURLRequest *__nonnull (^requestCustomization)(NSMutableURLRequest *__nonnull request);
232232

233+
/// Allow transform resesoinse object in the processing queue. The return value will become the final responseObject.
234+
@property (nullable) id __nullable (^responseObjectTransformer)(RFAPIDefine *__nonnull define, id __nullable responseObject);
235+
233236
/// Identifier for request. If `nil`, the api name will be used.
234237
@property (nullable) NSString *identifier;
235238

@@ -279,6 +282,9 @@ FOUNDATION_EXTERN NSErrorDomain __nonnull const RFAPIErrorDomain;
279282
/// This may be used to test whether the UI is in a proper state when network latency.
280283
@property NSTimeInterval debugDelayRequestSend;
281284

285+
/// If no nil, simulate the request fail with the given error code.
286+
@property NSInteger debugRequestFailWithCode;
287+
282288
/// This value will be passed to the task object.
283289
@property (nullable) NSDictionary *userInfo;
284290

Sources/RFAPI/RFAPI.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,13 @@ - (void)cancelOperationsWithGroupIdentifier:(nullable NSString *)identifier {
194194
[self.networkActivityIndicatorManager showMessage:message];
195195
});
196196
}
197+
198+
if (context.debugRequestFailWithCode != 0) {
199+
NSError *error = [NSError errorWithDomain:RFAPIErrorDomain code:context.debugRequestFailWithCode userInfo:@{ NSLocalizedDescriptionKey: [NSString.alloc initWithFormat:@"Debug error, code: %@", @(context.debugRequestFailWithCode)] }];
200+
[self _RFAPI_executeTaskCallback:task failure:error];
201+
return task;
202+
}
203+
197204
dispatch_block_t work = ^{
198205
if (task.isEnd) return;
199206
[dataTask resume];
@@ -218,6 +225,7 @@ - (void)transferContext:(RFAPIRequestConext *)context toTask:(_RFAPISessionTask
218225
task.failure = context.failure;
219226
task.complation = context.finished;
220227
task.combinedComplation = context.combinedComplation;
228+
task.responseObjectTransformer = context.responseObjectTransformer;
221229
task.debugDelayRequestSend = context.debugDelayRequestSend;
222230
task.userInfo = context.userInfo;
223231
}
@@ -362,6 +370,9 @@ - (void)_RFAPI_handleTaskComplete:(_RFAPISessionTask *)task response:(NSURLRespo
362370
[self _RFAPI_executeTaskCallback:task failure:error];
363371
}
364372
else {
373+
if (task.responseObjectTransformer) {
374+
modelObject = task.responseObjectTransformer(task.define, modelObject);
375+
}
365376
[self _RFAPI_executeTaskCallback:task success:modelObject];
366377
}
367378
return;

Sources/RFAPI/URLSession/RFAPISessionTask.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
RFAPISessionTask
33
RFAPI
44
5-
Copyright © 2019-2020 BB9z
5+
Copyright © 2019-2021 BB9z
66
https://github.com/RFUI/RFAPI
77
88
The MIT License (MIT)
@@ -47,6 +47,8 @@ typedef void(^RFAPITaskComplation)(id __nullable responseObject, NSURLResponse *
4747
@property (nullable) NSDictionary *userInfo;
4848
@property NSTimeInterval debugDelayRequestSend;
4949

50+
@property (nullable) id __nullable (^responseObjectTransformer)(RFAPIDefine *__nonnull define, id __nullable responseObject);
51+
5052
#pragma mark - States
5153

5254
@property (readonly, copy, nullable, nonatomic) NSURLRequest *currentRequest;

0 commit comments

Comments
 (0)