Revising AFJSONRequestOperation documentation
When nil is specified as acceptable status code or content type, don't perform those validations (i.e. accept any value)
This commit is contained in:
parent
0f5814b17f
commit
e2a00952aa
2 changed files with 16 additions and 7 deletions
|
|
@ -24,11 +24,15 @@
|
|||
|
||||
@interface AFJSONRequestOperation : AFHTTPRequestOperation
|
||||
|
||||
///---------------------------------------
|
||||
/// @name Creating JSON Request Operations
|
||||
///---------------------------------------
|
||||
|
||||
/**
|
||||
Creates and returns an `AFJSONRequestOperation` object and sets the specified success callback.
|
||||
|
||||
@param urlRequest The request object to be loaded asynchronously during execution of the operation
|
||||
@param success A block object to be executed when the JSON request operation finishes successfully, with a status code in the 2xx range, and with an acceptable [HTTP content type](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17) (e.g. `application/json`). This block has no return value and takes a single argument, which is the JSON object created from the response data of request, or nil if there was an error.
|
||||
@param success A block object to be executed when the JSON request operation finishes successfully, with a status code in the 2xx range, and with an acceptable content types (e.g. `application/json`). This block has no return value and takes a single argument, which is the JSON object created from the response data of request, or nil if there was an error.
|
||||
|
||||
@see defaultAcceptableStatusCodes
|
||||
@see defaultAcceptableContentTypes
|
||||
|
|
@ -43,7 +47,7 @@
|
|||
Creates and returns an `AFJSONRequestOperation` object and sets the specified success and failure callbacks.
|
||||
|
||||
@param urlRequest The request object to be loaded asynchronously during execution of the operation
|
||||
@param success A block object to be executed when the JSON request operation finishes successfully, with a status code in the 2xx range, and with an acceptable [HTTP content type](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17) (e.g. `application/json`). This block has no return value and takes a single argument, which is the JSON object created from the response data of request.
|
||||
@param success A block object to be executed when the JSON request operation finishes successfully, with a status code in the 2xx range, and with an acceptable content types (e.g. `application/json`). This block has no return value and takes a single argument, which is the JSON object created from the response data of request.
|
||||
@param failure A block object to be executed when the JSON request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the resonse data as JSON. 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 defaultAcceptableStatusCodes
|
||||
|
|
@ -60,9 +64,9 @@
|
|||
Creates and returns an `AFJSONRequestOperation` object and sets the specified success and failure callbacks, as well as the status codes and content types that are acceptable for a successful request.
|
||||
|
||||
@param urlRequest The request object to be loaded asynchronously during execution of the operation
|
||||
@param acceptableStatusCodes An `NSIndexSet` object that specifies the ranges of acceptable [HTTP status codes](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html). If you specify nil, all status codes will be considered acceptable.
|
||||
@param acceptableContentTypes An `NSSet` object that specifies the acceptable [HTTP content types](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17). If you specify nil, all content types will be considered acceptable.
|
||||
@param success A block object to be executed when the JSON request operation finishes successfully, with a status code in the 2xx range, and with an acceptable [HTTP content type](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17) (e.g. `application/json`). This block has no return value and takes a single argument, which is the JSON object created from the response data of request.
|
||||
@param acceptableStatusCodes An `NSIndexSet` object that specifies the ranges of acceptable status codes. If you specify nil, all status codes will be considered acceptable.
|
||||
@param acceptableContentTypes An `NSSet` object that specifies the acceptable content types. If you specify nil, all content types will be considered acceptable.
|
||||
@param success A block object to be executed when the JSON request operation finishes successfully, with a status code in the 2xx range, and with an acceptable content types (e.g. `application/json`). This block has no return value and takes a single argument, which is the JSON object created from the response data of request.
|
||||
@param failure A block object to be executed when the JSON request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the resonse data as JSON. This block has no return value and takes a single argument, which is the `NSError` object describing the network or parsing error that occurred.
|
||||
|
||||
@return A new JSON request operation
|
||||
|
|
@ -73,6 +77,11 @@
|
|||
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, id JSON))success
|
||||
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure;
|
||||
|
||||
|
||||
///----------------------------------
|
||||
/// @name Getting Default HTTP Values
|
||||
///----------------------------------
|
||||
|
||||
/**
|
||||
Returns an `NSIndexSet` object containing the ranges of acceptable [HTTP status codes](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html) used in operationWithRequest:success and operationWithRequest:success:failure.
|
||||
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ static dispatch_queue_t json_request_operation_processing_queue() {
|
|||
{
|
||||
return [self operationWithRequest:urlRequest completion:^(NSURLRequest *request, NSHTTPURLResponse *response, NSData *data, NSError *error) {
|
||||
if (!error) {
|
||||
if (![acceptableStatusCodes containsIndex:[response statusCode]]) {
|
||||
if (acceptableStatusCodes && ![acceptableStatusCodes containsIndex:[response statusCode]]) {
|
||||
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
|
||||
[userInfo setValue:[NSString stringWithFormat:NSLocalizedString(@"Expected status code %@, got %d", nil), acceptableStatusCodes, [response statusCode]] forKey:NSLocalizedDescriptionKey];
|
||||
[userInfo setValue:[request URL] forKey:NSURLErrorFailingURLErrorKey];
|
||||
|
|
@ -73,7 +73,7 @@ static dispatch_queue_t json_request_operation_processing_queue() {
|
|||
error = [[[NSError alloc] initWithDomain:AFNetworkingErrorDomain code:NSURLErrorBadServerResponse userInfo:userInfo] autorelease];
|
||||
}
|
||||
|
||||
if (![acceptableContentTypes containsObject:[response MIMEType]]) {
|
||||
if (acceptableContentTypes && ![acceptableContentTypes containsObject:[response MIMEType]]) {
|
||||
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
|
||||
[userInfo setValue:[NSString stringWithFormat:NSLocalizedString(@"Expected content type %@, got %@", nil), acceptableContentTypes, [response MIMEType]] forKey:NSLocalizedDescriptionKey];
|
||||
[userInfo setValue:[request URL] forKey:NSURLErrorFailingURLErrorKey];
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue