Inherits from NSObject
Conforms to NSURLConnectionDelegate
Declared in SPiDRequest.h
SPiDRequest.m

Overview

SPiDRequest handles a request against SPiD.

Tasks

Other Methods

Public methods

Private methods

Properties

retryCount

@property (nonatomic) NSInteger retryCount

Class Methods

apiGetRequestWithPath:completionHandler:

Creates a GET SPiDRequest

+ (SPiDRequest *)apiGetRequestWithPath:(NSString *)requestPath completionHandler:(void ( ^ ) ( SPiDResponse *response ))completionHandler

Parameters

requestPath

API path for GET request e.g. /user

completionHandler

Completion handler run after request is finished

Return Value

SPiDRequest

Declared In

SPiDRequest.h

apiPostRequestWithPath:body:completionHandler:

Creates a POST SPiDRequest

+ (SPiDRequest *)apiPostRequestWithPath:(NSString *)requestPath body:(NSDictionary *)body completionHandler:(void ( ^ ) ( SPiDResponse *response ))completionHandler

Parameters

requestPath

API path for POST request e.g. /user

body

The HTTP body

completionHandler

Completion handler run after request is finished

Return Value

SPiDRequest

Declared In

SPiDRequest.h

requestWithPath:method:body:completionHandler:

Creates a SPiDRequest

+ (SPiDRequest *)requestWithPath:(NSString *)requestPath method:(NSString *)method body:(NSDictionary *)body completionHandler:(void ( ^ ) ( SPiDResponse *response ))completionHandler

Parameters

requestPath

API path for request

method

HTTP method for the request

body

HTTP body, used if method is POST

completionHandler

Completion handler run after request is finished

Return Value

SPiDRequest

Declared In

SPiDRequest.h

Instance Methods

connection:didFailWithError:

NSURLConnectionDelegate method

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error

Parameters

connection

The connection sending the message.

error

An error object containing details of why the connection failed to load the request successfully.

Discussion

Sent when a connection fails to load its request successfully.

Declared In

SPiDRequest.m

connection:didReceiveData:

‘NSURLConnectionDelegate’ method

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data

Parameters

connection

The connection sending the data.

data

The newly available data.

Discussion

Sent as a connection loads message incrementally and concatenates the message to the private instance variable ‘_receivedData’.

Declared In

SPiDRequest.m

connection:willSendRequest:redirectResponse:

‘NSURLConnectionDelegate’ method

- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response

Parameters

connection

The connection sending the message.

request

The proposed redirected request.

response

The URL response that caused the redirect

Return Value

The actual URL request to use in light of the redirection response.

Discussion

Sent when the connection determines that it must change URLs in order to continue loading a request.

Declared In

SPiDRequest.m

connectionDidFinishLoading:

NSURLConnectionDelegate method

- (void)connectionDidFinishLoading:(NSURLConnection *)connection

Parameters

connection

The connection sending the message.

Discussion

Sent when a connection has finished loading successfully.

Declared In

SPiDRequest.m

initGetRequestWithPath:completionHandler:

Initializes a GET SPiDRequest

- (id)initGetRequestWithPath:(NSString *)requestPath completionHandler:(void ( ^ ) ( SPiDResponse *response ))completionHandler

Parameters

requestPath

Path to endpoint

completionHandler

Called on request completion or error

Return Value

SPiDRequest

Declared In

SPiDRequest.m

initPostRequestWithPath:body:completionHandler:

Initializes a POST SPiDRequest

- (id)initPostRequestWithPath:(NSString *)requestPath body:(NSDictionary *)body completionHandler:(void ( ^ ) ( SPiDResponse *response ))completionHandler

Parameters

requestPath

Path to endpoint

body

The post body

completionHandler

Called on request completion or error

Return Value

SPiDRequest

Declared In

SPiDRequest.m

initRequestWithPath:method:body:completionHandler:

Initializes a SPiDRequest

- (id)initRequestWithPath:(NSString *)requestPath method:(NSString *)method body:(NSDictionary *)body completionHandler:(void ( ^ ) ( SPiDResponse *response ))completionHandler

Parameters

requestPath

Path to endpoint

method

Http request method

body

The post body

completionHandler

Called on request completion or error

Return Value

SPiDRequest

Declared In

SPiDRequest.m

startRequest

Runs the request without access token

- (void)startRequest

Declared In

SPiDRequest.h

startRequestWithAccessToken

Runs the request with the current access token

- (void)startRequestWithAccessToken

Declared In

SPiDRequest.h

startRequestWithURL:body:

Starts a SPiD request

- (void)startRequestWithURL:(NSString *)urlStr body:(NSString *)body

Parameters

urlStr

The url as a string

body

The body

Declared In

SPiDRequest.m