Skip to content

Commit 6a0e4bd

Browse files
committed
implement API change with CodeBuilder push + unshift
1 parent 331e83e commit 6a0e4bd

17 files changed

Lines changed: 108 additions & 112 deletions

File tree

src/targets/go/native.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,24 @@ module.exports = function (source, options) {
6464
if (opts.timeout > 0) {
6565
client = 'client'
6666
code.push(1, 'client := http.Client{')
67-
.push(2, util.format('Timeout: time.Duration(%s * time.Second),', opts.timeout))
67+
.push(2, 'Timeout: time.Duration(%s * time.Second),', opts.timeout)
6868
.push(1, '}')
6969
.blank()
7070
} else {
7171
client = 'http.DefaultClient'
7272
}
7373

74-
code.push(1, util.format('url := "%s"', source.fullUrl))
74+
code.push(1, 'url := "%s"', source.fullUrl)
7575
.blank()
7676

7777
// If we have body content or not create the var and reader or nil
7878
if (source.postData.text) {
79-
code.push(1, util.format('payload := strings.NewReader(%s)', JSON.stringify(source.postData.text)))
79+
code.push(1, 'payload := strings.NewReader(%s)', JSON.stringify(source.postData.text))
8080
.blank()
81-
.push(1, util.format('req, %s := http.NewRequest("%s", url, payload)', errorPlaceholder, source.method))
81+
.push(1, 'req, %s := http.NewRequest("%s", url, payload)', errorPlaceholder, source.method)
8282
.blank()
8383
} else {
84-
code.push(1, util.format('req, %s := http.NewRequest("%s", url, nil)', errorPlaceholder, source.method))
84+
code.push(1, 'req, %s := http.NewRequest("%s", url, nil)', errorPlaceholder, source.method)
8585
.blank()
8686
}
8787

@@ -90,20 +90,20 @@ module.exports = function (source, options) {
9090
// Add headers
9191
if (Object.keys(source.allHeaders).length) {
9292
Object.keys(source.allHeaders).map(function (key) {
93-
code.push(1, util.format('req.Header.Add("%s", "%s")', key, source.allHeaders[key]))
93+
code.push(1, 'req.Header.Add("%s", "%s")', key, source.allHeaders[key])
9494
})
9595
code.blank()
9696
}
9797

9898
// Make request
99-
code.push(1, util.format('res, %s := %s.Do(req)', errorPlaceholder, client))
99+
code.push(1, 'res, %s := %s.Do(req)', errorPlaceholder, client)
100100
errorCheck()
101101

102102
// Get Body
103103
if (opts.printBody) {
104104
code.blank()
105105
.push(1, 'defer res.Body.Close()')
106-
.push(1, util.format('body, %s := ioutil.ReadAll(res.Body)', errorPlaceholder))
106+
.push(1, 'body, %s := ioutil.ReadAll(res.Body)', errorPlaceholder)
107107
errorCheck()
108108
}
109109

src/targets/java/unirest.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ module.exports = function (source, options) {
2323
var methods = [ 'GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS' ]
2424

2525
if (methods.indexOf(source.method.toUpperCase()) === -1) {
26-
code.push(util.format('HttpResponse<String> response = Unirest.customMethod("%s","%s")', source.method.toUpperCase(), source.fullUrl))
26+
code.push('HttpResponse<String> response = Unirest.customMethod("%s","%s")', source.method.toUpperCase(), source.fullUrl)
2727
} else {
28-
code.push(util.format('HttpResponse<String> response = Unirest.%s("%s")', source.method.toLowerCase(), source.fullUrl))
28+
code.push('HttpResponse<String> response = Unirest.%s("%s")', source.method.toLowerCase(), source.fullUrl)
2929
}
3030

3131
// Add headers, including the cookies
@@ -34,12 +34,12 @@ module.exports = function (source, options) {
3434
// construct headers
3535
if (headers.length) {
3636
headers.map(function (key) {
37-
code.push(1, util.format('.header("%s", "%s")', key, source.allHeaders[key]))
37+
code.push(1, '.header("%s", "%s")', key, source.allHeaders[key])
3838
})
3939
}
4040

4141
if (source.postData.text) {
42-
code.push(1, util.format('.body(%s)', JSON.stringify(source.postData.text)))
42+
code.push(1, '.body(%s)', JSON.stringify(source.postData.text))
4343
}
4444

4545
code.push(1, '.asString();')

src/targets/javascript/jquery.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ module.exports = function (source, options) {
4242
code.push('var form = new FormData();')
4343

4444
source.postData.params.map(function (param) {
45-
code.push(util.format('form.append(%s, %s);', JSON.stringify(param.name), JSON.stringify(param.value || param.fileName || '')))
45+
code.push('form.append(%s, %s);', JSON.stringify(param.name), JSON.stringify(param.value || param.fileName || ''))
4646
})
4747

4848
settings.processData = false

src/targets/javascript/xhr.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ module.exports = function (source, options) {
2323

2424
switch (source.postData.mimeType) {
2525
case 'application/json':
26-
code.push(util.format('var data = JSON.stringify(%s);', JSON.stringify(source.postData.jsonObj, null, opts.indent)))
26+
code.push('var data = JSON.stringify(%s);', JSON.stringify(source.postData.jsonObj, null, opts.indent))
2727
.push(null)
2828
break
2929

3030
case 'multipart/form-data':
3131
code.push('var data = new FormData();')
3232

3333
source.postData.params.map(function (param) {
34-
code.push(util.format('data.append(%s, %s);', JSON.stringify(param.name), JSON.stringify(param.value || param.fileName || '')))
34+
code.push('data.append(%s, %s);', JSON.stringify(param.name), JSON.stringify(param.value || param.fileName || ''))
3535
})
3636

3737
// remove the contentType header
@@ -43,7 +43,7 @@ module.exports = function (source, options) {
4343
break
4444

4545
default:
46-
code.push(util.format('var data = %s;', JSON.stringify(source.postData.text || null)))
46+
code.push('var data = %s;', JSON.stringify(source.postData.text || null))
4747
.blank()
4848
}
4949

@@ -60,10 +60,10 @@ module.exports = function (source, options) {
6060
.push(1, '}')
6161
.push('});')
6262
.blank()
63-
.push(util.format('xhr.open(%s, %s);', JSON.stringify(source.method), JSON.stringify(source.fullUrl)))
63+
.push('xhr.open(%s, %s);', JSON.stringify(source.method), JSON.stringify(source.fullUrl))
6464

6565
Object.keys(source.allHeaders).map(function (key) {
66-
code.push(util.format('xhr.setRequestHeader(%s, %s);', JSON.stringify(key), JSON.stringify(source.allHeaders[key])))
66+
code.push('xhr.setRequestHeader(%s, %s);', JSON.stringify(key), JSON.stringify(source.allHeaders[key]))
6767
})
6868

6969
code.blank()

src/targets/node/native.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ module.exports = function (source, options) {
2828
headers: source.allHeaders
2929
}
3030

31-
code.push(util.format('var http = require("%s");', source.uriObj.protocol.replace(':', '')))
31+
code.push('var http = require("%s");', source.uriObj.protocol.replace(':', ''))
3232

3333
code.blank()
34-
.push(util.format('var options = %s;', JSON.stringify(reqOpts, null, opts.indent)))
34+
.push('var options = %s;', JSON.stringify(reqOpts, null, opts.indent))
3535
.blank()
3636
.push('var req = http.request(options, function (res) {')
3737
.push(1, 'var chunks = [];')
@@ -51,23 +51,23 @@ module.exports = function (source, options) {
5151
case 'application/x-www-form-urlencoded':
5252
if (source.postData.paramsObj) {
5353
code.unshift('var qs = require("querystring");')
54-
code.push(util.format('req.write(qs.stringify(%s));', util.inspect(source.postData.paramsObj, {
54+
code.push('req.write(qs.stringify(%s));', util.inspect(source.postData.paramsObj, {
5555
depth: null
56-
})))
56+
}))
5757
}
5858
break
5959

6060
case 'application/json':
6161
if (source.postData.jsonObj) {
62-
code.push(util.format('req.write(JSON.stringify(%s));', util.inspect(source.postData.jsonObj, {
62+
code.push('req.write(JSON.stringify(%s));', util.inspect(source.postData.jsonObj, {
6363
depth: null
64-
})))
64+
}))
6565
}
6666
break
6767

6868
default:
6969
if (source.postData.text) {
70-
code.push(util.format('req.write(%s);', JSON.stringify(source.postData.text, null, opts.indent)))
70+
code.push('req.write(%s);', JSON.stringify(source.postData.text, null, opts.indent))
7171
}
7272
}
7373

src/targets/node/request.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ module.exports = function (source, options) {
9292
var url = source.url
9393

9494
source.cookies.map(function (cookie) {
95-
code.push(util.format('jar.setCookie(request.cookie("%s=%s"), "%s");', encodeURIComponent(cookie.name), encodeURIComponent(cookie.value), url))
95+
code.push('jar.setCookie(request.cookie("%s=%s"), "%s");', encodeURIComponent(cookie.name), encodeURIComponent(cookie.value), url)
9696
})
9797
code.blank()
9898
}
@@ -101,7 +101,7 @@ module.exports = function (source, options) {
101101
code.unshift('var fs = require("fs");')
102102
}
103103

104-
code.push(util.format('request(%s, %s', JSON.stringify(reqOpts, null, opts.indent), 'function (error, response, body) {'))
104+
code.push('request(%s, %s', JSON.stringify(reqOpts, null, opts.indent), 'function (error, response, body) {')
105105
.push(1, 'if (error) throw new Error(error);')
106106
.blank()
107107
.push(1, 'console.log(body);')

src/targets/node/unirest.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,41 +23,41 @@ module.exports = function (source, options) {
2323

2424
code.push('var unirest = require("unirest");')
2525
.blank()
26-
.push(util.format('var req = unirest("%s", "%s");', source.method, source.url))
26+
.push('var req = unirest("%s", "%s");', source.method, source.url)
2727
.blank()
2828

2929
if (source.cookies.length) {
3030
code.push('var CookieJar = unirest.jar();')
3131

3232
source.cookies.forEach(function (cookie) {
33-
code.push(util.format('CookieJar.add("%s=%s","%s");', encodeURIComponent(cookie.name), encodeURIComponent(cookie.value), source.url))
33+
code.push('CookieJar.add("%s=%s","%s");', encodeURIComponent(cookie.name), encodeURIComponent(cookie.value), source.url)
3434
})
3535

3636
code.push('req.jar(CookieJar);')
3737
.blank()
3838
}
3939

4040
if (Object.keys(source.queryObj).length) {
41-
code.push(util.format('req.query(%s);', JSON.stringify(source.queryObj, null, opts.indent)))
41+
code.push('req.query(%s);', JSON.stringify(source.queryObj, null, opts.indent))
4242
.blank()
4343
}
4444

4545
if (Object.keys(source.headersObj).length) {
46-
code.push(util.format('req.headers(%s);', JSON.stringify(source.headersObj, null, opts.indent)))
46+
code.push('req.headers(%s);', JSON.stringify(source.headersObj, null, opts.indent))
4747
.blank()
4848
}
4949

5050
switch (source.postData.mimeType) {
5151
case 'application/x-www-form-urlencoded':
5252
if (source.postData.paramsObj) {
53-
code.push(util.format('req.form(%s);', JSON.stringify(source.postData.paramsObj, null, opts.indent)))
53+
code.push('req.form(%s);', JSON.stringify(source.postData.paramsObj, null, opts.indent))
5454
}
5555
break
5656

5757
case 'application/json':
5858
if (source.postData.jsonObj) {
5959
code.push('req.type("json");')
60-
.push(util.format('req.send(%s);', JSON.stringify(source.postData.jsonObj, null, opts.indent)))
60+
.push('req.send(%s);', JSON.stringify(source.postData.jsonObj, null, opts.indent))
6161
}
6262
break
6363

@@ -84,12 +84,12 @@ module.exports = function (source, options) {
8484
}
8585
})
8686

87-
code.push(util.format('req.multipart(%s);', JSON.stringify(multipart, null, opts.indent)))
87+
code.push('req.multipart(%s);', JSON.stringify(multipart, null, opts.indent))
8888
break
8989

9090
default:
9191
if (source.postData.text) {
92-
code.push(opts.indent + util.format('req.send(%s);', JSON.stringify(source.postData.text, null, opts.indent)))
92+
code.push(opts.indent + 'req.send(%s);', JSON.stringify(source.postData.text, null, opts.indent))
9393
}
9494
}
9595

src/targets/ocaml/cohttp.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module.exports = function (source, options) {
2525
.push('open Cohttp')
2626
.push('open Lwt')
2727
.blank()
28-
.push(util.format('let uri = Uri.of_string "%s" in', source.fullUrl))
28+
.push('let uri = Uri.of_string "%s" in', source.fullUrl)
2929

3030
// Add headers, including the cookies
3131
var headers = Object.keys(source.allHeaders)
@@ -34,7 +34,7 @@ module.exports = function (source, options) {
3434
code.push('let headers = Header.init ()')
3535

3636
headers.map(function (key) {
37-
code.push(1, util.format('|> fun h -> Header.add h "%s" "%s"', key, source.allHeaders[key]))
37+
code.push(1, '|> fun h -> Header.add h "%s" "%s"', key, source.allHeaders[key])
3838
})
3939

4040
code.push('in')
@@ -43,17 +43,17 @@ module.exports = function (source, options) {
4343
// Add body
4444
if (source.postData.text) {
4545
// Just text
46-
code.push(util.format('let body = Cohttp_lwt_body.of_string %s in', JSON.stringify(source.postData.text)))
46+
code.push('let body = Cohttp_lwt_body.of_string %s in', JSON.stringify(source.postData.text))
4747
}
4848

4949
// Do the request
5050
code.blank()
5151

52-
code.push(util.format('Client.call %s%s%s uri',
52+
code.push('Client.call %s%s%s uri',
5353
headers.length ? '~headers ' : '',
5454
source.postData.text ? '~body ' : '',
5555
(methods.indexOf(source.method.toLowerCase()) >= 0 ? ('`' + source.method.toUpperCase()) : '(Code.method_of_string "' + source.method + '")')
56-
))
56+
)
5757

5858
// Catch result
5959
code.push('>>= fun (res, body_stream) ->')

src/targets/php/http1.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,45 +30,45 @@ module.exports = function (source, options) {
3030
}
3131

3232
if (!~helpers.methods.indexOf(source.method.toUpperCase())) {
33-
code.push(util.format('HttpRequest::methodRegister(\'%s\');', source.method))
33+
code.push('HttpRequest::methodRegister(\'%s\');', source.method)
3434
}
3535

3636
code.push('$request = new HttpRequest();')
37-
.push(util.format('$request->setUrl(%s);', helpers.convert(source.url)))
37+
.push('$request->setUrl(%s);', helpers.convert(source.url))
3838

3939
if (~helpers.methods.indexOf(source.method.toUpperCase())) {
40-
code.push(util.format('$request->setMethod(HTTP_METH_%s);', source.method.toUpperCase()))
40+
code.push('$request->setMethod(HTTP_METH_%s);', source.method.toUpperCase())
4141
} else {
42-
code.push(util.format('$request->setMethod(HttpRequest::HTTP_METH_%s);', source.method.toUpperCase()))
42+
code.push('$request->setMethod(HttpRequest::HTTP_METH_%s);', source.method.toUpperCase())
4343
}
4444

4545
code.blank()
4646

4747
if (Object.keys(source.queryObj).length) {
48-
code.push(util.format('$request->setQueryData(%s);', helpers.convert(source.queryObj, opts.indent)))
48+
code.push('$request->setQueryData(%s);', helpers.convert(source.queryObj, opts.indent))
4949
.blank()
5050
}
5151

5252
if (Object.keys(source.headersObj).length) {
53-
code.push(util.format('$request->setHeaders(%s);', helpers.convert(source.headersObj, opts.indent)))
53+
code.push('$request->setHeaders(%s);', helpers.convert(source.headersObj, opts.indent))
5454
.blank()
5555
}
5656

5757
if (Object.keys(source.cookiesObj).length) {
58-
code.push(util.format('$request->setCookies(%s);', helpers.convert(source.cookiesObj, opts.indent)))
58+
code.push('$request->setCookies(%s);', helpers.convert(source.cookiesObj, opts.indent))
5959
.blank()
6060
}
6161

6262
switch (source.postData.mimeType) {
6363
case 'application/x-www-form-urlencoded':
64-
code.push(util.format('$request->setContentType(%s);', helpers.convert(source.postData.mimeType)))
65-
.push(util.format('$request->setPostFields(%s);', helpers.convert(source.postData.paramsObj, opts.indent)))
64+
code.push('$request->setContentType(%s);', helpers.convert(source.postData.mimeType))
65+
.push('$request->setPostFields(%s);', helpers.convert(source.postData.paramsObj, opts.indent))
6666
.blank()
6767
break
6868

6969
default:
7070
if (source.postData.text) {
71-
code.push(util.format('$request->setBody(%s);', helpers.convert(source.postData.text)))
71+
code.push('$request->setBody(%s);', helpers.convert(source.postData.text))
7272
.blank()
7373
}
7474
}

0 commit comments

Comments
 (0)