File tree Expand file tree Collapse file tree 2 files changed +29
-4
lines changed Expand file tree Collapse file tree 2 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -79,6 +79,23 @@ describe('tone_analyzer.v3', function() {
79
79
assert . equal ( req . headers [ 'accept' ] , 'application/json' ) ;
80
80
} ) ;
81
81
82
+ it ( 'tone API should add optional language parameter' , function ( ) {
83
+ const options = {
84
+ text : tone_request . text ,
85
+ tones : 'emotion' ,
86
+ sentences : true ,
87
+ language : 'en'
88
+ } ;
89
+ const req = tone_analyzer . tone ( options , noop ) ;
90
+ const body = Buffer . from ( req . body ) . toString ( 'ascii' ) ;
91
+ assert . equal ( req . uri . href , service . url + tone_path + '?version=2016-05-19&tones=emotion&sentences=true' ) ;
92
+ assert . equal ( body , tone_request . text ) ;
93
+ assert . equal ( req . method , 'POST' ) ;
94
+ assert . equal ( req . headers [ 'content-type' ] , 'text/plain' ) ;
95
+ assert . equal ( req . headers [ 'accept' ] , 'application/json' ) ;
96
+ assert . equal ( req . headers [ 'content-language' ] , 'en' ) ;
97
+ } ) ;
98
+
82
99
it ( 'tone API should set HTML content-type' , function ( ) {
83
100
const options = { text : tone_request . text , isHTML : true } ;
84
101
const req = tone_analyzer . tone ( options , noop ) ;
Original file line number Diff line number Diff line change @@ -57,6 +57,7 @@ ToneAnalyzerV3.URL = 'https://gateway.watsonplatform.net/tone-analyzer/api';
57
57
* - `isHTML`: A boolean value telling that the `params.text` argument is
58
58
* to be trated as HTML contents. On HTML input, the services does
59
59
* cleanup of tags and performs the analysis on the text contents only.
60
+ * - `language`: Language of the input. It defaults to `en`.
60
61
*
61
62
* @return upon success, the callback function is called with an object
62
63
* containing the different tones (emotion, writing and social) analyzed.
@@ -70,6 +71,16 @@ ToneAnalyzerV3.prototype.tone = function(params, callback) {
70
71
return ;
71
72
}
72
73
const contentType = params . isHTML ? 'text/html' : 'text/plain' ;
74
+
75
+ const headers = {
76
+ accept : 'application/json' ,
77
+ 'content-type' : contentType
78
+ } ;
79
+
80
+ if ( params . language ) {
81
+ headers [ 'content-language' ] = params . language ;
82
+ }
83
+
73
84
const parameters = {
74
85
options : {
75
86
url : '/v3/tone' ,
@@ -78,10 +89,7 @@ ToneAnalyzerV3.prototype.tone = function(params, callback) {
78
89
qs : pick ( params , [ 'tones' , 'sentences' ] )
79
90
} ,
80
91
defaultOptions : extend ( true , this . _options , {
81
- headers : {
82
- accept : 'application/json' ,
83
- 'content-type' : contentType
84
- }
92
+ headers : headers
85
93
} )
86
94
} ;
87
95
You can’t perform that action at this time.
0 commit comments