Skip to content

Commit 7f9c3d7

Browse files
committed
[WIP] begining of callback url registering
1 parent 1b60f7e commit 7f9c3d7

File tree

3 files changed

+113
-78
lines changed

3 files changed

+113
-78
lines changed

speech-to-text/v1.js

Lines changed: 95 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,28 @@ SpeechToTextV1.prototype.name = 'speech_to_text';
9090
SpeechToTextV1.prototype.version = 'v1';
9191
SpeechToTextV1.URL = 'https://stream.watsonplatform.net/speech-to-text/api';
9292

93+
SpeechToTextV1.prototype.registerCallbackUrl = function(params, callback) {
94+
const missingParams = helper.getMissingParams(params, ['callback_url']);
95+
if (missingParams) {
96+
callback(missingParams);
97+
return;
98+
}
99+
100+
const parameters = {
101+
requiredParams: ['callback_url'],
102+
options: {
103+
method: 'POST',
104+
url: '/v1/register_callback',
105+
qs: pick(params, ['callback_url', 'user_secret']),
106+
body: {},
107+
json: true
108+
},
109+
defaultOptions: this._options
110+
};
111+
112+
return requestFactory(parameters, callback);
113+
};
114+
93115
/**
94116
* Speech recognition for given audio using default model.
95117
*
@@ -405,14 +427,9 @@ SpeechToTextV1.prototype.createRecognizeStream = function(params) {
405427
SpeechToTextV1.prototype[name] = function deprecated(params) {
406428
if (!(params || {}).silent && !this._options.silent) {
407429
// eslint-disable-next-line no-console
408-
console.log(
409-
new Error(
410-
'The ' +
411-
name +
412-
'() method is deprecated and will be removed from a future version of the watson-developer-cloud SDK. ' +
413-
'Please use createRecognizeStream() instead.\n(Set {silent: true} to hide this message.)'
414-
)
415-
);
430+
console.log(new Error(
431+
`The ${name}() method is deprecated and will be removed from a future version of the watson-developer-cloud SDK. Please use createRecognizeStream() instead.\n(Set {silent: true} to hide this message.)`
432+
));
416433
}
417434
return original.apply(this, arguments);
418435
};
@@ -460,37 +477,37 @@ SpeechToTextV1.prototype.createCustomization = function(params, callback) {
460477
* List all customizations
461478
*
462479
* Example response:
463-
```json
464-
{ customizations:
465-
[ { owner: '8a6f5bb1-5b2d-4a20-85a9-eaa421d25c88',
466-
base_model_name: 'en-US_BroadbandModel',
467-
customization_id: '6a7785a0-9665-11e6-a73a-0da9193a4475',
468-
created: '2016-10-20T01:35:00.346Z',
469-
name: 'IEEE-test',
470-
description: '',
471-
progress: 0,
472-
language: 'en-US',
473-
status: 'pending' },
474-
{ owner: '8a6f5bb1-5b2d-4a20-85a9-eaa421d25c88',
475-
base_model_name: 'en-US_BroadbandModel',
476-
customization_id: '9e2f6bb0-9665-11e6-a73a-0da9193a4475',
477-
created: '2016-10-20T01:36:27.115Z',
478-
name: 'IEEE-test',
479-
description: '',
480-
progress: 0,
481-
language: 'en-US',
482-
status: 'ready' },
483-
{ owner: '8a6f5bb1-5b2d-4a20-85a9-eaa421d25c88',
484-
base_model_name: 'en-US_BroadbandModel',
485-
customization_id: '6b194e70-9666-11e6-a73a-0da9193a4475',
486-
created: '2016-10-20T01:42:10.903Z',
487-
name: 'IEEE-test',
488-
description: '',
489-
progress: 100,
490-
language: 'en-US',
491-
status: 'available' } ] }
480+
```json
481+
{ customizations:
482+
[ { owner: '8a6f5bb1-5b2d-4a20-85a9-eaa421d25c88',
483+
base_model_name: 'en-US_BroadbandModel',
484+
customization_id: '6a7785a0-9665-11e6-a73a-0da9193a4475',
485+
created: '2016-10-20T01:35:00.346Z',
486+
name: 'IEEE-test',
487+
description: '',
488+
progress: 0,
489+
language: 'en-US',
490+
status: 'pending' },
491+
{ owner: '8a6f5bb1-5b2d-4a20-85a9-eaa421d25c88',
492+
base_model_name: 'en-US_BroadbandModel',
493+
customization_id: '9e2f6bb0-9665-11e6-a73a-0da9193a4475',
494+
created: '2016-10-20T01:36:27.115Z',
495+
name: 'IEEE-test',
496+
description: '',
497+
progress: 0,
498+
language: 'en-US',
499+
status: 'ready' },
500+
{ owner: '8a6f5bb1-5b2d-4a20-85a9-eaa421d25c88',
501+
base_model_name: 'en-US_BroadbandModel',
502+
customization_id: '6b194e70-9666-11e6-a73a-0da9193a4475',
503+
created: '2016-10-20T01:42:10.903Z',
504+
name: 'IEEE-test',
505+
description: '',
506+
progress: 100,
507+
language: 'en-US',
508+
status: 'available' } ] }
492509
493-
```
510+
```
494511
*
495512
* @param {Object} params The parameters
496513
* @param {String} [params.language] optional filter.
@@ -518,7 +535,7 @@ SpeechToTextV1.prototype.getCustomizations = function(params, callback) {
518535
*
519536
* Example response:
520537
*
521-
```json
538+
```json
522539
{ owner: '8a6f5bb1-5b2d-4a20-85a9-eaa421d25c88',
523540
base_model_name: 'en-US_BroadbandModel',
524541
customization_id: 'e695ad30-97c1-11e6-be92-bb627d4684b9',
@@ -528,7 +545,7 @@ SpeechToTextV1.prototype.getCustomizations = function(params, callback) {
528545
progress: 0,
529546
language: 'en-US',
530547
status: 'pending' }
531-
```
548+
```
532549
*
533550
*
534551
* @param {Object} params The parameters
@@ -686,14 +703,14 @@ SpeechToTextV1.prototype.getCorpora = function(params, callback) {
686703
*
687704
* Example response:
688705
*
689-
```json
690-
{
691-
"name": "corpus-1",
692-
"total_words": 100,
693-
"out_of_vocabulary_words": 5,
694-
"status": "analyzed"
695-
}
696-
```
706+
```json
707+
{
708+
"name": "corpus-1",
709+
"total_words": 100,
710+
"out_of_vocabulary_words": 5,
711+
"status": "analyzed"
712+
}
713+
```
697714
*
698715
*
699716
* @param {Object} params The parameters
@@ -960,36 +977,36 @@ SpeechToTextV1.prototype.addWord = function(params, callback) {
960977
* You can list all words from the custom model's words resource, only custom words that were added or modified by the user, or only OOV words that were extracted from corpora.
961978
*
962979
* Example response:
963-
```json
964-
{
965-
"words": [
966-
{
967-
"word": "hhonors",
968-
"sounds_like": ["hilton honors","h honors"],
969-
"display_as": "HHonors",
970-
"source": ["corpus1"]
971-
},
972-
{
973-
"word": "ieee",
974-
"sounds_like": ["i triple e"],
975-
"display_as": "IEEE",
976-
"source": ["corpus1","corpus2"]
977-
},
978-
{
979-
"word": "tomato",
980-
"sounds_like": ["tomatoh","tomayto"],
981-
"display_as": "",
982-
"source": ["user"]
983-
},
984-
{
985-
"word": "$75.00",
986-
"sounds_like": ["75 dollars"],
987-
"display_as": "",
988-
"source": ["user"],
989-
"error":" Numbers are not allowed in sounds-like"
990-
}
991-
]
992-
}
980+
```json
981+
{
982+
"words": [
983+
{
984+
"word": "hhonors",
985+
"sounds_like": ["hilton honors","h honors"],
986+
"display_as": "HHonors",
987+
"source": ["corpus1"]
988+
},
989+
{
990+
"word": "ieee",
991+
"sounds_like": ["i triple e"],
992+
"display_as": "IEEE",
993+
"source": ["corpus1","corpus2"]
994+
},
995+
{
996+
"word": "tomato",
997+
"sounds_like": ["tomatoh","tomayto"],
998+
"display_as": "",
999+
"source": ["user"]
1000+
},
1001+
{
1002+
"word": "$75.00",
1003+
"sounds_like": ["75 dollars"],
1004+
"display_as": "",
1005+
"source": ["user"],
1006+
"error":" Numbers are not allowed in sounds-like"
1007+
}
1008+
]
1009+
}
9931010
```
9941011
*
9951012
* @param {Object} params The parameters

test/integration/test.speech_to_text.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,5 +380,10 @@ describe('speech_to_text_integration', function() {
380380
speech_to_text.deleteCustomization({ customization_id: customization_id }, done);
381381
customization_id = null;
382382
});
383+
384+
it('register callbackUrl', function(done) {
385+
const params = { callback_url: 'http://{user_callback_path}/results', user_secret: 'ThisIsMySecret' };
386+
speech_to_text.registerCallbackUrl(params, done);
387+
});
383388
});
384389
});

test/unit/test.speech_to_text.v1.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,4 +344,17 @@ describe('speech_to_text', function() {
344344
assert(isStream(speech_to_text.createRecognizeStream()));
345345
});
346346
});
347+
348+
it('should register a callback url', function() {
349+
const path = '/v1/register_callback';
350+
const response = {};
351+
352+
nock(service.url).persist().get(path).reply(200, response);
353+
354+
const params = { callback_url: 'http://{user_callback_path}/results', user_secret: 'ThisIsMySecret' };
355+
const req = speech_to_text.registerCallbackUrl(params, (err, res) => assert.equal(JSON.stringify(res), 'toto'));
356+
357+
assert.equal(req.uri.href, service.url + path + '?callback_url=http%3A%2F%2F%7Buser_callback_path%7D%2Fresults&user_secret=ThisIsMySecret');
358+
assert.equal(req.method, 'POST');
359+
});
347360
});

0 commit comments

Comments
 (0)