functions/node_modules/googleapis/build/src/lib/apirequest.js
/**
 * Create and send request to Google API
 * @param  {object}   parameters Parameters used to form request
 * @param  {Function} callback   Callback when request finished or error found
 * @return {Request}             Returns Request object or null
 */
Create and send request to Google API
@param  {object}   parameters Parameters used to form request
@param  {Function} callback   Callback when request finished or error found
@return {Request}             Returns Request object or null
Create and send request to Google API @param { object } parameters Parameters used to form request @param { Function } callback Callback when request finished or error found @return { Request } Returns Request object or null
function createAPIRequest(parameters, callback) {
    var missingParams;
    var params = parameters.params;
    var options = Object.assign({}, parameters.options);
    if (typeof params === 'function') {
        callback = params;
        params = {};
    }
    params = Object.assign({}, 
    parameters.context.google._options.params, 
    parameters.context._options.params, 
    params 
    );
    var media = params.media || {};
    var resource = params.resource;
    var authClient = params.auth || parameters.context._options.auth ||
        parameters.context.google._options.auth;
    var defaultMime = typeof media.body === 'string' ?
        'text/plain' :
        'application/octet-stream';
    delete params.media;
    delete params.resource;
    delete params.auth;
    var headers = params.headers || {};
    delete params.headers;
    Object.keys(params).forEach(function (key) {
        if (key.slice(-1) === '_') {
            var newKey = key.slice(0, -1);
            params[newKey] = params[key];
            delete params[key];
        }
    });
    callback = createCallback(callback);
    missingParams = getMissingParams(params, parameters.requiredParams);
    if (missingParams) {
        callback(new Error('Missing required parameters: ' + missingParams.join(', ')));
        return null;
    }
    if (options.url) {
        options.url = parseString(options.url, params);
    }
    if (parameters.mediaUrl) {
        parameters.mediaUrl = parseString(parameters.mediaUrl, params);
    }
    options.paramsSerializer = function (params) {
        return qs.stringify(params, { arrayFormat: 'repeat' });
    };
    parameters.pathParams.forEach(function (param) {
        delete params[param];
    });
    if (typeof authClient === 'string') {
        params.key = params.key || authClient;
        authClient = null;
    }
    if (parameters.mediaUrl && media.body) {
        options.url = parameters.mediaUrl;
        if (resource) {
            params.uploadType = 'multipart';
            var multipart = [
                { 'Content-Type': 'application/json', body: JSON.stringify(resource) }, {
                    'Content-Type': media.mimeType || (resource && resource.mimeType) || defaultMime,
                    body: media.body 
                }
            ];
            var boundary = uuid.v4();
            var finale_1 = "--" + boundary + "--";
            var rStream_1 = new stream.PassThrough();
            var isStream = isReadableStream(multipart[1].body);
            headers['Content-Type'] = "multipart/related; boundary=" + boundary;
            for (var _i = 0, multipart_1 = multipart; _i < multipart_1.length; _i++) {
                var part = multipart_1[_i];
                var preamble = "--" + boundary + "\r\nContent-Type: " + part['Content-Type'] + "\r\n\r\n";
                rStream_1.push(preamble);
                if (typeof part.body === 'string') {
                    rStream_1.push(part.body);
                    rStream_1.push('\r\n');
                }
                else {
                    part.body.pipe(rStream_1, { end: false });
                    part.body.on('end', function () {
                        rStream_1.push('\r\n');
                        rStream_1.push(finale_1);
                        rStream_1.push(null);
                    });
                }
            }
            if (!isStream) {
                rStream_1.push(finale_1);
                rStream_1.push(null);
            }
            options.data = rStream_1;
        }
        else {
            params.uploadType = 'media';
            Object.assign(headers, { 'Content-Type': media.mimeType || defaultMime });
            options.data = media.body;
        }
    }
    else {
        options.data = resource || undefined;
    }
    options.headers = headers;
    options.params = params;
    options = Object.assign({}, parameters.context.google._options, parameters.context._options, options);
    delete options.auth; 
    if (authClient) {
        authClient.request(options, callback);
    }
    else {
        (new google_auth_library_1.DefaultTransporter()).request(options, callback);
    }
}
function createAPIRequest ( parameters , callback ) { var missingParams ; var params = parameters . params ; var options = Object . assign ( { } , parameters . options ) ; if ( typeof params === 'function' ) { callback = params ; params = { } ; } params = Object . assign ( { } , parameters . context . google . _options . params , parameters . context . _options . params , params ) ; var media = params . media || { } ; var resource = params . resource ; var authClient = params . auth || parameters . context . _options . auth || parameters . context . google . _options . auth ; var defaultMime = typeof media . body === 'string' ? 'text/plain' : 'application/octet-stream' ; delete params . media ; delete params . resource ; delete params . auth ; var headers = params . headers || { } ; delete params . headers ; Object . keys ( params ) . forEach ( function ( key ) { if ( key . slice ( - 1 ) === '_' ) { var newKey = key . slice ( 0 , - 1 ) ; params [ newKey ] = params [ key ] ; delete params [ key ] ; } } ) ; callback = createCallback ( callback ) ; missingParams = getMissingParams ( params , parameters . requiredParams ) ; if ( missingParams ) { callback ( new Error ( 'Missing required parameters: ' + missingParams . join ( ', ' ) ) ) ; return null ; } if ( options . url ) { options . url = parseString ( options . url , params ) ; } if ( parameters . mediaUrl ) { parameters . mediaUrl = parseString ( parameters . mediaUrl , params ) ; } options . paramsSerializer = function ( params ) { return qs . stringify ( params , { arrayFormat : 'repeat' } ) ; } ; parameters . pathParams . forEach ( function ( param ) { delete params [ param ] ; } ) ; if ( typeof authClient === 'string' ) { params . key = params . key || authClient ; authClient = null ; } if ( parameters . mediaUrl && media . body ) { options . url = parameters . mediaUrl ; if ( resource ) { params . uploadType = 'multipart' ; var multipart = [ { 'Content-Type' : 'application/json' , body : JSON . stringify ( resource ) } , { 'Content-Type' : media . mimeType || ( resource && resource . mimeType ) || defaultMime , body : media . body } ] ; var boundary = uuid . v4 ( ) ; var finale_1 = "--" + boundary + "--" ; var rStream_1 = new stream . PassThrough ( ) ; var isStream = isReadableStream ( multipart [ 1 ] . body ) ; headers [ 'Content-Type' ] = "multipart/related; boundary=" + boundary ; for ( var _i = 0 , multipart_1 = multipart ; _i < multipart_1 . length ; _i ++ ) { var part = multipart_1 [ _i ] ; var preamble = "--" + boundary + "\r\nContent-Type: " + part [ 'Content-Type' ] + "\r\n\r\n" ; rStream_1 . push ( preamble ) ; if ( typeof part . body === 'string' ) { rStream_1 . push ( part . body ) ; rStream_1 . push ( '\r\n' ) ; } else { part . body . pipe ( rStream_1 , { end : false } ) ; part . body . on ( 'end' , function ( ) { rStream_1 . push ( '\r\n' ) ; rStream_1 . push ( finale_1 ) ; rStream_1 . push ( null ) ; } ) ; } } if ( ! isStream ) { rStream_1 . push ( finale_1 ) ; rStream_1 . push ( null ) ; } options . data = rStream_1 ; } else { params . uploadType = 'media' ; Object . assign ( headers , { 'Content-Type' : media . mimeType || defaultMime } ) ; options . data = media . body ; } } else { options . data = resource || undefined ; } options . headers = headers ; options . params = params ; options = Object . assign ( { } , parameters . context . google . _options , parameters . context . _options , options ) ; delete options . auth ; if ( authClient ) { authClient . request ( options , callback ) ; } else { ( new google_auth_library_1 . DefaultTransporter ( ) ) . request ( options , callback ) ; } }
Create and send request to Google API
 @param  {object}   parameters Parameters used to form request
 @param  {Function} callback   Callback when request finished or error found
 @return {Request}             Returns Request object or null
Create and send request to Google API @param { object } parameters Parameters used to form request @param { Function } callback Callback when request finished or error found @return { Request } Returns Request object or null
// If the params are not present, and callback was passed instead, // use params as the callback and create empty params. // Create a new params object so it can no longer be modified from outside // code Also support global and per-client params, but allow them to be // overriden per-request // New base object // Global params // Per-client params // API call params // Grab headers from user provided options // Un-alias parameters that were modified due to conflicts with reserved names // Normalize callback // Check for missing required parameters in the API request // Some params are missing - stop further operations and inform the // developer which required params are not included in the request // Parse urls // When forming the querystring, override the serializer so that array // values are serialized like this: // myParams: ['one', 'two'] ---> 'myParams=one&myParams=two' // This serializer also encodes spaces in the querystring as `%20`, // whereas the default serializer in axios encodes to a `+`. // delete path parameters from the params object so they do not end up in // query // if authClient is actually a string, use it as an API KEY // Axios doesn't support multipart/related uploads, so it has to // be implemented here. // can be a readable stream or raw string! // is overridden by our auth code // create request (using authClient or otherwise and return request obj)