Skip to content

Commit

Permalink
(mostly) automated fixes to adheer to new, stricter lint rules & styling
Browse files Browse the repository at this point in the history
  • Loading branch information
nfriedly committed Feb 3, 2017
1 parent a0ff196 commit cb0ed74
Show file tree
Hide file tree
Showing 105 changed files with 4,613 additions and 4,319 deletions.
36 changes: 18 additions & 18 deletions alchemy-data-news/v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

'use strict';

var extend = require('extend');
var requestFactory = require('../lib/requestwrapper');
var util = require('util');
var BaseServiceAlchemy = require('../lib/base_service_alchemy');
var errorFormatter = require('../lib/alchemy_error_formatter');
const extend = require('extend');
const requestFactory = require('../lib/requestwrapper');
const util = require('util');
const BaseServiceAlchemy = require('../lib/base_service_alchemy');
const errorFormatter = require('../lib/alchemy_error_formatter');

/**
* @param options
Expand All @@ -43,20 +43,20 @@ AlchemyDataNewsV1.URL = 'https://gateway-a.watsonplatform.net/calls';
* @param params.start
* @param {Function} callback
*/
AlchemyDataNewsV1.prototype.getNews = function (params, callback ) {
params = params || {};
AlchemyDataNewsV1.prototype.getNews = function(params, callback) {
params = params || {};

var parameters = {
options: {
url: '/data/GetNews',
method: 'GET',
json: true,
qs: extend({}, params, {outputMode: 'json'}) // change default output to json
},
requiredParams: ['end','start'],
defaultOptions: this._options
};
return requestFactory(parameters, errorFormatter(callback));
const parameters = {
options: {
url: '/data/GetNews',
method: 'GET',
json: true,
qs: extend({}, params, { outputMode: 'json' }) // change default output to json
},
requiredParams: ['end', 'start'],
defaultOptions: this._options
};
return requestFactory(parameters, errorFormatter(callback));
};

module.exports = AlchemyDataNewsV1;
55 changes: 27 additions & 28 deletions alchemy-language/v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,39 @@

'use strict';

var extend = require('extend');
var util = require('util');
var BaseServiceAlchemy = require('../lib/base_service_alchemy');
var requestFactory = require('../lib/requestwrapper');
const extend = require('extend');
const util = require('util');
const BaseServiceAlchemy = require('../lib/base_service_alchemy');
const requestFactory = require('../lib/requestwrapper');
// IMPORTANT:
// Due to the current design, the URL must be the last key on each endpoint or
// it could inadvertently clobber a url query param in the users request.
// see #236
var endpoints = require('../lib/alchemy_endpoints.json');
var helper = require('../lib/helper');
var pick = require('object.pick');
var errorFormatter = require('../lib/alchemy_error_formatter');
const endpoints = require('../lib/alchemy_endpoints.json');
const helper = require('../lib/helper');
const pick = require('object.pick');
const errorFormatter = require('../lib/alchemy_error_formatter');

function createRequest(method) {
return function(_params, callback ) {
var params = _params || {};
var accepted_formats = Object.keys(endpoints[method]);
var format = helper.getFormat(params, accepted_formats);
return function(_params, callback) {
const params = _params || {};
const accepted_formats = Object.keys(endpoints[method]);
const format = helper.getFormat(params, accepted_formats);

if (format === null) {
callback(new Error('Missing required parameters: ' +
accepted_formats.join(', ') +
' needs to be specified'));
callback(new Error('Missing required parameters: ' + accepted_formats.join(', ') + ' needs to be specified'));
return;
}

var parameters = {
const parameters = {
options: {
url: endpoints[method][format],
method: 'POST',
json: true,
qs: pick(params, ['model']),
form: extend({}, params, {outputMode: 'json'}) // change default output to json
form: extend({}, params, { outputMode: 'json' }) // change default output to json
},
defaultOptions: this._options
defaultOptions: this._options // eslint-disable-line no-invalid-this
};
return requestFactory(parameters, errorFormatter(callback));
};
Expand Down Expand Up @@ -98,10 +96,11 @@ AlchemyLanguageV1.prototype.concepts = createRequest('concepts');
* Calculates the sentiment for text, a URL or HTML.
*/
AlchemyLanguageV1.prototype.sentiment = function(params, callback) {
var _params = extend({}, params);
var service = (params.target || params.targets) ? 'sentiment_targeted' : 'sentiment';
if (util.isArray(_params.targets))
{_params.targets = _params.targets.join('|');}
const _params = extend({}, params);
const service = params.target || params.targets ? 'sentiment_targeted' : 'sentiment';
if (util.isArray(_params.targets)) {
_params.targets = _params.targets.join('|');
}

return createRequest(service).call(this, _params, callback);
};
Expand All @@ -110,7 +109,7 @@ AlchemyLanguageV1.prototype.sentiment = function(params, callback) {
* if raw = true, extracts the cleaned text (removes ads, navigation, etc.).
*/
AlchemyLanguageV1.prototype.text = function(params, callback) {
var service = (params && params.raw) ? 'text_raw' : 'text';
const service = params && params.raw ? 'text_raw' : 'text';
return createRequest(service).call(this, params, callback);
};

Expand Down Expand Up @@ -213,10 +212,11 @@ AlchemyLanguageV1.prototype.combined = createRequest('combined');
* @param {Function} callback
*/
AlchemyLanguageV1.prototype.emotion = function(params, callback) {
var _params = extend({}, params);
var service = (params.target || params.targets) ? 'emotion_targeted' : 'emotion';
if (util.isArray(_params.targets))
{_params.targets = _params.targets.join('|');}
const _params = extend({}, params);
const service = params.target || params.targets ? 'emotion_targeted' : 'emotion';
if (util.isArray(_params.targets)) {
_params.targets = _params.targets.join('|');
}

return createRequest(service).call(this, _params, callback);
};
Expand All @@ -230,5 +230,4 @@ AlchemyLanguageV1.prototype.emotion = function(params, callback) {
*/
AlchemyLanguageV1.prototype.typedRelations = createRequest('typed_relations');


module.exports = AlchemyLanguageV1;
42 changes: 20 additions & 22 deletions alchemy-vision/v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,50 +16,49 @@

'use strict';

var requestFactory = require('../lib/requestwrapper');
var endpoints = require('../lib/alchemy_endpoints.json');
var helper = require('../lib/helper');
var isStream = require('isstream');
var omit = require('object.omit');
var fs = require('fs');
var util = require('util');
var BaseServiceAlchemy = require('../lib/base_service_alchemy');
var errorFormatter = require('../lib/alchemy_error_formatter');
const requestFactory = require('../lib/requestwrapper');
const endpoints = require('../lib/alchemy_endpoints.json');
const helper = require('../lib/helper');
const isStream = require('isstream');
const omit = require('object.omit');
const fs = require('fs');
const util = require('util');
const BaseServiceAlchemy = require('../lib/base_service_alchemy');
const errorFormatter = require('../lib/alchemy_error_formatter');

function createRequest(method) {
return function(_params, callback ) {
var params = _params || {};
var accepted_formats = Object.keys(endpoints[method]);
var format = helper.getFormat(params, accepted_formats);
return function(_params, callback) {
const params = _params || {};
const accepted_formats = Object.keys(endpoints[method]);
const format = helper.getFormat(params, accepted_formats);

if (format === null) {
callback(new Error('Missing required parameters: ' +
accepted_formats.join(', ') +
' needs to be specified'));
callback(new Error('Missing required parameters: ' + accepted_formats.join(', ') + ' needs to be specified'));
return;
}
// always return json
params.outputMode = 'json';

var parameters = {
const parameters = {
options: {
url: endpoints[method][format],
method: 'POST'
},
defaultOptions: this._options
defaultOptions: this._options // eslint-disable-line no-invalid-this
};

if (!params.image || !isStream(params.image)) {
// url or base64 images are considered 'not-raw'
if (params.image)
{params.imagePostMode = 'not-raw';}
if (params.image) {
params.imagePostMode = 'not-raw';
}
// send the parameters as form url-encoded
parameters.options.form = params;
return requestFactory(parameters, errorFormatter(callback));
} else {
params.imagePostMode = 'raw';
// send the parameters as query parameters
parameters.options.qs = omit(params,['image']);
parameters.options.qs = omit(params, ['image']);
// add the content-length to the headers
parameters.options.headers = {
'Content-Length': fs.statSync(params.image.path).size
Expand All @@ -69,7 +68,6 @@ function createRequest(method) {
};
}


/**
*
* @param options
Expand Down
19 changes: 9 additions & 10 deletions authorization/v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

'use strict';

var requestFactory = require('../lib/requestwrapper');
var url = require('url');
var util = require('util');
var BaseService = require('../lib/base_service');
const requestFactory = require('../lib/requestwrapper');
const url = require('url');
const util = require('util');
const BaseService = require('../lib/base_service');

/**
*
Expand All @@ -33,7 +33,7 @@ function AuthorizationV1(options) {
BaseService.call(this, options);
this.target_url = options.url;
// replace the url to always point to /authorization/api
var hostname = url.parse(this._options.url);
const hostname = url.parse(this._options.url);
hostname.pathname = '/authorization/api';
this._options.url = url.format(hostname);
}
Expand All @@ -52,22 +52,21 @@ AuthorizationV1.URL = 'https://stream.watsonplatform.net/authorization/api';
AuthorizationV1.prototype.getToken = function(params, callback) {
if (typeof params === 'function') {
callback = params;
params = {url: this.target_url};
params = { url: this.target_url };
}
if (!params.url){
if (!params.url) {
callback(new Error('Missing required parameters: url'));
return;
}

var parameters = {
const parameters = {
options: {
method: 'GET',
url: '/v1/token?url='+params.url
url: '/v1/token?url=' + params.url
},
defaultOptions: this._options
};
return requestFactory(parameters, callback);
};


module.exports = AuthorizationV1;
14 changes: 8 additions & 6 deletions conversation/v1-experimental.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

'use strict';

var requestFactory = require('../lib/requestwrapper');
var pick = require('object.pick');
var util = require('util');
var BaseService = require('../lib/base_service');
const requestFactory = require('../lib/requestwrapper');
const pick = require('object.pick');
const util = require('util');
const BaseService = require('../lib/base_service');

/**
*
Expand All @@ -31,7 +31,9 @@ function ConversationV1Experimental(options) {

if (!this._options.silent) {
// eslint-disable-next-line no-console
console.warn(new Error("Watson Conversation v1-experimental is sunset as of 2016-08-01. Please upgrade to v1. Set {silent: true} to disable this message.").stack);
console.warn(
new Error('Watson Conversation v1-experimental is sunset as of 2016-08-01. Please upgrade to v1. Set {silent: true} to disable this message.').stack
);
}

// Check if 'version_date' was provided
Expand All @@ -52,7 +54,7 @@ ConversationV1Experimental.URL = 'https://gateway.watsonplatform.net/conversatio
ConversationV1Experimental.prototype.message = function(params, callback) {
params = params || {};

var parameters = {
const parameters = {
options: {
url: '/v1/workspaces/{workspace_id}/message',
method: 'POST',
Expand Down
10 changes: 5 additions & 5 deletions conversation/v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

'use strict';

var requestFactory = require('../lib/requestwrapper');
var pick = require('object.pick');
var util = require('util');
var BaseService = require('../lib/base_service');
const requestFactory = require('../lib/requestwrapper');
const pick = require('object.pick');
const util = require('util');
const BaseService = require('../lib/base_service');

/**
*
Expand Down Expand Up @@ -135,7 +135,7 @@ ConversationV1.VERSION_DATE_2016_09_20 = '2016-09-20';
ConversationV1.prototype.message = function(params, callback) {
params = params || {};

var parameters = {
const parameters = {
options: {
url: '/v1/workspaces/{workspace_id}/message',
method: 'POST',
Expand Down
3 changes: 2 additions & 1 deletion dependency-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@ executedModules:
- watchify
- minify
- build
- compat-check
shellScripts:
dev: []
ignore: []
root: ''

ignoreErrors:
missing: []
shouldBeDependency: []
shouldBeDevDependency: []
unused:
- karma-*
- eslint-*

requiredModules:
files:
Expand Down
Loading

0 comments on commit cb0ed74

Please sign in to comment.