Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Replacing AFHTTPClient -enqueueHTTPRequestOperationWithRequest:... wi…

…th -HTTPRequestOperationWithRequest:..., thereby decoupling the automatic HTTP operation creation from enqueuing them
  • Loading branch information...
commit afbd799e3b82b3682588cb27d14f60053bd2961b 1 parent ee88f67
@mattt mattt authored
Showing with 25 additions and 23 deletions.
  1. +13 −15 AFNetworking/AFHTTPClient.h
  2. +12 −8 AFNetworking/AFHTTPClient.m
View
28 AFNetworking/AFHTTPClient.h
@@ -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.
View
20 AFNetworking/AFHTTPClient.m
@@ -313,9 +313,9 @@ - (NSMutableURLRequest *)multipartFormRequestWithMethod:(NSString *)method
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 @@ - (void)enqueueHTTPRequestOperationWithRequest:(NSURLRequest *)urlRequest
[operation setCompletionBlockWithSuccess:success failure:failure];
- [self enqueueHTTPRequestOperation:operation];
+ return operation;
}
- (void)enqueueHTTPRequestOperation:(AFHTTPRequestOperation *)operation {
@@ -356,7 +356,8 @@ - (void)getPath:(NSString *)path
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 @@ - (void)postPath:(NSString *)path
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 @@ - (void)putPath:(NSString *)path
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 @@ - (void)deletePath:(NSString *)path
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
Please sign in to comment.
Something went wrong with that request. Please try again.