Skip to content

Commit 3ad07ac

Browse files
author
James Thomas
committed
Allow setting optional request parameters, tones and sentences.
Added service code to pick up query parameters and add test cases.
1 parent c5b9643 commit 3ad07ac

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

services/tone_analyzer/v3-beta.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
'use strict';
1818

1919
var extend = require('extend');
20+
var pick = require('object.pick');
2021
var requestFactory = require('../../lib/requestwrapper');
2122

2223
function ToneAnalyzer(options) {
@@ -60,7 +61,8 @@ ToneAnalyzer.prototype.tone = function(params, callback) {
6061
options: {
6162
url: '/v3/tone',
6263
method: 'POST',
63-
body: params.text
64+
body: params.text,
65+
qs: pick(params, ['tone', 'sentences'])
6466
},
6567
defaultOptions: extend(this._options, {
6668
headers: {

test/test.tone_analyzer.v3-beta.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ describe('tone_analyzer.v3', function() {
6060
assert.equal(req.headers['accept'], 'application/json');
6161
});
6262

63+
it('tone API should add optional query parameters', function() {
64+
var options = {text: tone_request.text, tone: 'emotion', sentences: true}
65+
var req = tone_analyzer.tone(options, noop);
66+
var body = new Buffer(req.body).toString('ascii');
67+
assert.equal(req.uri.href, service.url + tone_path + '?version=2016-02-11&tone=emotion&sentences=true');
68+
assert.equal(body, tone_request.text);
69+
assert.equal(req.method, 'POST');
70+
assert.equal(req.headers['content-type'], 'text/plain');
71+
assert.equal(req.headers['accept'], 'application/json');
72+
});
73+
6374
it('tone API should format the response', function(done) {
6475
tone_analyzer.tone(tone_request, function(err, response) {
6576
if (err)

0 commit comments

Comments
 (0)