Skip to content

Commit 14b700b

Browse files
committed
Merge pull request Kong#26 from shashiranjan84/master
added custom methods support
2 parents 9460739 + 164c0c6 commit 14b700b

12 files changed

Lines changed: 31 additions & 12 deletions

src/targets/java/unirest.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

4241
module.exports.info = {

test/fixtures/available-targets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
"clients": [
125125
{
126126
"key": "unirest",
127-
"title": "JAVA",
127+
"title": "Unirest",
128128
"link": "http://unirest.io/java.html",
129129
"description": "Unirest Java interface"
130130
}

test/fixtures/output/java/unirest/application-form-encoded.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//Import unirest libarary (http://unirest.io/java.html)
2+
13
HttpResponse<String> response = Unirest.post("http://mockbin.com/har")
24
.header("content-type", "application/x-www-form-urlencoded")
35
.body("foo=bar&hello=world")

test/fixtures/output/java/unirest/application-json.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//Import unirest libarary (http://unirest.io/java.html)
2+
13
HttpResponse<String> response = Unirest.post("http://mockbin.com/har")
24
.header("content-type", "application/json")
35
.body("{\"number\": 1, \"string\": \"f\\\"oo\", \"arr\": [1, 2, 3], \"nested\": {\"a\": \"b\"}, \"arr_mix\": [1, \"a\", {\"arr_mix_nested\": {}}] }")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//Import unirest libarary (http://unirest.io/java.html)
2+
13
HttpResponse<String> response = Unirest.post("http://mockbin.com/har")
24
.header("cookie", "foo=bar; bar=baz")
35
.asString();

test/fixtures/output/java/unirest/full.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//Import unirest libarary (http://unirest.io/java.html)
2+
13
HttpResponse<String> response = Unirest.post("http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value")
24
.header("cookie", "foo=bar; bar=baz")
35
.header("accept", "application/json")

test/fixtures/output/java/unirest/headers.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//Import unirest libarary (http://unirest.io/java.html)
2+
13
HttpResponse<String> response = Unirest.get("http://mockbin.com/har")
24
.header("accept", "application/json")
35
.header("x-foo", "Bar")

test/fixtures/output/java/unirest/multipart-data.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//Import unirest libarary (http://unirest.io/java.html)
2+
13
HttpResponse<String> response = Unirest.post("http://mockbin.com/har")
24
.header("content-type", "multipart/form-data; boundary=---011000010111000001101001")
35
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001--")

test/fixtures/output/java/unirest/multipart-file.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//Import unirest libarary (http://unirest.io/java.html)
2+
13
HttpResponse<String> response = Unirest.post("http://mockbin.com/har")
24
.header("content-type", "multipart/form-data; boundary=---011000010111000001101001")
35
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--")

test/fixtures/output/java/unirest/multipart-form-data.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//Import unirest libarary (http://unirest.io/java.html)
2+
13
HttpResponse<String> response = Unirest.post("http://mockbin.com/har")
24
.header("content-type", "multipart/form-data; boundary=---011000010111000001101001")
35
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--")

0 commit comments

Comments
 (0)