Skip to content

Arrow functions, let/const, and cleanup #732

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions lib/apirequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

var utils = require('./utils.js');
var DefaultTransporter = require('./transporters.js');
var stream = require('stream');
var parseString = require('string-template');
const googleauth = require('./googleauth.js');
const utils = googleauth.utils;
const DefaultTransporter = googleauth.transporters;
const stream = require('stream');
const parseString = require('string-template');

function isReadableStream (obj) {
return obj instanceof stream.Stream &&
Expand All @@ -35,7 +34,7 @@ function createCallback (callback) {
}

function getMissingParams (params, required) {
var missing = [];
const missing = [];

required.forEach(function (param) {
// Is the required param in the params object?
Expand All @@ -55,9 +54,9 @@ function getMissingParams (params, required) {
* @return {Request} Returns Request object or null
*/
function createAPIRequest (parameters, callback) {
var req, body, missingParams;
var params = parameters.params;
var options = utils.extend({}, parameters.options);
let req, body, missingParams;
let params = parameters.params;
let options = utils.extend({}, parameters.options);

// If the params are not present, and callback was passed instead,
// use params as the callback and create empty params.
Expand All @@ -75,25 +74,25 @@ function createAPIRequest (parameters, callback) {
params // API call params
);

var media = params.media || {};
var resource = params.resource;
var authClient = params.auth ||
const media = params.media || {};
const resource = params.resource;
let authClient = params.auth ||
parameters.context._options.auth ||
parameters.context.google._options.auth;

var defaultMime = typeof media.body === 'string' ? 'text/plain' : 'application/octet-stream';
const defaultMime = typeof media.body === 'string' ? 'text/plain' : 'application/octet-stream';
delete params.media;
delete params.resource;
delete params.auth;

// Grab headers from user provided options
var headers = params.headers || {};
const headers = params.headers || {};
delete params.headers;

// Un-alias parameters that were modified due to conflicts with reserved names
Object.keys(params).forEach(function (key) {
if (key.slice(-1) === '_') {
var newKey = key.slice(0, -1);
const newKey = key.slice(0, -1);
params[newKey] = params[key];
delete params[key];
}
Expand Down
24 changes: 0 additions & 24 deletions lib/auth/computeclient.ts

This file was deleted.

24 changes: 0 additions & 24 deletions lib/auth/jwtclient.ts

This file was deleted.

24 changes: 0 additions & 24 deletions lib/auth/loginticket.ts

This file was deleted.

24 changes: 0 additions & 24 deletions lib/auth/oauth2client.ts

This file was deleted.

62 changes: 30 additions & 32 deletions lib/discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,19 @@
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';
const generatorUtils = require('./generator_utils');
const DefaultTransporter = generatorUtils.DefaultTransporter;
const handleError = generatorUtils.handleError;
const async = require('async');
const fs = require('fs');
const url = require('url');
const util = require('util');
const createAPIRequest = require('./apirequest');

var generatorUtils = require('./generator_utils');
var DefaultTransporter = generatorUtils.DefaultTransporter;
var handleError = generatorUtils.handleError;
var async = require('async');
var fs = require('fs');
var url = require('url');
var util = require('util');
var createAPIRequest = require('./apirequest');

var transporter = new DefaultTransporter();
const transporter = new DefaultTransporter();

function getPathParams (params) {
var pathParams = [];
const pathParams = [];
if (typeof params !== 'object') {
params = {};
}
Expand All @@ -48,9 +46,9 @@ function getPathParams (params) {
*/
function makeMethod (schema, method, context) {
return function (params, callback) {
var url = generatorUtils.buildurl(schema.rootUrl + schema.servicePath + method.path);
const url = generatorUtils.buildurl(schema.rootUrl + schema.servicePath + method.path);

var parameters = {
const parameters = {
options: {
url: url.substring(1, url.length - 1),
method: method.httpMethod
Expand All @@ -65,7 +63,7 @@ function makeMethod (schema, method, context) {
if (method.mediaUpload && method.mediaUpload.protocols &&
method.mediaUpload.protocols.simple &&
method.mediaUpload.protocols.simple.path) {
var mediaUrl = generatorUtils.buildurl(
const mediaUrl = generatorUtils.buildurl(
schema.rootUrl +
method.mediaUpload.protocols.simple.path
);
Expand All @@ -88,8 +86,8 @@ function makeMethod (schema, method, context) {
*/
function applyMethodsFromSchema (target, rootSchema, schema, context) {
if (schema.methods) {
for (var name in schema.methods) {
var method = schema.methods[name];
for (const name in schema.methods) {
const method = schema.methods[name];
target[name] = makeMethod(rootSchema, method, context);
}
}
Expand All @@ -110,8 +108,8 @@ function applySchema (target, rootSchema, schema, context) {
applyMethodsFromSchema(target, rootSchema, schema, context);

if (schema.resources) {
for (var resourceName in schema.resources) {
var resource = schema.resources[resourceName];
for (const resourceName in schema.resources) {
const resource = schema.resources[resourceName];
if (!target[resourceName]) {
target[resourceName] = {};
}
Expand All @@ -128,8 +126,8 @@ function applySchema (target, rootSchema, schema, context) {
* @return Function The Endpoint.
*/
function makeEndpoint (schema) {
var Endpoint = function (options) {
var self = this;
const Endpoint = function (options) {
const self = this;
self._options = options || {};

applySchema(self, schema, schema, self);
Expand Down Expand Up @@ -165,8 +163,8 @@ Discovery.prototype.log = function () {
* @throws {Error} If there is an error generating any of the APIs
*/
Discovery.prototype.discoverAllAPIs = function (discoveryUrl, callback) {
var self = this;
var headers = this.options.includePrivate ? {} : { 'X-User-Ip': '0.0.0.0' };
const self = this;
const headers = this.options.includePrivate ? {} : { 'X-User-Ip': '0.0.0.0' };
transporter.request({
uri: discoveryUrl,
headers: headers
Expand All @@ -190,15 +188,15 @@ Discovery.prototype.discoverAllAPIs = function (discoveryUrl, callback) {
return callback(err);
}

var versionIndex = {};
var apisIndex = {};
const versionIndex = {};
const apisIndex = {};

apis.forEach(function (api) {
if (!apisIndex[api.name]) {
versionIndex[api.name] = {};
apisIndex[api.name] = function (options) {
var type = typeof options;
var version;
const type = typeof options;
let version;
if (type === 'string') {
version = options;
options = {};
Expand All @@ -209,8 +207,8 @@ Discovery.prototype.discoverAllAPIs = function (discoveryUrl, callback) {
throw new Error('Argument error: Accepts only string or object');
}
try {
var Endpoint = versionIndex[api.name][version];
var ep = new Endpoint(options);
const Endpoint = versionIndex[api.name][version];
const ep = new Endpoint(options);
ep.google = this; // for drive.google.transporter
return Object.freeze(ep); // create new & freeze
} catch (e) {
Expand Down Expand Up @@ -243,7 +241,7 @@ Discovery.prototype.discoverAPI = function (apiDiscoveryUrl, callback) {
}

if (typeof apiDiscoveryUrl === 'string') {
var parts = url.parse(apiDiscoveryUrl);
const parts = url.parse(apiDiscoveryUrl);

if (apiDiscoveryUrl && !parts.protocol) {
this.log('Reading from file ' + apiDiscoveryUrl);
Expand All @@ -263,9 +261,9 @@ Discovery.prototype.discoverAPI = function (apiDiscoveryUrl, callback) {
}, _generate);
}
} else {
var options = apiDiscoveryUrl;
const options = apiDiscoveryUrl;
this.log('Requesting ' + options.url);
var parameters = {
const parameters = {
options: {
url: options.url,
method: 'GET'
Expand Down
Loading