lib/api.js
function(method, callback, options) {
        options = this._getOptions(callback, options);

        if (this.config.debugMode) {
            this.config.logClass(method, options);
        }

        /**
         * If data has parse method, call it before passing data
         */
        if (options.data && options.data instanceof this.models.EntityBase) {
            options.data = this.buildRequestData(options.data);
        } else if (options.data && options.data.toJSON) {
            options.data = options.data.toJSON();
        }
        var self = this;

        /**
         * If there's no OAuthKey, request one
         */
        if (!this.requestOptions.headers.Authorization || this.isExpired()) {
            return new Promise(function(resolve, reject){
                self.authorize()
                    .then(function(){
                        self.method.call(self, method, function(data, response){
                            // Check if we have to wrap data into a model
                            if (_.isFunction(callback)) {
                                callback(data, response);
                            }
                        }, options)
                            .then(resolve)
                            .catch(reject)
                    })
                    .catch(reject);
            });
        }

        /**
         * Extend default request options with custom ones, if present
         */
        var requestOptions = _.extend({}, this.requestOptions, options);

        /**
         * If we have custom headers, we have to prevent them to override Authentication header
         */
        if (options && options.headers) {
            _.extend(requestOptions.headers, this.requestOptions.headers, options.headers);
        }

        /**
         * Append the path placeholders in order to build the proper url for the request
         */
        if (options && options.path) {
            _.extend(requestOptions.path, this.requestOptions.path, options.path);
        }

        return this._requestApi(requestOptions, method, callback);
    }
function(method, callback, options) {
        options = this._getOptions(callback, options);

        if (this.config.debugMode) {
            this.config.logClass(method, options);
        }

        /**
         * If data has parse method, call it before passing data
         */
        if (options.data && options.data instanceof this.models.EntityBase) {
            options.data = this.buildRequestData(options.data);
        } else if (options.data && options.data.toJSON) {
            options.data = options.data.toJSON();
        }
        var self = this;

        /**
         * If there's no OAuthKey, request one
         */
        if (!this.requestOptions.headers.Authorization || this.isExpired()) {
            return new Promise(function(resolve, reject){
                self.authorize()
                    .then(function(){
                        self.method.call(self, method, function(data, response){
                            // Check if we have to wrap data into a model
                            if (_.isFunction(callback)) {
                                callback(data, response);
                            }
                        }, options)
                            .then(resolve)
                            .catch(reject)
                    })
                    .catch(reject);
            });
        }

        /**
         * Extend default request options with custom ones, if present
         */
        var requestOptions = _.extend({}, this.requestOptions, options);

        /**
         * If we have custom headers, we have to prevent them to override Authentication header
         */
        if (options && options.headers) {
            _.extend(requestOptions.headers, this.requestOptions.headers, options.headers);
        }

        /**
         * Append the path placeholders in order to build the proper url for the request
         */
        if (options && options.path) {
            _.extend(requestOptions.path, this.requestOptions.path, options.path);
        }

        return this._requestApi(requestOptions, method, callback);
    }
function ( method , callback , options ) { options = this . _getOptions ( callback , options ) ; if ( this . config . debugMode ) { this . config . logClass ( method , options ) ; } /**
         * If data has parse method, call it before passing data
         */ if ( options . data && options . data instanceof this . models . EntityBase ) { options . data = this . buildRequestData ( options . data ) ; } else if ( options . data && options . data . toJSON ) { options . data = options . data . toJSON ( ) ; } var self = this ; /**
         * If there's no OAuthKey, request one
         */ if ( ! this . requestOptions . headers . Authorization || this . isExpired ( ) ) { return new Promise ( function ( resolve , reject ) { self . authorize ( ) . then ( function ( ) { self . method . call ( self , method , function ( data , response ) { // Check if we have to wrap data into a model if ( _ . isFunction ( callback ) ) { callback ( data , response ) ; } } , options ) . then ( resolve ) . catch ( reject ) } ) . catch ( reject ) ; } ) ; } /**
         * Extend default request options with custom ones, if present
         */ var requestOptions = _ . extend ( { } , this . requestOptions , options ) ; /**
         * If we have custom headers, we have to prevent them to override Authentication header
         */ if ( options && options . headers ) { _ . extend ( requestOptions . headers , this . requestOptions . headers , options . headers ) ; } /**
         * Append the path placeholders in order to build the proper url for the request
         */ if ( options && options . path ) { _ . extend ( requestOptions . path , this . requestOptions . path , options . path ) ; } return this . _requestApi ( requestOptions , method , callback ) ; }
Main API resource request method
@param {string}      method      Mangopay API method to be called
@param {function}    callback    Callback function
@param {object}      options     Hash of configuration to be passed to request
@returns {object} request promise
Main API resource request method