55 * Released under the MIT License
66 */
77
8- var xml2js = require ( 'xml2js' ) ,
9- url = require ( 'url' ) ,
10- os = require ( 'os' ) ,
11- csv = require ( 'csv' ) ,
12- entities = require ( 'entities' ) ;
8+ var xml2js = require ( 'xml2js' ) ,
9+ url = require ( 'url' ) ,
10+ os = require ( 'os' ) ,
11+ csv = require ( 'csv' ) ,
12+ entities = require ( 'entities' ) ,
13+ qs = require ( 'querystring' ) ;
1314
14- var parser = new xml2js . Parser ( { explicitArray : false , mergeAttrs : true } ) ;
15+ var parser = new xml2js . Parser ( { explicitArray : false , mergeAttrs : true } ) ;
1516
1617var reNumber = / ^ [ \. \+ \- ] ? [ \d \. ] + $ / ,
17- reInvalidDec = / (?: \. \d * ) { 2 , } / ,
18- reDec = / \. / ,
19- reLineBreak = / [ \n \r ] + / g,
20- reLastBreak = / \n $ / ,
21- reProtocol = / ^ h t t p s ? : \/ \/ / i,
22- reIp = / \d + \. \d + \. \d + \. \d + / , // 127.0.0.1
18+ reInvalidDec = / (?: \. \d * ) { 2 , } / ,
19+ reDec = / \. / ,
20+ reLineBreak = / [ \n \r ] + / g,
21+ reLastBreak = / \n $ / ,
22+ reProtocol = / ^ h t t p s ? : \/ \/ / i,
23+ reIp = / \d + \. \d + \. \d + \. \d + / , // 127.0.0.1
2324
24- TAB = '\t' ,
25- NEWLINE = '\n' ;
25+ TAB = '\t' ,
26+ NEWLINE = '\n' ;
2627
2728function parseNumber ( s ) {
2829 if ( typeof s !== 'string' || ! reNumber . test ( s ) || reInvalidDec . test ( s ) ) {
@@ -34,7 +35,7 @@ function parseNumber(s) {
3435
3536function normalizeObj ( root ) {
3637 if ( typeof root === 'object' ) {
37- Object . keys ( root ) . forEach ( function ( key ) {
38+ Object . keys ( root ) . forEach ( function ( key ) {
3839 var value = root [ key ] ;
3940 if ( typeof value === 'string' ) {
4041 if ( value . length === 0 || value === '\n' ) {
@@ -62,8 +63,8 @@ function xmlToObj(xml, callback) {
6263
6364function svToObj ( delimiter , headers , sv ) {
6465 var data ,
65- start = 0 ,
66- obj = { } ;
66+ start = 0 ,
67+ obj = { } ;
6768
6869 delimiter = delimiter || ',' ;
6970
@@ -101,11 +102,11 @@ function svToObj(delimiter, headers, sv) {
101102}
102103
103104function csvParser ( data , callback ) {
104- csv . parse ( data . toString ( ) , { columns : true } , function ( err , data ) {
105+ csv . parse ( data . toString ( ) , { columns : true } , function ( err , data ) {
105106 if ( err ) {
106107 callback . bind ( this , err ) ;
107108 }
108- csv . transform ( data , function ( row ) {
109+ csv . transform ( data , function ( row ) {
109110 var key , value ;
110111 for ( key in row ) {
111112 value = row [ key ] . replace ( / < b > | < \/ b > / g, '' ) ;
@@ -155,19 +156,32 @@ function scriptToString(data) {
155156}
156157
157158// Build the RESTful API url call only
158- function dryRun ( config , path ) {
159+ function dryRun ( config , path , form ) {
159160 path = url . parse ( path , true ) ;
160161
161- return {
162- url : url . format ( {
163- protocol : config . protocol ,
164- hostname : config . hostname ,
165- port : ( config . port !== 80 && config . port !== 443 ?
166- config . port : undefined ) ,
167- pathname : path . pathname ,
168- query : path . query
169- } )
170- } ;
162+ if ( config . method == "POST" ) {
163+ return {
164+ url : url . format ( {
165+ protocol : config . protocol ,
166+ hostname : config . hostname ,
167+ port : ( config . port !== 80 && config . port !== 443 ?
168+ config . port : undefined ) ,
169+ pathname : path . pathname ,
170+ } ) ,
171+ form : qs . stringify ( form )
172+ } ;
173+ } else {
174+ return {
175+ url : url . format ( {
176+ protocol : config . protocol ,
177+ hostname : config . hostname ,
178+ port : ( config . port !== 80 && config . port !== 443 ?
179+ config . port : undefined ) ,
180+ pathname : path . pathname ,
181+ query : path . query
182+ } )
183+ } ;
184+ }
171185}
172186
173187// Normalize server config
@@ -221,8 +235,8 @@ function setQuery(map, options, query) {
221235 map . options . forEach ( function eachOpts ( opt ) {
222236 Object . keys ( opt ) . forEach ( function eachOpt ( key ) {
223237 var param = opt [ key ] ,
224- name = param . name ,
225- value = options [ name ] || options [ key ] ;
238+ name = param . name ,
239+ value = options [ name ] || options [ key ] ;
226240
227241 if ( value !== undefined && param . api ) {
228242 if ( param . array ) {
0 commit comments