Skip to content

Instantly share code, notes, and snippets.

@matzew
Created August 20, 2012 17:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matzew/3405912 to your computer and use it in GitHub Desktop.
Save matzew/3405912 to your computer and use it in GitHub Desktop.
AeroGear-iOS: first API draft

Basic functionality of the aerogear-ios pipeline structure - DRAFT Version 0.1

The pipeline object (AGPipeline):

/**
 * AGPipeline represents a 'collection' of server connections (pipes) and
 * their corresponding data models. This object provides a standard way to
 * communicate with the server no matter the data format or transport expected.
 * 
 * A pipeline must have at least one pipe.
 */
@interface AGPipeline : NSObject

/**
 * A factory methods to instantiate the AGPipeline, which 
 * contains a RESTful pipe.
 *
 * @param name the name of the first AGPipe object
 * @param url the URL of the server
 *
 * @return the AGPipeline object
 */
+(id) pipelineWithPipe:(NSString*) name url:(NSURL*)url;

/**
 * A factory methods to instantiate the AGPipeline, which 
 * contains a pipe object. The actual type is determined by the type argument.
 *
 * @param name the name of the first AGPipe object
 * @param url the URL of the server
 * @param type the type of the actual pipe/connection
 *
 * @return the AGPipeline object
 */
+(id) pipelineWithPipe:(NSString*) name url:(NSURL*)url type:(NSString*)type;

/**
 * Adds a new RESTful pipe to the AGPipeline object
 *
 * @param name the name of the actual pipe
 * @param url the URL of the server
 *
 * @return the new created AGPipe object
 */
-(id<AGPipe>) add:(NSString*) name url:(NSURL*)url;

/**
 * Adds a new pipe (server connection) to the AGPipeline object
 *
 * @param name the name of the actual pipe
 * @param url the URL of the server
 * @param type the type of the actual pipe/connection
 *
 * @return the new created AGPipe object
 */
-(id<AGPipe>) add:(NSString*) name url:(NSURL*)url type:(NSString*)type;

/**
 * Removes a pipe from the AGPipeline object
 *
 * @param name the name of the actual pipe
 *
 * @return the new created AGPipe object
 */
-(id<AGPipe>) remove:(NSString*) name;

/**
 * Look up for a pipe object.
 *
 * @param name the name of the actual pipe
 *
 * @return the new created AGPipe object
 */
-(id<AGPipe>) get:(NSString*) name;

@end

The pipe object, representing an actual connection to a server:

/**
 * AGPipe represents a server connection. An object of this class is responsible to
 * communicate with the server and perfoms read/write operations.
 */
@protocol AGPipe <NSObject>

/**
 * Reads all the data from the underlying server connection. The results are being returned as
 * a dictionary/map, representing the actual JSON response.
 *
 * @return a map, representing the JSON response
 */
-(NSDictionary*) read;

/**
 * Reads all the data that matches a given filter creteria from the underlying server connection.
 * The results are being returned as a dictionary/map, representing the actual JSON response.
 *
 * @param filterObject TODO some filter object..........
 * @return a map, representing the JSON response
 */
-(NSDictionary*) readWithFilter:(id)filterObject;

/**
 * Saves (or updates) a give 'JSON' map on the server;
 *
 * @param object a 'JSON' map, representing the data to save/update
 * @return the created or updated object
 */
-(id) save:(NSDictionary*) object;

/**
 * Removes an object from the underlying server connection. The
 * given key argument is used as the objects ID.
 *
 * @param key (string, integer,...) representing the 'id'
 * @return the removed object
 */
-(id) remove:(id) key;

@end

The AGPipe @protocol will be implemented by different 'adapters', like an AGRestAdapter. Based on the given type a matching adapter is used.

Hopefully this means, that we don't need to expose the different adapters (e.g. AGRestAdapter) inside of our Aerogear.h library header file!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment