Inherits from NSObject
Declared in MMServer.h
MMServer.m

Overview

MMServer provides the primary interface for making a request to a server. MMServer is designed to be subclassed. One of the great things about MMServer is that it removes the depency of a project on any particular networking framework. You can build all of your networking code around MMRecord and MMServer and freely interchange request frameworks under the hood as desired. The intent here is to also allow the ability to use a local server or a live server interchangably without needing to change any controller-level code.

Subclassing Notes

This class is designed and required to be subclassed. Subclasses must implement the cancelRequests and startRequestWithURN methods. The intent is that you will subclass this class for every server your app wishes to interact with, either local or live. If you wish to support pagination you should also implement pageManagerClass. The session timeout methods should not need to be implemented by subclasses.

Methods to Override

To allow your server to support pagination you should override pageManagerClass and return the class of your MMServerPageManager subclass.

Tasks

Starting and Stopping Server Requests

Handling API Request Response Pagination

  • + pageManagerClass

    Returns a subclass of MMServerPageManager configured to support your server’s implementation of pagination. You should override this method if you want your server to support pagination.

Handling a Session Timeout Request Failure

Support for URL-based Record Caching

  • + requestWithURN:data:

    Returns an NSURLRequest properly configured as it would be for a call to startRequestWithURN:. This method is required for an installation of MMRecord/MMServer that wishes to support caching.

Class Methods

cancelRequestsWithDomain:

Cancels any requests in progress. This method must be implemented by the subclass of MMServer.

+ (void)cancelRequestsWithDomain:(id)domain

Parameters

domain

A domain value used to know which requests to cancel. It is left to the subclass to decide how to interpret this value.

Discussion

Cancels any requests in progress. This method must be implemented by the subclass of MMServer.

Declared In

MMServer.h

pageManagerClass

Returns a subclass of MMServerPageManager configured to support your server’s implementation of pagination. You should override this method if you want your server to support pagination.

+ (Class)pageManagerClass

Return Value

The page manager class.

Discussion

Returns a subclass of MMServerPageManager configured to support your server’s implementation of pagination. You should override this method if you want your server to support pagination.

Declared In

MMServer.h

registerSessionTimeoutBlock:

Registers the session timeout block which will be called in the event of a session timeout.

+ (void)registerSessionTimeoutBlock:(MMServerSessionTimeoutBlock)block

Parameters

block

A block of type MMServerSessionTimeoutBlock.

Discussion

Registers the session timeout block which will be called in the event of a session timeout.

Declared In

MMServer.h

requestWithURN:data:

Returns an NSURLRequest properly configured as it would be for a call to startRequestWithURN:. This method is required for an installation of MMRecord/MMServer that wishes to support caching.

+ (NSURLRequest *)requestWithURN:(NSString *)URN data:(NSDictionary *)data

Parameters

URN

The base URN for the request endpoint.

data

A dictionary containing request parameters.

Return Value

A configured NSURLRequest.

Discussion

Returns an NSURLRequest properly configured as it would be for a call to startRequestWithURN:. This method is required for an installation of MMRecord/MMServer that wishes to support caching.

Declared In

MMServer.h

sessionTimeoutBlock

Accessor for the session timeout block.

+ (MMServerSessionTimeoutBlock)sessionTimeoutBlock

Return Value

The registered session timeout block.

Discussion

Accessor for the session timeout block.

Declared In

MMServer.h

startRequestWithURN:data:paged:domain:batched:dispatchGroup:responseBlock:failureBlock:

Starts a request. This method must be implemented by the subclass of MMServer.

+ (void)startRequestWithURN:(NSString *)URN data:(NSDictionary *)data paged:(BOOL)paged domain:(id)domain batched:(BOOL)batched dispatchGroup:(dispatch_group_t)dispatchGroup responseBlock:(void ( ^ ) ( id responseObject ))responseBlock failureBlock:(void ( ^ ) ( NSError *error ))failureBlock

Parameters

URN

The base URN for the request endpoint.

data

A dictionary containing request parameters.

paged

A boolean value indicating whether or not the request should be paged. The paged request should request the first page by default. You should only set a page size parameter if this value is YES.

domain

A domain value used for request cancellation. It is left to the subclass to decide how to use this value.

batched

A boolean value indicating whether or not a request is intended to be batched. Depending on your networking implementation this may or may not matter to you. The default implementation of MMRecord’s batching support will use dispatch groups to fire a completion block after all of the responseBlocks (which by default use this group) finish. This property may be useful to you in some cases, and if so, please contact the maintainers to tell them what this use-case is :) It is easily possible that this parameter will be deprecated in the future, so plan accordingly.

dispatchGroup

A dispatch_group variable to be used for grouping batch requests. All dispatch_async blocks in MMRecord are issued with a dispatch_group. This property is intended as a safe-guard should you need to dispatch any other blocks asynchronously. In order to gaurantee that batching will still work, you should use this dispatch group if you ever find yourself in that situation. Using this is not required in order for batching to work.

responseBlock

A block object to be executed when the request finishes successfully. The block is called with the response object as a parameter.

failureBlock

A block object to be executed when the request finishes unsuccessfully. The block contains an error object that describes a request failure or a record parsing failure.

Discussion

Starts a request. This method must be implemented by the subclass of MMServer.

Declared In

MMServer.h