Skip to content

Instantly share code, notes, and snippets.

@kborchers
Created July 17, 2012 04:48
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 kborchers/3127213 to your computer and use it in GitHub Desktop.
Save kborchers/3127213 to your computer and use it in GitHub Desktop.
/* Need to add license, description, etc. */
// This will be broken into its own file to be reused
(function( window, undefined ) {
var aerogear = window.aerogear = {
};
})( this );
// AeroGear Pipeline
(function( aerogear, undefined ) {
aerogear.pipeline = function( pipe ) {
var config = pipe || {},
pipes = {};
if ( typeof config === "string" ) {
pipes[ config ] = aerogear.pipeline.adapters.rest( config );
}
return pipes;
};
aerogear.pipeline.adapters = {};
})( aerogear );
// Rest Adapter (default)
(function( aerogear, $, undefined ) {
aerogear.pipeline.adapters.rest = function( pipeName, ajaxSettings ) {
ajaxSettings = $.extend({
// use the pipeName as the default rest endpoint
url: pipeName
}, ajaxSettings );
return {
read: function( options ) {
options = options || {};
ajaxSettings = $.extend({
type: "GET"
}, options.ajax || {}, ajaxSettings );
return $.ajax( ajaxSettings );
},
save: function( data, options ) {
options = options || {};
ajaxSettings = $.extend({
type: "POST",
data: data
}, options.ajax || {}, ajaxSettings );
return $.ajax( ajaxSettings );
}
};
};
})( aerogear, jQuery );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment