|
1 | | -'use strict'; |
| 1 | +'use strict' |
2 | 2 |
|
3 | | -var util = require('util'); |
| 3 | +var util = require('util') |
4 | 4 |
|
5 | | -module.exports = function(options) { |
6 | | - var self = this; |
| 5 | +module.exports = function (options) { |
| 6 | + var self = this |
7 | 7 | var opts = util._extend({ |
8 | | - indent : ' ' |
9 | | - }, options); |
| 8 | + indent: ' ' |
| 9 | + }, options) |
10 | 10 |
|
11 | | - var code = []; |
| 11 | + var code = [] |
12 | 12 |
|
13 | | - var methods = [ "GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS" ]; |
| 13 | + var methods = [ 'GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS' ] |
14 | 14 |
|
15 | | - if (methods.indexOf(self.source.method.toUpperCase()) == -1) { |
16 | | - return self.source.method.toUpperCase() + " method not supported by Unirest liabrary."; |
| 15 | + if (methods.indexOf(self.source.method.toUpperCase()) === -1) { |
| 16 | + return self.source.method.toUpperCase() + ' method not supported by Unirest liabrary.' |
17 | 17 | } |
18 | 18 |
|
19 | | - code.push(util.format('HttpResponse<String> response = Unirest.%s("%s")', self.source.method.toLowerCase(), self.source.fullUrl)); |
| 19 | + code.push(util.format('HttpResponse<String> response = Unirest.%s("%s")', self.source.method.toLowerCase(), self.source.fullUrl)) |
20 | 20 |
|
21 | 21 | // Add headers, including the cookies |
22 | | - var headers = Object.keys(self.source.allHeaders); |
| 22 | + var headers = Object.keys(self.source.allHeaders) |
23 | 23 |
|
24 | 24 | // construct headers |
25 | 25 | if (headers.length) { |
26 | | - headers.map(function(key) { |
27 | | - code.push(util.format('.header("%s", "%s")', key, self.source.allHeaders[key])); |
28 | | - }); |
| 26 | + headers.map(function (key) { |
| 27 | + code.push(util.format('.header("%s", "%s")', key, self.source.allHeaders[key])) |
| 28 | + }) |
29 | 29 | } |
30 | 30 |
|
31 | 31 | // construct postdata |
32 | 32 | if (self.source.postData) { |
33 | 33 | if (self.source.postData.text) { |
34 | | - code.push(util.format('.body(%s)', JSON.stringify(self.source.postData.text))); |
| 34 | + code.push(util.format('.body(%s)', JSON.stringify(self.source.postData.text))) |
35 | 35 | } |
36 | 36 | } |
37 | 37 |
|
38 | | - code.push(".asString();"); |
39 | | - return code.join('\n' + opts.indent); |
40 | | -}; |
| 38 | + code.push('.asString();') |
| 39 | + return code.join('\n' + opts.indent) |
| 40 | +} |
41 | 41 |
|
42 | 42 | module.exports.info = { |
43 | | - key : 'unirest', |
44 | | - title : 'JAVA', |
45 | | - link : 'http://unirest.io/java.html', |
46 | | - description : 'Unirest Java interface' |
47 | | -}; |
| 43 | + key: 'unirest', |
| 44 | + title: 'JAVA', |
| 45 | + link: 'http://unirest.io/java.html', |
| 46 | + description: 'Unirest Java interface' |
| 47 | +} |
0 commit comments