TyphoonRestClient Class Reference

TyphoonRestClient is a library for integration against contract-first web service. More...

Inheritance diagram for TyphoonRestClient:

Properties

BOOL reachable
 Returns YES if connection supports reachability and network is reachable - otherwise NO More...
 
TRCConnectionReachabilityState reachabilityState
 Returns current reachabilityState. More...
 
id< TRCErrorHandlererrorHandler
 Set your TRCErrorHandler here. Default nil. More...
 
id< TRCConnectionconnection
 Set your TRCConnection here. Default nil. You must set this property. More...
 
TRCSerialization defaultResponseSerialization
 Default: TRCSerializationJson. More...
 
BOOL shouldSuppressWarnings
 If enabled, warning messages would be printed using NSLog. Disable if you are nervous, enable if you careful. Default: NO. More...
 
TRCOptions options
 Set validation and processing options here. Default: TRCOptionsNone More...
 
TRCSerializerHttpQueryOptions querySerializationOptions
 This options allows you to specify specific query serialization parameters It used while generating request's URL query and also by TRCSerializerHttpQuery to generate the body. More...
 
NSOperationQueue * callbackQueue
 This queue used to call completion blocks. Main Queue used by default. More...
 
NSOperationQueue * workQueue
 This queue used to do all serialization, deserialization, validations and parsing. Main Queue used by default. More...
 

Instance Methods

(id< TRCProgressHandler >) - sendRequest:completion:
 Sends your TRCRequest using connection and returns result in completion block. More...
 
(void) - registerValueTransformer:forTag:
 Registers TRCValueTransformer for specific tag string. More...
 
(void) - registerObjectMapper:forTag:
 Registers TRCObjectMapper for specific tag string. More...
 
(void) - registerPreProcessor:
 Adds your TRCPreProcessor into registry. More...
 
(void) - registerPostProcessor:
 Adds your TRCPostProcessor into registry. More...
 
(void) - registerDefaultRequestSerialization:forBodyObjectWithClass:
 Registers TRCSerialization as default for body object class. More...
 
(id) - convertThenValidateRequestObject:usingSchemaTag:options:error:
 
(id) - validateThenConvertResponseObject:usingSchemaTag:options:error:
 
(void) - registerRequestSerializer:forName:
 Registers TRCRequestSerializer for special string identifier TRCSerialization. More...
 
(void) - registerResponseSerializer:forName:
 Registers TRCResponseSerializer for special string identifier TRCSerialization. More...
 
(void) - registerSchemeFormat:forFileExtension:
 Registers scheme file format in TyphoonRestClient. More...
 
(void) - registerValidationErrorPrinter:forFormatWithFileExtension:
 Registers validation error printer for schema file extension. More...
 
(void) - registerTRCValueTransformerType:withValueClass:
 Registers TRCValueTransformerType with objective-c class. More...
 

Detailed Description

TyphoonRestClient is a library for integration against contract-first web service.

It provides facilities for customisable serialisation / marshalling, validation and stubbing requests.

TRC helps to quickly achieve end-to-end proof of concept, at the same time as providing a robust platform for deploying into demanding production environments.

Property Documentation

◆ reachable

- (BOOL) reachable
readnonatomicassign

Returns YES if connection supports reachability and network is reachable - otherwise NO

◆ reachabilityState

- (TRCConnectionReachabilityState) reachabilityState
readnonatomicassign

Returns current reachabilityState.

See also
TRCConnectionReachabilityState

◆ errorHandler

- (id<TRCErrorHandler>) errorHandler
readwritenonatomicstrong

Set your TRCErrorHandler here. Default nil.

◆ connection

- (id<TRCConnection>) connection
readwritenonatomicstrong

Set your TRCConnection here. Default nil. You must set this property.

◆ defaultResponseSerialization

- (TRCSerialization) defaultResponseSerialization
readwritenonatomicassign

Default: TRCSerializationJson.

◆ shouldSuppressWarnings

- (BOOL) shouldSuppressWarnings
readwritenonatomicassign

If enabled, warning messages would be printed using NSLog. Disable if you are nervous, enable if you careful. Default: NO.

◆ options

- (TRCOptions) options
readwritenonatomicassign

Set validation and processing options here. Default: TRCOptionsNone

◆ querySerializationOptions

- (TRCSerializerHttpQueryOptions) querySerializationOptions
readwritenonatomicassign

This options allows you to specify specific query serialization parameters It used while generating request's URL query and also by TRCSerializerHttpQuery to generate the body.

◆ callbackQueue

- (NSOperationQueue*) callbackQueue
readwritenonatomicstrong

This queue used to call completion blocks. Main Queue used by default.

◆ workQueue

- (NSOperationQueue*) workQueue
readwritenonatomicstrong

This queue used to do all serialization, deserialization, validations and parsing. Main Queue used by default.

Method Documentation

◆ sendRequest:completion:()

- (id<TRCProgressHandler>) sendRequest: (id< TRCRequest >)  request
completion: (void(^)(id result, NSError *error))  completion 

Sends your TRCRequest using connection and returns result in completion block.

Make sure that connection property set before calling this method.

See also
TRCRequest TRCConnection

◆ registerValueTransformer:forTag:()

- (void) registerValueTransformer: (id< TRCValueTransformer >)  valueTransformer
forTag: (NSString *)  tag 

Registers TRCValueTransformer for specific tag string.

Use this tag in your schemes to mark values which must be processed by this valueTransformer

See also
TRCValueTransformer

◆ registerObjectMapper:forTag:()

- (void) registerObjectMapper: (id< TRCObjectMapper >)  objectMapper
forTag: (NSString *)  tag 

Registers TRCObjectMapper for specific tag string.

Use this tag in schemas to mark which part of object should be processed by this objectMapper

For example, you have next JSON object:

{
"people": {
"first_name": "string",
"last_name": "string"
}
}

and your mappers process objects:

{
"first_name": "string",
"last_name": "string"
}

then you can register your mapper, for example, with tag = <people>. After that registration you can modify your scheme into that:

{
"people": "<people>"
}
See also
TRCObjectMapper

◆ registerPreProcessor:()

- (void) registerPreProcessor: (id< TRCPreProcessor >)  preProcessor

Adds your TRCPreProcessor into registry.

See TRCPreProcessor for more details

See also
TRCPostProcessor

◆ registerPostProcessor:()

- (void) registerPostProcessor: (id< TRCPostProcessor >)  postProcessor

Adds your TRCPostProcessor into registry.

See TRCPostProcessor for more details

See also
TRCPostProcessor

◆ registerDefaultRequestSerialization:forBodyObjectWithClass:()

- (void) registerDefaultRequestSerialization: (TRCSerialization requestSerialization
forBodyObjectWithClass: (Class)  clazz 

Registers TRCSerialization as default for body object class.

That's useful to avoid typing TRCRequest.requestBodySerialization in each TRCRequest in most cases.

Default registration is:

  • NSArray registered with TRCSerializationJson
  • NSDictionary registered with TRCSerializationJson
  • NSData registered with TRCSerializationData
  • NSInputStream registered with TRCSerializationRequestInputStream
  • NSString registered with TRCSerializationString

So if you return NSInputStream as bodyObject.TRCRequest and avoid implementation of TRCRequest.requestBodySerialization then TRCSerializationRequestInputStream serialization would be used automatically

Feel free to change that registration, by re-registering for same classes, or registering nils

Note
class matching done using NSObject.isKindOfClass method. If you register different TRCSerialization-s for classes that inherit each over, then result is unexpected. For example if you register TRCSerializationJson for NSArray and TRCSerializationPlist for NSMutableArray it's undefined which serialization would be taken for NSMutableArray.
Parameters
requestSerializationTRCSerialization string identifier to register or nil to undo registration
clazzclass used for matching when search for default serialization.

◆ convertThenValidateRequestObject:usingSchemaTag:options:error:()

- (id) convertThenValidateRequestObject: (id)  object
usingSchemaTag: (NSString *)  tag
options: (TRCTransformationOptions)  options
error: (NSError **)  pError 

Provided by category TyphoonRestClient(Extensions).

◆ validateThenConvertResponseObject:usingSchemaTag:options:error:()

- (id) validateThenConvertResponseObject: (id)  object
usingSchemaTag: (NSString *)  tag
options: (TRCTransformationOptions)  options
error: (NSError **)  pError 

Provided by category TyphoonRestClient(Extensions).

◆ registerRequestSerializer:forName:()

- (void) registerRequestSerializer: (id< TRCRequestSerializer >)  serializer
forName: (TRCSerialization serializerName 

Registers TRCRequestSerializer for special string identifier TRCSerialization.

Use TRCSerialization identifier later in your TRCRequest-s

Provided by category TyphoonRestClient(Infrastructure).

◆ registerResponseSerializer:forName:()

- (void) registerResponseSerializer: (id< TRCResponseSerializer >)  serializer
forName: (TRCSerialization serializerName 

Registers TRCResponseSerializer for special string identifier TRCSerialization.

Use TRCSerialization identifier later in your TRCRequest-s

Provided by category TyphoonRestClient(Infrastructure).

◆ registerSchemeFormat:forFileExtension:()

- (void) registerSchemeFormat: (id< TRCSchemaFormat >)  schemeFormat
forFileExtension: (NSString *)  extension 

Registers scheme file format in TyphoonRestClient.

You are free to invent your own schema format to process and validate your own serialization formats.

By default, only one format available for schema. It's JSON format (with file extension 'json')

All scheme files must have path extensions of registered scheme format. For example all JSON schemes must ends with .json extension

See also
TRCSchemaFormat

Provided by category TyphoonRestClient(Infrastructure).

◆ registerValidationErrorPrinter:forFormatWithFileExtension:()

- (void) registerValidationErrorPrinter: (id< TRCValidationErrorPrinter >)  printer
forFormatWithFileExtension: (NSString *)  extension 

Registers validation error printer for schema file extension.

Because schema files with different extensions, looks different, then full description of validation error should also looks different per extension.

See also
TRCValidationErrorPrinter

Provided by category TyphoonRestClient(Infrastructure).

◆ registerTRCValueTransformerType:withValueClass:()

- (void) registerTRCValueTransformerType: (TRCValueTransformerType *)  type
withValueClass: (Class)  clazz 

Registers TRCValueTransformerType with objective-c class.

Then TRCValueTransformerType can be used as identifier in TRCValueTransformer to specify input types, and type validation would be done based on classes registered with it.

To use TRCValueTransformerType as identifier, it useful to have them as global variable in serializer header, and register pointer to that variables with classes. Calling that method will set correct value to these variables.

Note that value of type variable would be set as BitMask, so you can later combine all acceptable types as one value like that: type1 | type2 | type3

See also
TRCValueTransformerType

Provided by category TyphoonRestClient(Infrastructure).