Skip to content

Commit 3d70c5c

Browse files
committed
wrapping up vr v3 changes/docs/tests
1 parent 8416f73 commit 3d70c5c

File tree

4 files changed

+92
-15
lines changed

4 files changed

+92
-15
lines changed

lib/requestwrapper.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ function formatErrorIfExists(cb) {
7676
* 3. Encode path and query parameters
7777
* 4. Call the api
7878
* @private
79+
* @return {ReadableStream|undefined}
7980
*/
8081
function createRequest(parameters, callback) {
8182
var missingParams = null,

services/visual_recognition/v3.js

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -435,11 +435,7 @@ VisualRecognitionV3.prototype.createClassifier = function(params, callback) {
435435
}
436436
// todo: validate that all *_examples are streams or else objects with buffers and content-types
437437

438-
if (!params.name) {
439-
callback(new Error('Missing required parameter: name'));
440-
return;
441-
}
442-
438+
443439

444440
var allowed_keys = ['name', NEGATIVE_EXAMPLES].concat(example_keys);
445441

@@ -459,10 +455,9 @@ VisualRecognitionV3.prototype.createClassifier = function(params, callback) {
459455
/**
460456
* Retrieve a list of all classifiers, including built-in and
461457
* user-created classifiers.
462-
* @param verbose If verbose is present and not equal to "0",
463-
* return detailed results for each classifier.
464458
*
465459
* Example output:
460+
466461
{"classifiers": [
467462
{
468463
"classifier_id": "fruit_679357912",
@@ -475,6 +470,11 @@ VisualRecognitionV3.prototype.createClassifier = function(params, callback) {
475470
"status": "ready"
476471
}
477472
]}
473+
474+
* @param {Object} params
475+
* @param {Boolean} [params.verbose=false]
476+
* @param {Function} callback
477+
* @return {ReadableStream|undefined}
478478
*/
479479
VisualRecognitionV3.prototype.listClassifiers = function(params, callback) {
480480
var parameters = {
@@ -491,7 +491,24 @@ VisualRecognitionV3.prototype.listClassifiers = function(params, callback) {
491491

492492
/**
493493
* Retrieves information about a specific classifier.
494-
* @param classifier_id The classifier id
494+
*
495+
* Example output:
496+
{
497+
classifier_id: 'fruit_679357912',
498+
name: 'fruit',
499+
owner: 'a3a48ea7-492b-448b-87d7-9dade8bde5a9',
500+
status: 'ready',
501+
created: '2016-05-23T21:50:41.680Z',
502+
classes: [
503+
{ class: 'banana' },
504+
{ class: 'apple' }
505+
]
506+
}
507+
508+
* @param {Object} params
509+
* @param {Boolean} params.classifier_id The classifier id
510+
* @param {Function} callback
511+
* @return {ReadableStream|undefined}
495512
*/
496513
VisualRecognitionV3.prototype.getClassifier = function(params, callback) {
497514
var parameters = {
@@ -501,16 +518,19 @@ VisualRecognitionV3.prototype.getClassifier = function(params, callback) {
501518
path: params,
502519
json: true
503520
},
504-
requiredParams: ['classifier_id', 'api_key'],
521+
requiredParams: ['classifier_id'],
505522
defaultOptions: this._options
506523
};
507524
return requestFactory(parameters, callback);
508525
};
509526

510527
/**
511528
* Deletes a custom classifier with the specified classifier id.
512-
* @param classifier_id The classifier id
513529
*
530+
* @param {Object} params
531+
* @param {String} params.classifier_id The classifier id
532+
* @param {Function} callback
533+
* @returns {ReadableStream|undefined}
514534
*/
515535
VisualRecognitionV3.prototype.deleteClassifier = function(params, callback) {
516536
var parameters = {

test/test.integration-all-services.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,22 @@ describe('integration-all-services', function() {
457457
});
458458
});
459459

460-
describe('createClassifier()', function() {
461-
460+
describe('getClassifier()', function() {
461+
it('should retrieve the classifier', function(done) {
462+
var expected = { classifier_id: 'fruit_679357912',
463+
name: 'fruit',
464+
owner: 'a3a48ea7-492b-448b-87d7-9dade8bde5a9',
465+
status: 'ready',
466+
created: '2016-05-23T21:50:41.680Z',
467+
classes: [ { class: 'banana' }, { class: 'apple' } ] };
468+
visual_recognition.getClassifier({classifier_id: 'fruit_679357912'}, function(err, classifier){
469+
if (err) {
470+
return done(err);
471+
}
472+
assert.deepEqual(classifier, expected);
473+
done();
474+
});
475+
});
462476
});
463477
});
464478
});
@@ -1018,7 +1032,6 @@ describe('integration-all-services', function() {
10181032
if (err) {
10191033
return done(err);
10201034
}
1021-
console.log(res); // eslint-disable-line no-console
10221035
assert(res);
10231036
assert(res.media_type_detected, 'application/vnd.openxmlformats-officedocument.wordprocessingml.document');
10241037
assert(res.answer_units);

test/test.visual_recognition.v3.js

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('visual_recognition', function() {
1313
// Test params
1414
var service = {
1515
api_key: 'batman',
16-
url: 'http://ibm.com:80',
16+
url: 'http://ibm.com:80/visual-recognition/api',
1717
version: 'v3',
1818
version_date: '2016-05-20'
1919
};
@@ -151,7 +151,7 @@ describe('visual_recognition', function() {
151151
visual_recognition.createClassifier({positive_examples: '', negative_examples: '', name: 'foo'}, missingParameter); // positive examples must include a tag
152152
visual_recognition.createClassifier({foo_positive_examples: '', negative_examples: ''}, missingParameter); // missing name
153153
});
154-
154+
155155
it('should generate a valid payload with streams', function(done) {
156156
var params = {
157157
foo_positive_examples: fake_file,
@@ -189,6 +189,23 @@ describe('visual_recognition', function() {
189189
assert.equal(req.uri.href, service.url + foo_classifiers_path);
190190
assert.equal(req.method, 'DELETE');
191191
});
192+
193+
it('should make a DELETE request and return the result', function(done) {
194+
var scope = nock('http://ibm.com:80', {"encodedQueryParams":true})
195+
.delete('/visual-recognition/api/v3/classifiers/foo_123')
196+
.query({"api_key":"batman","version":"2016-05-20"})
197+
.reply(200, {});
198+
199+
visual_recognition.deleteClassifier({
200+
classifier_id: 'foo_123'
201+
}, function(err) {
202+
if (err) {
203+
return done(err);
204+
}
205+
assert(scope.isDone());
206+
done();
207+
});
208+
});
192209
});
193210

194211
describe('getClassifier()', function() {
@@ -206,5 +223,31 @@ describe('visual_recognition', function() {
206223
assert.equal(req.uri.href, service.url + foo_classifiers_path);
207224
assert.equal(req.method, 'GET');
208225
});
226+
227+
it('should make a GET request and return the result', function(done) {
228+
var expected = {
229+
"classifier_id":"fruit_679357912",
230+
"name":"fruit",
231+
"owner":"a3a48ea7-492b-448b-87d7-9dade8bde5a9",
232+
"status":"ready",
233+
"created":"2016-05-23T21:50:41.680Z",
234+
"classes":[{"class":"banana"},{"class":"apple"}]
235+
};
236+
var scope = nock('http://ibm.com:80', {"encodedQueryParams":true})
237+
.get('/visual-recognition/api/v3/classifiers/fruit_679357912')
238+
.query({"api_key":"batman","version":"2016-05-20"})
239+
.reply(200, expected);
240+
241+
visual_recognition.getClassifier({
242+
classifier_id: 'fruit_679357912'
243+
}, function(err, res) {
244+
if (err) {
245+
return done(err);
246+
}
247+
assert(scope.isDone());
248+
assert.deepEqual(res, expected);
249+
done();
250+
});
251+
});
209252
});
210253
});

0 commit comments

Comments
 (0)