VKHTTPClient Class Reference

Inherits from VKObject : NSObject
Conforms to NSCoding
Declared in VKHTTPClient.h
VKHTTPClient.m

Overview

Class for NSURLRequests generation, made for VK API. Based on AFNetworking library ( https://github.com/AFNetworking/AFNetworking )

Initialization

+ getClient

Creates and initializes an VKHTTPClient object with the specified base URL.

+ (instancetype)getClient

Return Value

The newly-initialized HTTP client

Discussion

Creates and initializes an VKHTTPClient object with the specified base URL.

Declared In

VKHTTPClient.h

  operationQueue

The operation queue which manages operations enqueued by the HTTP client.

@property (readonly, nonatomic, strong) NSOperationQueue *operationQueue

Discussion

The operation queue which manages operations enqueued by the HTTP client.

Declared In

VKHTTPClient.h

Operations with default headers

– defaultValueForHeader:

Returns the value for the HTTP headers set in request objects created by the HTTP client.

- (NSString *)defaultValueForHeader:(NSString *)header

Parameters

header

The HTTP header to return the default value for

Return Value

The default value for the HTTP header, or nil if unspecified

Discussion

Returns the value for the HTTP headers set in request objects created by the HTTP client.

Declared In

VKHTTPClient.h

– setDefaultHeader:value:

Sets the value for the HTTP headers set in request objects made by the HTTP client. If nil, removes the existing value for that header.

- (void)setDefaultHeader:(NSString *)header value:(NSString *)value

Parameters

header

The HTTP header to set a default value for

value

The value set as default for the specified header, or `nil

Discussion

Sets the value for the HTTP headers set in request objects made by the HTTP client. If nil, removes the existing value for that header.

Declared In

VKHTTPClient.h

Preparing requests

– requestWithMethod:path:parameters:secure:

Creates an NSMutableURLRequest object with the specified HTTP method and path.

- (NSMutableURLRequest *)requestWithMethod:(NSString *)method path:(NSString *)path parameters:(NSDictionary *)parameters secure:(BOOL)secure

Parameters

method

The HTTP method for the request, such as GET, POST, PUT, or DELETE. This parameter must not be nil.

path

The path to be appended to the HTTP client’s base URL and used as the request URL. If nil, no path will be appended to the base URL.

parameters

The parameters to be either set as a query string for GET requests, or the request HTTP body.

secure

Use HTTPS or not

Return Value

An NSMutableURLRequest object

Discussion

Creates an NSMutableURLRequest object with the specified HTTP method and path.

If the HTTP method is GET, HEAD, or DELETE, the parameters will be used to construct a url-encoded query string that is appended to the request’s URL. Otherwise, the parameters will be encoded according to the value of the parameterEncoding property, and set as the request body.

Declared In

VKHTTPClient.h

– multipartFormRequestWithMethod:path:images:

Creates an NSMutableURLRequest object with the specified HTTP method and path, and constructs a multipart/form-data HTTP body, using the specified parameters and multipart form data block. See http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.2

- (NSMutableURLRequest *)multipartFormRequestWithMethod:(NSString *)method path:(NSString *)path images:(NSArray *)images

Parameters

method

The HTTP method for the request. This parameter must not be GET or HEAD, or nil.

path

The path to be appended to the HTTP client’s base URL and used as the request URL.

images

Upload images objects to append

Return Value

An NSMutableURLRequest object

Discussion

Creates an NSMutableURLRequest object with the specified HTTP method and path, and constructs a multipart/form-data HTTP body, using the specified parameters and multipart form data block. See http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.2

Multipart form requests are automatically streamed, reading files directly from disk along with in-memory data in a single HTTP body. The resulting NSMutableURLRequest object has an HTTPBodyStream property, so refrain from setting HTTPBodyStream or HTTPBody on this request object, as it will clear out the multipart form body stream.

Declared In

VKHTTPClient.h

Enqueuing operations

– enqueueOperation:

Enqueues an AFHTTPRequestOperation to the HTTP client’s operation queue.

- (void)enqueueOperation:(NSOperation *)operation

Parameters

operation

The HTTP request operation to be enqueued.

Discussion

Enqueues an AFHTTPRequestOperation to the HTTP client’s operation queue.

Declared In

VKHTTPClient.h

– enqueueBatchOfHTTPRequestOperations:progressBlock:completionBlock:

Enqueues the specified request operations into a batch. When each request operation finishes, the specified progress block is executed, until all of the request operations have finished, at which point the completion block also executes.

- (void)enqueueBatchOfHTTPRequestOperations:(NSArray *)operations progressBlock:(void ( ^ ) ( NSUInteger numberOfFinishedOperations , NSUInteger totalNumberOfOperations ))progressBlock completionBlock:(void ( ^ ) ( NSArray *operations ))completionBlock

Parameters

operations

The request operations used to be batched and enqueued.

progressBlock

A block object to be executed upon the completion of each request operation in the batch. This block has no return value and takes two arguments: the number of operations that have already finished execution, and the total number of operations.

completionBlock

A block object to be executed upon the completion of all of the request operations in the batch. This block has no return value and takes a single argument: the batched request operations.

Discussion

Enqueues the specified request operations into a batch. When each request operation finishes, the specified progress block is executed, until all of the request operations have finished, at which point the completion block also executes.

Declared In

VKHTTPClient.h