Skip to content
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

[tradeoff-analytics] Add support for "generate_visualization" #191

Merged
merged 2 commits into from
Dec 25, 2015
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "watson-developer-cloud",
"version": "1.1.2",
"version": "1.1.3",
"description": "Client library to use the IBM Watson Services and AlchemyAPI",
"main": "./lib/index",
"repository": {
Expand Down
7 changes: 5 additions & 2 deletions services/tradeoff_analytics/v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ function TradeoffAnalytics(options) {
* @param {String} params.options A list of options. Typically, the rows in a
* table representation of your data
* @param {String} params.metadataHeader Value of the x-watson-metadata header to be forwarded
* for analytics purposes
* for analytics purposes
* @param {String} params.generate_visualization Boolean (default = true). if false, the algorithm
* will not create the "map" visualization, and will typically run much faster
*/
TradeoffAnalytics.prototype.dilemmas = function(params, callback) {
params = params || {};
Expand All @@ -55,10 +57,11 @@ TradeoffAnalytics.prototype.dilemmas = function(params, callback) {
options: {
method: 'POST',
url: '/v1/dilemmas',
body: omit(params,['metadata_header']),
body: omit(params,['metadata_header','generate_visualization']),
headers: {
'x-watson-metadata' : params.metadata_header
},
qs: params.generate_visualization === false ? {'generate_visualization': false} : undefined,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change

qs: params.generate_visualization === false ? {'generate_visualization': false} : undefined,

to be:

qs: pick(params, ['generate_visualization'] ),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the reason I did it like that is that I wanted to go with a more 'strict'
approach, and accept only booleans. Maybe I should have added some
assertion to check this.

2015-12-24 18:36 GMT+02:00 German Attanasio Ruiz notifications@github.com:

In services/tradeoff_analytics/v1.js
#191 (comment)
:

   headers: {
     'x-watson-metadata' : params.metadata_header
   },
  •  qs: params.generate_visualization === false ? {'generate_visualization': false} : undefined,
    

Can we change

qs: params.generate_visualization === false ? {'generate_visualization': false} : undefined,

to be:

qs: pick(params, ['generate_visualization'] ),


Reply to this email directly or view it on GitHub
https://github.com/watson-developer-cloud/node-sdk/pull/191/files#r48420472
.

json: true
},
requiredParams: ['columns', 'subject', 'options'],
Expand Down
49 changes: 40 additions & 9 deletions test/test.tradeoff_analytics.v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('tradeoff_analytics', function() {
var service_response = {};

var service_path = '/v1/dilemmas';
var service_path_no_viz = '/v1/dilemmas?generate_visualization=false';
var events_path = '/v1/events';

var service = {
Expand All @@ -30,6 +31,10 @@ describe('tradeoff_analytics', function() {
.persist()
.post(service_path, service_request)
.reply(200, service_response);
nock(service.url)
.persist()
.post(service_path_no_viz, service_request)
.reply(200, service_response);
nock(service.url)
.persist()
.post(events_path, events_request)
Expand Down Expand Up @@ -68,17 +73,43 @@ describe('tradeoff_analytics', function() {
assert.equal(req.headers['x-watson-metadata'], params.metadata_header);
assert.equal(req.method, 'POST');
});

it('should append generate_visualization=false query param to url if (and only if) needed', function() {
// check with generate_visualization = false
var params = extend({}, service_request);
params.generate_visualization = false;
var req = tradeoff_analytics.dilemmas(params, noop);
assert.equal(req.uri.href, service.url + service_path_no_viz);

// check with generate_visualization = true
params = extend({}, service_request);
params.generate_visualization = true;
req = tradeoff_analytics.dilemmas(params, noop);
assert.equal(req.uri.href, service.url + service_path);

// check with generate_visualization = 'sdfsd' - should be same as 'true'
params = extend({}, service_request);
params.generate_visualization = 'sdfsd';
req = tradeoff_analytics.dilemmas(params, noop);
assert.equal(req.uri.href, service.url + service_path);

// check without generate_visualization- should be same as 'true'
params = extend({}, service_request);
req = tradeoff_analytics.dilemmas(params, noop);
assert.equal(req.uri.href, service.url + service_path);
});


it('should forward the events correctly', function() {
var params = extend({}, events_request);
params.metadata_header = 'test_header_content';
var req = tradeoff_analytics.events(params, noop);
var body = new Buffer(req.body).toString('ascii');
assert.equal(req.uri.href, service.url + events_path);
assert.equal(body, JSON.stringify(events_request));
assert.notEqual(body, JSON.stringify(params));
assert.equal(req.headers['x-watson-metadata'], params.metadata_header);
assert.equal(req.method, 'POST');
var params = extend({}, events_request);
params.metadata_header = 'test_header_content';
var req = tradeoff_analytics.events(params, noop);
var body = new Buffer(req.body).toString('ascii');
assert.equal(req.uri.href, service.url + events_path);
assert.equal(body, JSON.stringify(events_request));
assert.notEqual(body, JSON.stringify(params));
assert.equal(req.headers['x-watson-metadata'], params.metadata_header);
assert.equal(req.method, 'POST');
});

it('should format the response', function(done) {
Expand Down