@@ -81,14 +81,13 @@ function AlchemyVision(options) {
8181/**
8282 * Extracts images from a URL or html
8383 */
84- AlchemyVision . prototype . imageLinks = function ( _params , callback ) {
84+ AlchemyVision . prototype . getImageLinks = function ( _params , callback ) {
8585 var params = _params || { } ;
8686 var accepted_formats = Object . keys ( endpoints [ 'image_link' ] ) ;
8787 var format = helper . getFormat ( params , accepted_formats ) ;
8888
8989 if ( format === null ) {
90- callback ( new Error ( 'Missing required parameters: ' +
91- accepted_formats . join ( ', ' ) + ' needs to be specified' ) ) ;
90+ callback ( new Error ( 'Missing required parameters: ' + accepted_formats . join ( ', ' ) + ' needs to be specified' ) ) ;
9291 return ;
9392 }
9493
@@ -97,7 +96,7 @@ AlchemyVision.prototype.imageLinks = function(_params, callback ) {
9796 url : endpoints [ 'image_link' ] [ format ] ,
9897 method : 'POST' ,
9998 json : true ,
100- qs : extend ( { outputMode : 'json' } , params ) // change default output to json
99+ qs : extend ( { } , params , { outputMode : 'json' } ) // change default output to json
101100 } ,
102101 defaultOptions : this . _options
103102 } ;
@@ -109,44 +108,46 @@ AlchemyVision.prototype.imageLinks = function(_params, callback ) {
109108 * Tags image with keywords
110109 */
111110AlchemyVision . prototype . getImageKeywords = function ( _params , callback ) {
112- var params = _params || { } ;
111+ var params = extend ( { } , _params ) ;
113112 var accepted_formats = Object . keys ( endpoints [ 'image_keywords' ] ) ;
114113 var format = helper . getFormat ( params , accepted_formats ) ;
115- var image = null ;
114+
116115 if ( format === null ) {
117- callback ( new Error ( 'Missing required parameters: ' +
118- accepted_formats . join ( ', ' ) + ' needs to be specified' ) ) ;
116+ callback ( new Error ( 'Missing required parameters: ' + accepted_formats . join ( ', ' ) + ' needs to be specified' ) ) ;
119117 return ;
120118 }
121119
120+ var parameters = {
121+ options : {
122+ url : endpoints [ 'image_keywords' ] [ format ] ,
123+ method : 'POST' ,
124+ json : true ,
125+ qs : { outputMode : 'json' } // change default output to json
126+ } ,
127+ defaultOptions : this . _options
128+ } ;
122129
123130 if ( typeof ( params . image ) !== 'undefined' ) {
131+
124132 // check if image is stream or string
125- if ( typeof ( params . image ) !== 'string' && ! isStream ( params . image ) ) {
133+ if ( ( typeof ( params . image ) !== 'string' ) && ! isStream ( params . image ) ) {
126134 callback ( new Error ( 'Invalid arguments: image needs to be a stream or base64' ) ) ;
127135 return ;
128136 }
129137
130138 if ( isStream ( params . image ) ) {
131139 params . imagePostMode = 'raw' ;
132- image = params . image ;
133- delete params . image ;
140+ // handle raw images
141+ parameters . options . body = params . image ;
142+
134143 } else {
135144 params . imagePostMode = 'not-raw' ;
145+ parameters . options . formData = params ;
136146 }
147+ } else {
148+ parameters . options . formData = params ;
137149 }
138150
139- var parameters = {
140- options : {
141- url : endpoints [ 'image_links' ] [ format ] ,
142- method : 'POST' ,
143- json : true ,
144- body : image ,
145- qs : extend ( { outputMode : 'json' } , params ) // change default output to json
146- } ,
147- defaultOptions : this . _options
148- } ;
149-
150151 return requestFactory ( parameters , errorFormatter ( callback ) ) ;
151152} ;
152153
@@ -156,7 +157,7 @@ AlchemyVision.prototype.getImageKeywords = function(_params, callback) {
156157AlchemyVision . prototype . recognizeFaces = function ( _params , callback ) {
157158 var params = _params || { } ;
158159
159- if ( typeof ( params . image ) !== 'string' )
160+ if ( params . image && typeof ( params . image ) !== 'string' )
160161 params . imagePostMode = 'raw' ;
161162
162163 return createRequest ( 'image_recognition' ) . call ( this , params , callback ) ;
0 commit comments