Skip to content

Commit 515fca1

Browse files
alchemy vision - get links is now supported #72
1 parent 2299d05 commit 515fca1

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

lib/alchemy_endpoints.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"html" : "/html/HTMLGetCombinedData"
8585
},
8686

87-
"image": {
87+
"image_link": {
8888
"url" : "/url/URLGetImage",
8989
"html" : "/html/HTMLGetImage"
9090
},
@@ -94,7 +94,7 @@
9494
"image" : "/image/ImageGetRankedImageKeywords"
9595
},
9696

97-
"image_face_tag": {
97+
"image_recognition": {
9898
"url" : "/url/URLGetRankedImageFaceTags",
9999
"image" : "/image/ImageGetRankedImageFaceTags"
100100
}

lib/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ var watson = {};
113113
'user_modeling',
114114

115115
// alchemy
116-
'alchemy_language',
117-
'alchemy_vision'
116+
'alchemy_language'
117+
//'alchemy_vision'
118118

119119
].forEach(function(api) {
120120
watson[api] = createServiceAPI(api);

services/alchemy_language/v1.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,18 @@ var endpoints = require('../../lib/alchemy_endpoints.json');
2222
var helper = require('../../lib/helper');
2323

2424
var errorFormatter = function(cb) {
25-
return function(err, result) {
25+
return function(err, result, response) {
2626
if (err) {
2727
cb(err, result);
2828
}
2929
else {
3030
if (result.status === 'OK')
3131
cb(err,result);
3232
else
33-
cb({error: result.statusInfo, code:400 }, null);
33+
cb({
34+
error: result.statusInfo || response['headers']['x-alchemyapi-error-msg'],
35+
code: 400
36+
}, null);
3437
}
3538
};
3639
};

services/alchemy_vision/v1.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,15 @@ function createRequest(method) {
5454
return;
5555
}
5656

57-
var imageOptions = {};
58-
59-
if (typeof(_params.image) !== 'string') {
60-
params.imagePostMode = 'raw';
61-
imageOptions.formData = { attachments: [_params.image] };
62-
} else {
63-
imageOptions.form = pick(params,['image']);
64-
}
65-
66-
var parameters = extend({
57+
var parameters = {
6758
options: {
6859
url: endpoints[method][format],
6960
method: 'POST',
7061
json: true,
71-
qs: extend({outputMode: 'json'}, omit(params,['image'])) // change default output to json
62+
qs: extend({outputMode: 'json'}, params) // change default output to json
7263
},
7364
defaultOptions: this._options
74-
}, imageOptions);
65+
};
7566

7667
return requestFactory(parameters, errorFormatter(callback));
7768
};
@@ -89,14 +80,21 @@ function AlchemyVision(options) {
8980
/**
9081
* Extracts images from a URL.
9182
*/
92-
AlchemyVision.prototype.imageLinks = createRequest('image');
83+
AlchemyVision.prototype.imageLinks = createRequest('image_link');
9384

9485
/**
9586
* Tags image with keywords
9687
*/
9788
AlchemyVision.prototype.imageTags = function(_params, callback) {
9889
var params = _params || {};
9990

91+
if (typeof(params.image) !== 'undefined' && typeof(params.image) !== 'string') {
92+
callback(new Error('Invalid arguments: image needs to be a filename or base64 image'));
93+
return;
94+
}
95+
96+
if (typeof(params.image) !== 'string')
97+
params.imagePostMode = 'raw';
10098

10199
return createRequest('image_keywords').call(this, params, callback);
102100
};
@@ -110,7 +108,7 @@ AlchemyVision.prototype.imageFaces = function(_params, callback) {
110108
if (typeof(params.image) !== 'string')
111109
params.imagePostMode = 'raw';
112110

113-
return createRequest('image_face_tag').call(this, params, callback);
111+
return createRequest('image_recognition').call(this, params, callback);
114112
};
115113

116114
module.exports = AlchemyVision;

0 commit comments

Comments
 (0)