1919var extend = require ( 'extend' ) ;
2020var requestFactory = require ( '../../lib/requestwrapper' ) ;
2121var isStream = require ( 'isstream' ) ;
22+ var pick = require ( 'object.pick' ) ;
23+ var omit = require ( 'object.omit' ) ;
2224
2325function DocumentConversion ( options ) {
2426 // Default URL
@@ -109,7 +111,6 @@ DocumentConversion.prototype.getBatch = function(params, callback) {
109111 options : {
110112 method : 'GET' ,
111113 url : '/v1/batches/{batch_id}' ,
112- qs : params ,
113114 path : params ,
114115 json : true
115116 } ,
@@ -126,23 +127,15 @@ DocumentConversion.prototype.getBatch = function(params, callback) {
126127 *
127128 */
128129DocumentConversion . prototype . updateBatch = function ( params , callback ) {
129-
130- if ( ! params . batch_id ) {
131- callback ( new Error ( 'batch_id is required' ) ) ;
132- return ;
133- }
134-
135- var id = params . batch_id ;
136- var pcopy = extend ( { } , params ) ;
137- delete pcopy . batch_id ;
138-
139130 var parameters = {
140131 options : {
141132 method : 'PUT' ,
142- url : '/v1/batches/' + id ,
143- body : pcopy ,
133+ url : '/v1/batches/{batch_id}' ,
134+ body : omit ( params , [ 'batch_id' ] ) ,
135+ path : pick ( params , [ 'batch_id' ] ) ,
144136 json : true
145137 } ,
138+ requiredParams :[ 'batch_id' ] ,
146139 defaultOptions : this . _options
147140 } ;
148141 return requestFactory ( parameters , callback ) ;
@@ -154,19 +147,15 @@ DocumentConversion.prototype.updateBatch = function(params, callback) {
154147 * @param {String } batch_id the batch identifier
155148 */
156149DocumentConversion . prototype . getBatchDocuments = function ( params , callback ) {
157-
158- if ( ! params . batch_id ) {
159- callback ( new Error ( 'batch_id is required' ) ) ;
160- return ;
161- }
162-
163150 var parameters = {
164151 options : {
165152 method : 'GET' ,
166- url : '/v1/batches/' + params . batch_id + '/documents' ,
167- qs : params ,
153+ url : '/v1/batches/{batch_id}/documents' ,
154+ qs : omit ( params , [ 'batch_id' ] ) ,
155+ path : pick ( params , [ 'batch_id' ] ) ,
168156 json : true
169157 } ,
158+ requiredParams : [ 'batch_id' ] ,
170159 defaultOptions : this . _options
171160 } ;
172161 return requestFactory ( parameters , callback ) ;
@@ -195,9 +184,11 @@ function fixupContentType(params) {
195184 */
196185DocumentConversion . prototype . convert = function ( params , callback ) {
197186 params = params || { } ;
198-
199187 if ( ! params . conversion_target || ! DocumentConversion . prototype . conversion_target [ params . conversion_target ] ) {
200- callback ( new Error ( 'Missing required parameter: params.conversion_target' ) ) ;
188+ var keys = Object . keys ( DocumentConversion . prototype . conversion_target ) ;
189+ var values = keys . map ( function ( v ) { return DocumentConversion . prototype . conversion_target [ v ] ; } ) ;
190+
191+ callback ( new Error ( 'Missing required parameter: conversion_target. Possible values are: ' + values . join ( ', ' ) ) ) ;
201192 return ;
202193 }
203194
@@ -211,18 +202,23 @@ DocumentConversion.prototype.convert = function(params, callback) {
211202 return ;
212203 }
213204
214- fixupContentType ( params ) ;
215-
216205 var parameters = {
217206 options : {
218207 method : 'POST' ,
219208 url : '/v1/convert_document' ,
220- formData : params ,
221209 json : true
222210 } ,
223211 defaultOptions : this . _options
224212 } ;
225213
214+ // send the parameters in the body or as formData depending on the request
215+ if ( params . file ) {
216+ fixupContentType ( params ) ;
217+ parameters . options . formData = params ;
218+ } else {
219+ parameters . options . body = params ;
220+ }
221+
226222 return requestFactory ( parameters , callback ) ;
227223} ;
228224
@@ -297,7 +293,8 @@ DocumentConversion.prototype.getDocument = function(params, callback) {
297293 options : {
298294 method : 'GET' ,
299295 url : '/v1/documents/{id}' ,
300- json : true
296+ json : true ,
297+ path : params
301298 } ,
302299 requiredParams :[ 'id' ] ,
303300 defaultOptions : this . _options
0 commit comments