src/qwest.js
function(q) {
            // Prepare
            var promises = [],
                loading = 0,
                values = [];
            // Create a new promise to handle all requests
            return pinkyswear(function(pinky) {
                // Basic request method
                var method_index = -1,
                    createMethod = function(method) {
                        return function(url, data, options, before) {
                            var index = ++method_index;
                            ++loading;
                            promises.push(qwest(method, pinky.base + url, data, options, before).then(function(xhr, response) {
                                values[index] = arguments;
                                if(!--loading) {
                                    pinky(true, values.length == 1 ? values[0] : [values]);
                                }
                            }, function() {
                                pinky(false, arguments);
                            }));
                            return pinky;
                        };
                    };
                // Define external API
                pinky.get = createMethod('GET');
                pinky.post = createMethod('POST');
                pinky.put = createMethod('PUT');
                pinky['delete'] = createMethod('DELETE');
                pinky['catch'] = function(f) {
                    return pinky.then(null, f);
                };
                pinky.complete = function(f) {
                    var func = function() {
                        f(); // otherwise arguments will be passed to the callback
                    };
                    return pinky.then(func, func);
                };
                pinky.map = function(type, url, data, options, before) {
                    return createMethod(type.toUpperCase()).call(this, url, data, options, before);
                };
                // Populate methods from external object
                for(var prop in q) {
                    if(!(prop in pinky)) {
                        pinky[prop] = q[prop];
                    }
                }
                // Set last methods
                pinky.send = function() {
                    for(var i=0, j=promises.length; i<j; ++i) {
                        promises[i].send();
                    }
                    return pinky;
                };
                pinky.abort = function() {
                    for(var i=0, j=promises.length; i<j; ++i) {
                        promises[i].abort();
                    }
                    return pinky;
                };
                return pinky;
            });
        }
function(q) {
            // Prepare
            var promises = [],
                loading = 0,
                values = [];
            // Create a new promise to handle all requests
            return pinkyswear(function(pinky) {
                // Basic request method
                var method_index = -1,
                    createMethod = function(method) {
                        return function(url, data, options, before) {
                            var index = ++method_index;
                            ++loading;
                            promises.push(qwest(method, pinky.base + url, data, options, before).then(function(xhr, response) {
                                values[index] = arguments;
                                if(!--loading) {
                                    pinky(true, values.length == 1 ? values[0] : [values]);
                                }
                            }, function() {
                                pinky(false, arguments);
                            }));
                            return pinky;
                        };
                    };
                // Define external API
                pinky.get = createMethod('GET');
                pinky.post = createMethod('POST');
                pinky.put = createMethod('PUT');
                pinky['delete'] = createMethod('DELETE');
                pinky['catch'] = function(f) {
                    return pinky.then(null, f);
                };
                pinky.complete = function(f) {
                    var func = function() {
                        f(); // otherwise arguments will be passed to the callback
                    };
                    return pinky.then(func, func);
                };
                pinky.map = function(type, url, data, options, before) {
                    return createMethod(type.toUpperCase()).call(this, url, data, options, before);
                };
                // Populate methods from external object
                for(var prop in q) {
                    if(!(prop in pinky)) {
                        pinky[prop] = q[prop];
                    }
                }
                // Set last methods
                pinky.send = function() {
                    for(var i=0, j=promises.length; i<j; ++i) {
                        promises[i].send();
                    }
                    return pinky;
                };
                pinky.abort = function() {
                    for(var i=0, j=promises.length; i<j; ++i) {
                        promises[i].abort();
                    }
                    return pinky;
                };
                return pinky;
            });
        }
function ( q ) { // Prepare var promises = [ ] , loading = 0 , values = [ ] ; // Create a new promise to handle all requests return pinkyswear ( function ( pinky ) { // Basic request method var method_index = - 1 , createMethod = function ( method ) { return function ( url , data , options , before ) { var index = ++ method_index ; ++ loading ; promises . push ( qwest ( method , pinky . base + url , data , options , before ) . then ( function ( xhr , response ) { values [ index ] = arguments ; if ( ! -- loading ) { pinky ( true , values . length == 1 ? values [ 0 ] : [ values ] ) ; } } , function ( ) { pinky ( false , arguments ) ; } ) ) ; return pinky ; } ; } ; // Define external API pinky . get = createMethod ( 'GET' ) ; pinky . post = createMethod ( 'POST' ) ; pinky . put = createMethod ( 'PUT' ) ; pinky [ 'delete' ] = createMethod ( 'DELETE' ) ; pinky [ 'catch' ] = function ( f ) { return pinky . then ( null , f ) ; } ; pinky . complete = function ( f ) { var func = function ( ) { f ( ) ; // otherwise arguments will be passed to the callback } ; return pinky . then ( func , func ) ; } ; pinky . map = function ( type , url , data , options , before ) { return createMethod ( type . toUpperCase ( ) ) . call ( this , url , data , options , before ) ; } ; // Populate methods from external object for ( var prop in q ) { if ( ! ( prop in pinky ) ) { pinky [ prop ] = q [ prop ] ; } } // Set last methods pinky . send = function ( ) { for ( var i = 0 , j = promises . length ; i < j ; ++ i ) { promises [ i ] . send ( ) ; } return pinky ; } ; pinky . abort = function ( ) { for ( var i = 0 , j = promises . length ; i < j ; ++ i ) { promises [ i ] . abort ( ) ; } return pinky ; } ; return pinky ; } ) ; }
Define external qwest object
Define external qwest object