@@ -12,31 +12,30 @@ module.exports = function (options) {
1212
1313 var methods = [ 'GET' , 'POST' , 'PUT' , 'DELETE' , 'PATCH' , 'HEAD' , 'OPTIONS' ]
1414
15+ code . push ( '//Import unirest libarary (http://unirest.io/java.html) \n' )
16+
1517 if ( methods . indexOf ( self . source . method . toUpperCase ( ) ) === - 1 ) {
16- return self . source . method . toUpperCase ( ) + ' method not supported by Unirest liabrary.'
18+ code . push ( util . format ( 'HttpResponse<String> response = Unirest.customMethod("%s","%s")' , self . source . method . toUpperCase ( ) , self . source . fullUrl ) )
19+ } else {
20+ code . push ( util . format ( 'HttpResponse<String> response = Unirest.%s("%s")' , self . source . method . toLowerCase ( ) , self . source . fullUrl ) )
1721 }
1822
19- code . push ( util . format ( 'HttpResponse<String> response = Unirest.%s("%s")' , self . source . method . toLowerCase ( ) , self . source . fullUrl ) )
20-
2123 // Add headers, including the cookies
2224 var headers = Object . keys ( self . source . allHeaders )
2325
2426 // construct headers
2527 if ( headers . length ) {
2628 headers . map ( function ( key ) {
27- code . push ( util . format ( '.header("%s", "%s")' , key , self . source . allHeaders [ key ] ) )
29+ code . push ( opts . indent + util . format ( '.header("%s", "%s")' , key , self . source . allHeaders [ key ] ) )
2830 } )
2931 }
3032
31- // construct postdata
32- if ( self . source . postData ) {
33- if ( self . source . postData . text ) {
34- code . push ( util . format ( '.body(%s)' , JSON . stringify ( self . source . postData . text ) ) )
35- }
33+ if ( self . source . postData . text ) {
34+ code . push ( opts . indent + util . format ( '.body(%s)' , JSON . stringify ( self . source . postData . text ) ) )
3635 }
3736
38- code . push ( '.asString();' )
39- return code . join ( '\n' + opts . indent )
37+ code . push ( opts . indent + '.asString();' )
38+ return code . join ( '\n' )
4039}
4140
4241module . exports . info = {
0 commit comments