@@ -21,9 +21,9 @@ module.exports = function (source, options) {
2121 var code = new CodeBuilder ( opts . indent )
2222
2323 code . push ( 'var unirest = require("unirest");' )
24- . blank ( )
25- . push ( 'var req = unirest("%s", "%s");' , source . method , source . url )
26- . blank ( )
24+ . blank ( )
25+ . push ( 'var req = unirest("%s", "%s");' , source . method , source . url )
26+ . blank ( )
2727
2828 if ( source . cookies . length ) {
2929 code . push ( 'var CookieJar = unirest.jar();' )
@@ -33,17 +33,17 @@ module.exports = function (source, options) {
3333 } )
3434
3535 code . push ( 'req.jar(CookieJar);' )
36- . blank ( )
36+ . blank ( )
3737 }
3838
3939 if ( Object . keys ( source . queryObj ) . length ) {
4040 code . push ( 'req.query(%s);' , JSON . stringify ( source . queryObj , null , opts . indent ) )
41- . blank ( )
41+ . blank ( )
4242 }
4343
4444 if ( Object . keys ( source . headersObj ) . length ) {
4545 code . push ( 'req.headers(%s);' , JSON . stringify ( source . headersObj , null , opts . indent ) )
46- . blank ( )
46+ . blank ( )
4747 }
4848
4949 switch ( source . postData . mimeType ) {
@@ -56,14 +56,15 @@ module.exports = function (source, options) {
5656 case 'application/json' :
5757 if ( source . postData . jsonObj ) {
5858 code . push ( 'req.type("json");' )
59- . push ( 'req.send(%s);' , JSON . stringify ( source . postData . jsonObj , null , opts . indent ) )
59+ . push ( 'req.send(%s);' , JSON . stringify ( source . postData . jsonObj , null , opts . indent ) )
6060 }
6161 break
6262
6363 case 'multipart/form-data' :
6464 var multipart = [ ]
6565
6666 source . postData . params . forEach ( function ( param ) {
67+ console . log ( 'unirest.js 67' , param )
6768 var part = { }
6869
6970 if ( param . fileName && ! param . value ) {
@@ -82,7 +83,7 @@ module.exports = function (source, options) {
8283 multipart . push ( part )
8384 }
8485 } )
85- console . log ( )
86+ console . log ( 'unirest.js 86' , multipart )
8687 code . push ( 'req.multipart(%s);' , JSON . stringify ( multipart , null , opts . indent ) )
8788 break
8889
@@ -97,12 +98,12 @@ module.exports = function (source, options) {
9798 }
9899
99100 code . blank ( )
100- . push ( 'req.end(function (res) {' )
101- . push ( 1 , 'if (res.error) throw new Error(res.error);' )
102- . blank ( )
103- . push ( 1 , 'console.log(res.body);' )
104- . push ( '});' )
105- . blank ( )
101+ . push ( 'req.end(function (res) {' )
102+ . push ( 1 , 'if (res.error) throw new Error(res.error);' )
103+ . blank ( )
104+ . push ( 1 , 'console.log(res.body);' )
105+ . push ( '});' )
106+ . blank ( )
106107
107108 return code . join ( ) . replace ( / " f s \. c r e a t e R e a d S t r e a m \( \\ " ( .+ ) \\ " \) " / , 'fs.createReadStream("$1")' )
108109}
0 commit comments