<TRCConnection> Protocol Reference

TRCConnection provides abstraction over network connection. More...

Inheritance diagram for <TRCConnection>:

Instance Methods

(NSMutableURLRequest *) - requestWithOptions:error:
 Creates NSURLRequest using information from TRCRequest. More...
 
(id< TRCProgressHandler >) - sendRequest:withOptions:completion:
 Sends NSURLRequest via network, then handles response using options.responseBodySerialization or writes into options.outputStream. More...
 
(TRCConnectionReachabilityState- reachabilityState
 Returns current reachability state if implemented. More...
 
(void) - setReachabilityDelegate:
 Sets TRCConnectionReachabilityDelegate, which used to get notified about reachabilityState changes. More...
 

Detailed Description

TRCConnection provides abstraction over network connection.

TyphoonRestClient instance uses connection to two main tasks:

  • request creation, using requestWithOptions:error: method
  • request sending, using sendRequest:withOptions:completion: method

You can use default implementation of TRCConnection protocol, which uses AFNetworking library (see TRCConnectionAFNetworking). It's also useful to inject your own connection between TyphoonRestClient and real TRCConnection, to listen all network events, and modify request if needed. For example TRCConnectionLogger just prints any network activity into log.

See also
TRCConnectionLogger.
TRCConnectionAFNetworking
TRCConnectionStub

Method Documentation

◆ requestWithOptions:error:()

- (NSMutableURLRequest *) requestWithOptions: (id< TRCConnectionRequestCreationOptions >)  options
error: (NSError **)  requestComposingError 

Creates NSURLRequest using information from TRCRequest.

TyphoonRestClient handles TRCRequest and collect all necessary info into special, easy-to-use object of <TRCConnectionRequestCreationOptions> protocol.

Notice, that return value is mutable NSMutableURLRequest. That useful for connections-in-the-middle to modify request made by real network connection (usually used to add additional headers)

Parameters
optionscontains all information required to compose NSURLRequest
requestComposingErrorpointer to NSError object. Write your error object into that pointer, if you can't create NSURLRequest and return nil

◆ sendRequest:withOptions:completion:()

- (id<TRCProgressHandler>) sendRequest: (NSURLRequest *)  request
withOptions: (id< TRCConnectionRequestSendingOptions >)  options
completion: (TRCConnectionCompletion completion 

Sends NSURLRequest via network, then handles response using options.responseBodySerialization or writes into options.outputStream.

TyphoonRestClient makes TRCConnectionRequestSendingOptions using TRCRequest. These send options contains all necessary information to send request and handle response.

Note that this method should return object that confirms <TRCProgressHandler> protocol, so caller can track upload and download progress. (Implemented in TRCConnectionAFNetworking)

Parameters
requestrequest to send via network
optionscontains information required to send request and handle response
completionblock that contains result, response information and error arguments. Note that completion block is not retained, so it's not necessary to put weak varies inside.
Returns
returns object that used by caller to track upload/download progress

◆ reachabilityState()

- (TRCConnectionReachabilityState) reachabilityState
optional

Returns current reachability state if implemented.

If not implemented, treats as TRCConnectionReachabilityStateUnknown

◆ setReachabilityDelegate:()

- (void) setReachabilityDelegate: (id< TRCConnectionReachabilityDelegate >)  reachabilityDelegate
optional

Sets TRCConnectionReachabilityDelegate, which used to get notified about reachabilityState changes.

Used by TyphoonRestClient, which post TyphoonRestClientReachabilityDidChangeNotification after each changing