Socket
Socket
Sign inDemoInstall

googleapis

Package Overview
Dependencies
Maintainers
1
Versions
257
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

googleapis - npm Package Compare versions

Comparing version 0.4.6 to 0.4.7

test/data/discovery_plus.json

42

lib/client.js

@@ -31,3 +31,3 @@ /**

// generate helper methods
this.extend_(this, apiMeta.resources || {});
this.extend_(this, apiMeta.methods || {}, apiMeta.resources || {});
}

@@ -53,19 +53,2 @@

* @private
* Extends the object with the given resource and its methods
* recursively.
* @param {?object} root Object to be extended.
*/
Client.prototype.extend_ = function(root, resources) {
for (var key in resources || {}) {
root[key] = root[key] || {};
for (var methodName in resources[key].methods || {}) {
root[key][methodName] =
this.generateHelper_(resources[key].methods[methodName]);
}
this.extend_(root[key], resources[key].resources || {});
}
};
/**
* @private
* Generate a request builder helper.

@@ -88,3 +71,3 @@ *

*
* @param {string} methodName Full name of the method.
* @param {object} methodMetada Discovery metadata of the method.
* @param {?object} params Parameters.

@@ -126,4 +109,25 @@ * @param {object=} opt_resource Optional resource.

/**
* @private
* Extends the object with the given resource and its methods
* recursively.
* @param {?object} root Object to be extended.
* @param {object} methods Discovery methods to extend the object with.
* @param {object} resources Discovery resources to extend the object with.
*/
Client.prototype.extend_ = function(root, methods, resources) {
for (var methodName in methods) {
root[methodName] = this.generateHelper_(methods[methodName]);
}
for (var key in resources) {
root[key] = root[key] || {};
this.extend_(
root[key],
resources[key].methods || {},
resources[key].resources || {});
}
};
/**
* Exporting Client.
*/
module.exports = Client;

@@ -113,4 +113,4 @@ /**

});
if (!alreadyDiscovered) {
if (!alreadyDiscovered) {
this.toBeDiscovered.push({

@@ -117,0 +117,0 @@ name: name, version: version, opts: opt_opts });

@@ -31,2 +31,5 @@ /**

/**
* Base URL for Google APIs endpoint.
*/
BaseRequest.BASE_URL = 'https://www.googleapis.com';

@@ -82,2 +85,3 @@

* Generates payload body of the request.
* @param {string} rootUrl
* @return {object?} Request payload.

@@ -105,2 +109,38 @@ */

/**
* Creates a URL with a root, paths and optionally query parameters.
*
* @param {string} root Root of the url e.g. http://myserver
* @param {Array} paths An array of string that will be joined to a
single path
* @param {object} queryParams Query parameters of the path, we be also used
* to replace inline path parameters e.g. {param}
* @return {string} A URL.
*/
var buildUri = function(root, paths, queryParams) {
// create a path is starts with a slash and ends without it.
// Preventing double slashes along the way
var path = '/' + paths.join('/').split('/').filter(function(p) {
return !!p;
}).join('/'),
fullPath = url.resolve(root, path);
queryParams = queryParams || {};
// replace path query parameters, if there are on the path
for (var paramName in queryParams) {
var param = '{' + paramName + '}';
if (fullPath.indexOf(param) >= 0) {
fullPath = fullPath.replace(param, queryParams[paramName]);
delete queryParams[paramName];
}
}
// append the other query parameters
if (Object.keys(queryParams).length > 0) {
fullPath += '?' + querystring.stringify(queryParams);
}
return fullPath;
};
/**
* Constructs a new Request.

@@ -110,6 +150,7 @@ * @constructor

* @param {object} apiMeta Schema returned by Discovery API.
* @param {string} methodName Method name.
* @param {string} methodMeta Method metadata.
* @param {?object} opt_params Required Parameters. If none are required,
* expected to be not passed.
* @param {object=} opt_resource Optional resource.
* @param {object=} opt_body Optional body.
* @param {object=} opt_defaultParams Optional default parameters.
*/

@@ -131,4 +172,4 @@ function Request(

if (opt_defaultParams) {
this.params = utils.extend(utils.extend({}, opt_defaultParams),
this.params);
this.params = utils.extend(
utils.extend({}, opt_defaultParams), this.params);
}

@@ -143,26 +184,31 @@ }

/**
* Generates uri to the method with given params.
* @param {object} queryParams Query params.
* @return {String} The method's endpoint URI.
*/
Request.prototype.generateMethodUri = function(queryParams) {
var p = [this.apiMeta.basePath, this.methodMeta.path];
if (this.media) {
p.unshift('/upload');
}
queryParams = queryParams || {};
if (this.apiKey) {
queryParams.key = this.apiKey;
}
return buildUri(this.apiMeta.rootUrl, p, queryParams);
};
/**
* Generates path to the method with given params.
* @param {object} queryParams Query params.
* @return {String} The method's REST path.
* @return {String} The method's REST path.
*/
Request.prototype.generatePath = function(queryParams) {
var path = this.apiMeta.basePath + this.methodMeta.path;
queryParams = queryParams || {};
if (this.apiKey) {
queryParams.key = this.apiKey;
queryParams.key = this.apiKey;
}
// replace path query parameters, if there are on the path
for (var paramName in queryParams) {
if (path.indexOf('{' + paramName + '}') >= 0) {
path = path.replace('{' + paramName + '}', queryParams[paramName]);
delete queryParams[paramName];
}
}
// append the oher query parameters
if (Object.keys(queryParams).length > 0) {
path += '?' + querystring.stringify(queryParams);
}
return path;
return buildUri(
'/', [this.apiMeta.basePath, this.methodMeta.path], queryParams);
};

@@ -172,8 +218,11 @@

* Generates an HTTP payload with a single request.
* @param {string} rootUrl The root URL of the owner API.
* @return {object} Returns request payload.
*/
Request.prototype.generatePayload = function(rootUrl) {
return !this.media ? this.generateBody(rootUrl) : this.generateUploadBody(rootUrl);
return !this.media ?
this.generateBody() : this.generateUploadBody();
};
/**

@@ -183,9 +232,9 @@ * Generates request opts.

*/
Request.prototype.generateBody = function(rootUrl) {
var path = this.generatePath(this.params);
Request.prototype.generateBody = function() {
return {
uri: rootUrl + path,
path: path,
uri: this.generateMethodUri(this.params),
path: this.generatePath(this.params),
method: this.methodMeta.httpMethod,
json: this.body
json: this.body || true // if content-type is not set, interpret it as
// application/json
};

@@ -199,14 +248,11 @@ };

*/
Request.prototype.generateUploadBody = function(rootUrl) {
Request.prototype.generateUploadBody = function() {
var params = this.params || {};
rootUrl = rootUrl.replace(/\/+$/, ''); // Remove any trailing slashes.
if (!this.body) {
params.uploadType = 'media';
return {
uri: rootUrl + '/upload' + this.generatePath(params),
uri: this.generateMethodUri(params),
method: this.methodMeta.httpMethod,
headers: {
'Content-Type': this.media.mimeType,
'Content-Type': this.media.mimeType
},

@@ -221,3 +267,3 @@ body: this.media.data

return {
uri: rootUrl + '/upload' + this.generatePath(params),
uri: this.generateMethodUri(params),
method: this.methodMeta.httpMethod,

@@ -254,13 +300,9 @@ multipart: [{

Request.prototype.execute = function(opt_callback) {
opt_callback = opt_callback || function() {};
var rootUrl = (this.apiMeta && this.apiMeta.rootUrl),
callback = this.handleResponse(opt_callback),
requestOpts = this.generatePayload(rootUrl);
var callback = this.handleResponse(opt_callback),
payload = this.generatePayload();
if (this.authClient) {
this.authClient.request(requestOpts, callback);
this.authClient.request(payload, callback);
} else {
// make the request with default client
this.transporter.request(requestOpts, callback);
this.transporter.request(payload, callback);
}

@@ -297,8 +339,10 @@ };

* Generates HTTP payload object.
*
* @param {?String} rootUrl Base URL for Google APIs endpoint. If null, replaced
* with BaseRequest.BASE_URL.
* @return {object} Generated payload.
*/
BatchRequest.prototype.generatePayload = function(rootUrl) {
// todo: implement
var multipart = [];
var multipart = [],
rootUrl = rootUrl || BaseRequest.BASE_URL;
this.requests_.forEach(function(request, key) {

@@ -309,3 +353,3 @@ var body = [];

if (request.body){
if (request.body) {
body.push(JSON.stringify(request.body), '');

@@ -323,3 +367,3 @@ }

method: 'POST',
uri: rootUrl + '/batch',
uri: buildUri(rootUrl, ['/batch']),
multipart: multipart,

@@ -367,6 +411,4 @@ headers: {

BatchRequest.prototype.execute = function(opt_callback) {
opt_callback = opt_callback || function() {};
var callback = this.handleResponse(opt_callback),
requestOpts = this.generatePayload(BaseRequest.BASE_URL);
requestOpts = this.generatePayload();
if (this.authClient) {

@@ -381,2 +423,7 @@ this.authClient.request(requestOpts, callback);

/**
* Exports buildUri.
*/
exports.buildUri = buildUri;
/**
* Exports Request.

@@ -383,0 +430,0 @@ */

{
"name": "googleapis",
"version": "0.4.6",
"version": "0.4.7",
"author": "Google Inc.",

@@ -37,5 +37,5 @@ "description": "Google APIs Client Library for Node.js",

"scripts": {
"test": "mocha tests/* --reporter spec --timeout 40000"
"test": "mocha --reporter spec --timeout 4000"
},
"license": "Apache 2"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc