5
5
* Released under the MIT License
6
6
*/
7
7
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' ) ;
13
14
14
- var parser = new xml2js . Parser ( { explicitArray : false , mergeAttrs : true } ) ;
15
+ var parser = new xml2js . Parser ( { explicitArray : false , mergeAttrs : true } ) ;
15
16
16
17
var 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
23
24
24
- TAB = '\t' ,
25
- NEWLINE = '\n' ;
25
+ TAB = '\t' ,
26
+ NEWLINE = '\n' ;
26
27
27
28
function parseNumber ( s ) {
28
29
if ( typeof s !== 'string' || ! reNumber . test ( s ) || reInvalidDec . test ( s ) ) {
@@ -34,7 +35,7 @@ function parseNumber(s) {
34
35
35
36
function normalizeObj ( root ) {
36
37
if ( typeof root === 'object' ) {
37
- Object . keys ( root ) . forEach ( function ( key ) {
38
+ Object . keys ( root ) . forEach ( function ( key ) {
38
39
var value = root [ key ] ;
39
40
if ( typeof value === 'string' ) {
40
41
if ( value . length === 0 || value === '\n' ) {
@@ -62,8 +63,8 @@ function xmlToObj(xml, callback) {
62
63
63
64
function svToObj ( delimiter , headers , sv ) {
64
65
var data ,
65
- start = 0 ,
66
- obj = { } ;
66
+ start = 0 ,
67
+ obj = { } ;
67
68
68
69
delimiter = delimiter || ',' ;
69
70
@@ -101,11 +102,11 @@ function svToObj(delimiter, headers, sv) {
101
102
}
102
103
103
104
function csvParser ( data , callback ) {
104
- csv . parse ( data . toString ( ) , { columns : true } , function ( err , data ) {
105
+ csv . parse ( data . toString ( ) , { columns : true } , function ( err , data ) {
105
106
if ( err ) {
106
107
callback . bind ( this , err ) ;
107
108
}
108
- csv . transform ( data , function ( row ) {
109
+ csv . transform ( data , function ( row ) {
109
110
var key , value ;
110
111
for ( key in row ) {
111
112
value = row [ key ] . replace ( / < b > | < \/ b > / g, '' ) ;
@@ -155,19 +156,32 @@ function scriptToString(data) {
155
156
}
156
157
157
158
// Build the RESTful API url call only
158
- function dryRun ( config , path ) {
159
+ function dryRun ( config , path , form ) {
159
160
path = url . parse ( path , true ) ;
160
161
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
+ }
171
185
}
172
186
173
187
// Normalize server config
@@ -221,8 +235,8 @@ function setQuery(map, options, query) {
221
235
map . options . forEach ( function eachOpts ( opt ) {
222
236
Object . keys ( opt ) . forEach ( function eachOpt ( key ) {
223
237
var param = opt [ key ] ,
224
- name = param . name ,
225
- value = options [ name ] || options [ key ] ;
238
+ name = param . name ,
239
+ value = options [ name ] || options [ key ] ;
226
240
227
241
if ( value !== undefined && param . api ) {
228
242
if ( param . array ) {
0 commit comments