Inherits from NSObject
Conforms to SRClientTransport
Declared in SRHttpBasedTransport.h

Overview

SRHttpBasedTransport is an abstract class intended to be subclassed. It publishes a programmatic interface that all subclasses must adopt and provide implementations for.

SRHttpBasedTransport is responsible for starting, sending data, processing server responses, and stopping the http based transports.

Tasks

Properties

Initializing an SRHttpBasedTransport Object

Preparing requests

Processing a response

Properties

transport

Returns an NSString object with the name of the active SRHttpBasedTransport

@property (strong, nonatomic, readonly) NSString *transport

Declared In

SRHttpBasedTransport.h

Instance Methods

getReceiveQueryString:data:

Generates a query string for request made to receive data from the server

- (NSString *)getReceiveQueryString:(SRConnection *)connection data:(NSString *)data

Parameters

connection

the SRConnection object that initialized the SRHttpBasedTransport

data

the additional data to be sent to the server

Return Value

an URL encoded NSString object of the form ?transport=&connectionId=&messageId=<messageId_or_Null>&groups=&connectionData=

Declared In

SRHttpBasedTransport.h

getSendQueryString:

Generates a query string for request made to send data from the server

- (NSString *)getSendQueryString:(SRConnection *)connection

Parameters

connection

the SRConnection object that initialized the SRHttpBasedTransport

Return Value

an URL encoded NSString object of the form ?transport=&connectionId=

Declared In

SRHttpBasedTransport.h

initWithTransport:

Initializes a new SRHttpBasedTransport.

- (id)initWithTransport:(NSString *)transport

Parameters

transport

the name of the transport

Discussion

transport name is included in the query string of all SRHttpBasedTransport some acceptible transport names include “serverSentEvents” and “longPolling”

Declared In

SRHttpBasedTransport.h

isRequestAborted:

Performs a check to see if the underlying HTTP request was cancelled

- (BOOL)isRequestAborted:(NSError *)error

Parameters

error

an error returned from the underlying HTTP request SRHttpHelper

Return Value

YES if the request was aborted, NO if not

Declared In

SRHttpBasedTransport.h

onBeforeAbort:

Subclasses of SRHttpBasedTransport should override this method if the SRHttpBasedTransport needs to perform cleanup before closing

- (void)onBeforeAbort:(SRConnection *)connection

Parameters

connection

the SRConnection object that initialized the SRHttpBasedTransport

Declared In

SRHttpBasedTransport.h

onStart:data:initializeCallback:errorCallback:

Important: this method should only be called from a subclass of SRHttpBasedTransport

- (void)onStart:(SRConnection *)connection data:(NSString *)data initializeCallback:(void ( ^ ) ( void ))initializeCallback errorCallback:(void ( ^ ) ( SRErrorByReferenceBlock ))errorCallback

Parameters

connection

the SRConnection object that initialized the SRHttpBasedTransport

data

the additional data to be sent to the server

initializeCallback

a block to call when the SRHttpBasedTransport has been initialized successfully

errorCallback

a block to call when the SRHttpBasedTransport failed to initialize successfully

Discussion

Important: this method should only be called from a subclass of SRHttpBasedTransport

Declared In

SRHttpBasedTransport.h

prepareRequest:forConnection:

Prepares http requests to be sent to the server

- (void)prepareRequest:(id)request forConnection:(SRConnection *)connection

Parameters

request

will either be an NSMutableURLRequest or an AFHTTPRequestOperation

connection

the SRConnection object that initialized the SRHttpBasedTransport

Discussion

if the request is an NSMutableURLRequest, [SRConneciton prepareRequest] is called if the request is an AFHTTPRequestOperation the request object is stored in SRConnection.items as a value for the key kHttpRequest theAFHTTPRequestOperationis stored so it can be easily retreived when theSRHttpBasedTransport` is stopped and the underlying request cancelled

Declared In

SRHttpBasedTransport.h

processResponse:response:timedOut:disconnected:

Processes a successful server response by updating relevant connection properties and dispatching calls to [SRConnection didReceiveData]

- (void)processResponse:(SRConnection *)connection response:(NSString *)response timedOut:(BOOL *)timedOut disconnected:(BOOL *)disconnected

Parameters

connection

the SRConnection object that initialized the SRHttpBasedTransport

response

an NSString representation of the server’s JSON response object

timedOut

a BOOL respresenting if the connection received a server side timeout

disconnected

a BOOL respresenting if the connection received a disconnect from the server

Declared In

SRHttpBasedTransport.h