Replacing AFHTTPClient -enqueueHTTPRequestOperationWithRequest:... with -HTTPRequestOperationWithRequest:..., thereby decoupling the automatic HTTP operation creation from enqueuing them
This commit is contained in:
parent
ee88f6795e
commit
afbd799e3b
2 changed files with 25 additions and 23 deletions
|
|
@ -227,25 +227,27 @@ typedef enum {
|
|||
parameters:(NSDictionary *)parameters
|
||||
constructingBodyWithBlock:(void (^)(id <AFMultipartFormData> formData))block;
|
||||
|
||||
|
||||
///--------------------------------
|
||||
/// @name Enqueuing HTTP Operations
|
||||
///--------------------------------
|
||||
///-------------------------------
|
||||
/// @name Creating HTTP Operations
|
||||
///-------------------------------
|
||||
|
||||
/**
|
||||
Creates and enqueues an `AFHTTPRequestOperation` to the HTTP client's operation queue.
|
||||
Creates an `AFHTTPRequestOperation`
|
||||
|
||||
In order to determine what kind of operation is enqueued, each registered subclass conforming to the `AFHTTPClient` protocol is consulted in turn to see if it can handle the specific request. The first class to return `YES` when sent a `canProcessRequest:` message is used to generate an operation using `HTTPRequestOperationWithRequest:success:failure:`.
|
||||
|
||||
|
||||
@param request The request object to be loaded asynchronously during execution of the operation.
|
||||
@param success A block object to be executed when the request operation finishes successfully. This block has no return value and takes a single argument, which is an object created from the response data of request.
|
||||
@param failure A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the resonse data. This block has no return value and takes a single argument, which is the `NSError` object describing the network or parsing error that occurred.
|
||||
|
||||
@see `AFHTTPClientOperation`
|
||||
*/
|
||||
- (void)enqueueHTTPRequestOperationWithRequest:(NSURLRequest *)request
|
||||
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
|
||||
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure;
|
||||
- (AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSURLRequest *)request
|
||||
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
|
||||
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure;
|
||||
|
||||
///----------------------------------------
|
||||
/// @name Managing Enqueued HTTP Operations
|
||||
///----------------------------------------
|
||||
|
||||
/**
|
||||
Enqueues an `AFHTTPRequestOperation` to the HTTP client's operation queue.
|
||||
|
||||
|
|
@ -253,10 +255,6 @@ typedef enum {
|
|||
*/
|
||||
- (void)enqueueHTTPRequestOperation:(AFHTTPRequestOperation *)operation;
|
||||
|
||||
///---------------------------------
|
||||
/// @name Cancelling HTTP Operations
|
||||
///---------------------------------
|
||||
|
||||
/**
|
||||
Cancels all operations in the HTTP client's operation queue that match the specified HTTP method and URL.
|
||||
|
||||
|
|
|
|||
|
|
@ -313,9 +313,9 @@ static NSString * AFPropertyListStringFromParameters(NSDictionary *parameters) {
|
|||
return request;
|
||||
}
|
||||
|
||||
- (void)enqueueHTTPRequestOperationWithRequest:(NSURLRequest *)urlRequest
|
||||
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
|
||||
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
|
||||
- (AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSURLRequest *)urlRequest
|
||||
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
|
||||
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
|
||||
{
|
||||
AFHTTPRequestOperation *operation = nil;
|
||||
NSString *className = nil;
|
||||
|
|
@ -333,7 +333,7 @@ static NSString * AFPropertyListStringFromParameters(NSDictionary *parameters) {
|
|||
|
||||
[operation setCompletionBlockWithSuccess:success failure:failure];
|
||||
|
||||
[self enqueueHTTPRequestOperation:operation];
|
||||
return operation;
|
||||
}
|
||||
|
||||
- (void)enqueueHTTPRequestOperation:(AFHTTPRequestOperation *)operation {
|
||||
|
|
@ -356,7 +356,8 @@ static NSString * AFPropertyListStringFromParameters(NSDictionary *parameters) {
|
|||
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
|
||||
{
|
||||
NSURLRequest *request = [self requestWithMethod:@"GET" path:path parameters:parameters];
|
||||
[self enqueueHTTPRequestOperationWithRequest:request success:success failure:failure];
|
||||
AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:success failure:failure];
|
||||
[self enqueueHTTPRequestOperation:operation];
|
||||
}
|
||||
|
||||
- (void)postPath:(NSString *)path
|
||||
|
|
@ -365,7 +366,8 @@ static NSString * AFPropertyListStringFromParameters(NSDictionary *parameters) {
|
|||
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
|
||||
{
|
||||
NSURLRequest *request = [self requestWithMethod:@"POST" path:path parameters:parameters];
|
||||
[self enqueueHTTPRequestOperationWithRequest:request success:success failure:failure];
|
||||
AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:success failure:failure];
|
||||
[self enqueueHTTPRequestOperation:operation];
|
||||
}
|
||||
|
||||
- (void)putPath:(NSString *)path
|
||||
|
|
@ -374,7 +376,8 @@ static NSString * AFPropertyListStringFromParameters(NSDictionary *parameters) {
|
|||
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
|
||||
{
|
||||
NSURLRequest *request = [self requestWithMethod:@"PUT" path:path parameters:parameters];
|
||||
[self enqueueHTTPRequestOperationWithRequest:request success:success failure:failure];
|
||||
AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:success failure:failure];
|
||||
[self enqueueHTTPRequestOperation:operation];
|
||||
}
|
||||
|
||||
- (void)deletePath:(NSString *)path
|
||||
|
|
@ -383,7 +386,8 @@ static NSString * AFPropertyListStringFromParameters(NSDictionary *parameters) {
|
|||
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
|
||||
{
|
||||
NSURLRequest *request = [self requestWithMethod:@"DELETE" path:path parameters:parameters];
|
||||
[self enqueueHTTPRequestOperationWithRequest:request success:success failure:failure];
|
||||
AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:success failure:failure];
|
||||
[self enqueueHTTPRequestOperation:operation];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue