@readme/httpsnippet 2.5.1 → 3.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/README.md +19 -9
  2. package/package.json +24 -28
  3. package/src/helpers/code-builder.js +85 -80
  4. package/src/helpers/form-data.js +27 -25
  5. package/src/helpers/headers.js +10 -19
  6. package/src/helpers/reducer.js +10 -14
  7. package/src/index.js +167 -146
  8. package/src/targets/c/index.js +3 -5
  9. package/src/targets/c/libcurl.js +18 -23
  10. package/src/targets/clojure/clj_http.js +103 -87
  11. package/src/targets/clojure/index.js +3 -5
  12. package/src/targets/csharp/httpclient.js +90 -90
  13. package/src/targets/csharp/index.js +3 -5
  14. package/src/targets/csharp/restsharp.js +20 -22
  15. package/src/targets/go/index.js +3 -5
  16. package/src/targets/go/native.js +46 -53
  17. package/src/targets/http/http1.1.js +26 -36
  18. package/src/targets/http/index.js +3 -5
  19. package/src/targets/index.js +2 -4
  20. package/src/targets/java/asynchttp.js +22 -23
  21. package/src/targets/java/index.js +3 -5
  22. package/src/targets/java/nethttp.js +20 -24
  23. package/src/targets/java/okhttp.js +31 -31
  24. package/src/targets/java/unirest.js +22 -19
  25. package/src/targets/javascript/axios.js +43 -38
  26. package/src/targets/javascript/fetch.js +66 -68
  27. package/src/targets/javascript/index.js +3 -5
  28. package/src/targets/javascript/jquery.js +46 -40
  29. package/src/targets/javascript/xhr.js +42 -38
  30. package/src/targets/kotlin/index.js +3 -5
  31. package/src/targets/kotlin/okhttp.js +31 -31
  32. package/src/targets/node/axios.js +33 -30
  33. package/src/targets/node/fetch.js +89 -83
  34. package/src/targets/node/index.js +4 -5
  35. package/src/targets/node/native.js +36 -30
  36. package/src/targets/node/request.js +64 -64
  37. package/src/targets/node/unirest.js +56 -55
  38. package/src/targets/objc/helpers.js +24 -23
  39. package/src/targets/objc/index.js +3 -5
  40. package/src/targets/objc/nsurlsession.js +73 -45
  41. package/src/targets/ocaml/cohttp.js +29 -27
  42. package/src/targets/ocaml/index.js +3 -5
  43. package/src/targets/php/curl.js +86 -82
  44. package/src/targets/php/guzzle.js +135 -0
  45. package/src/targets/php/helpers.js +29 -28
  46. package/src/targets/php/http1.js +33 -44
  47. package/src/targets/php/http2.js +70 -71
  48. package/src/targets/php/index.js +5 -5
  49. package/src/targets/powershell/common.js +35 -30
  50. package/src/targets/powershell/index.js +3 -5
  51. package/src/targets/powershell/restmethod.js +3 -5
  52. package/src/targets/powershell/webrequest.js +3 -5
  53. package/src/targets/python/helpers.js +37 -34
  54. package/src/targets/python/index.js +4 -5
  55. package/src/targets/python/python3.js +33 -44
  56. package/src/targets/python/requests.js +47 -72
  57. package/src/targets/r/httr.js +59 -70
  58. package/src/targets/r/index.js +3 -5
  59. package/src/targets/ruby/index.js +3 -5
  60. package/src/targets/ruby/native.js +39 -33
  61. package/src/targets/shell/curl.js +74 -52
  62. package/src/targets/shell/helpers.js +7 -9
  63. package/src/targets/shell/httpie.js +45 -39
  64. package/src/targets/shell/index.js +4 -5
  65. package/src/targets/shell/wget.js +20 -22
  66. package/src/targets/swift/helpers.js +35 -32
  67. package/src/targets/swift/index.js +3 -5
  68. package/src/targets/swift/nsurlsession.js +53 -39
@@ -8,153 +8,169 @@
8
8
  * for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
9
9
  */
10
10
 
11
- 'use strict'
12
-
13
- const CodeBuilder = require('../../helpers/code-builder')
14
- const helpers = require('../../helpers/headers')
11
+ const CodeBuilder = require('../../helpers/code-builder');
12
+ const helpers = require('../../helpers/headers');
15
13
 
16
14
  const Keyword = function (name) {
17
- this.name = name
18
- }
15
+ this.name = name;
16
+ };
19
17
 
20
18
  Keyword.prototype.toString = function () {
21
- return ':' + this.name
22
- }
19
+ return `:${this.name}`;
20
+ };
23
21
 
24
22
  const File = function (path) {
25
- this.path = path
26
- }
23
+ this.path = path;
24
+ };
27
25
 
28
26
  File.prototype.toString = function () {
29
- return '(clojure.java.io/file "' + this.path + '")'
30
- }
27
+ return `(clojure.java.io/file "${this.path}")`;
28
+ };
31
29
 
32
30
  const jsType = function (x) {
33
- return (typeof x !== 'undefined')
34
- ? x.constructor.name.toLowerCase()
35
- : null
36
- }
31
+ return typeof x !== 'undefined' ? x.constructor.name.toLowerCase() : null;
32
+ };
37
33
 
38
34
  const objEmpty = function (x) {
39
- return (jsType(x) === 'object')
40
- ? Object.keys(x).length === 0
41
- : false
42
- }
35
+ return jsType(x) === 'object' ? Object.keys(x).length === 0 : false;
36
+ };
43
37
 
44
38
  const filterEmpty = function (m) {
45
39
  Object.keys(m)
46
- .filter(function (x) { return objEmpty(m[x]) })
47
- .forEach(function (x) { delete m[x] })
48
- return m
49
- }
40
+ .filter(function (x) {
41
+ return objEmpty(m[x]);
42
+ })
43
+ .forEach(function (x) {
44
+ // eslint-disable-next-line no-param-reassign
45
+ delete m[x];
46
+ });
47
+
48
+ return m;
49
+ };
50
50
 
51
51
  const padBlock = function (x, s) {
52
- const padding = Array.apply(null, Array(x))
53
- .map(function (_) {
54
- return ' '
52
+ // eslint-disable-next-line prefer-spread
53
+ const padding = Array.apply(null, new Array(x))
54
+ .map(function () {
55
+ return ' ';
55
56
  })
56
- .join('')
57
- return s.replace(/\n/g, '\n' + padding)
58
- }
57
+ .join('');
58
+
59
+ return s.replace(/\n/g, `\n${padding}`);
60
+ };
59
61
 
60
62
  const jsToEdn = function (js) {
61
63
  switch (jsType(js)) {
62
64
  case 'string':
63
- return '"' + js.replace(/"/g, '\\"') + '"'
65
+ return `"${js.replace(/"/g, '\\"')}"`;
64
66
  case 'file':
65
- return js.toString()
67
+ return js.toString();
66
68
  case 'keyword':
67
- return js.toString()
69
+ return js.toString();
68
70
  case 'null':
69
- return 'nil'
71
+ return 'nil';
70
72
  case 'regexp':
71
- return '#"' + js.source + '"'
72
- case 'object': { // simple vertical format
73
+ return `#"${js.source}"`;
74
+
75
+ // simple vertical format
76
+ case 'object': {
73
77
  const obj = Object.keys(js)
74
78
  .reduce(function (acc, key) {
75
- const val = padBlock(key.length + 2, jsToEdn(js[key]))
76
- return acc + ':' + key + ' ' + val + '\n '
79
+ const val = padBlock(key.length + 2, jsToEdn(js[key]));
80
+ return `${acc}:${key} ${val}\n `;
77
81
  }, '')
78
- .trim()
79
- return '{' + padBlock(1, obj) + '}'
82
+ .trim();
83
+ return `{${padBlock(1, obj)}}`;
80
84
  }
81
- case 'array': { // simple horizontal format
82
- const arr = js.reduce(function (acc, val) {
83
- return acc + ' ' + jsToEdn(val)
84
- }, '').trim()
85
- return '[' + padBlock(1, arr) + ']'
85
+
86
+ // simple horizontal format
87
+ case 'array': {
88
+ const arr = js
89
+ .reduce(function (acc, val) {
90
+ return `${acc} ${jsToEdn(val)}`;
91
+ }, '')
92
+ .trim();
93
+ return `[${padBlock(1, arr)}]`;
86
94
  }
87
- default: // 'number' 'boolean'
88
- return js.toString()
95
+
96
+ // 'number' 'boolean'
97
+ default:
98
+ return js.toString();
89
99
  }
90
- }
100
+ };
91
101
 
92
102
  module.exports = function (source, options) {
93
- const code = new CodeBuilder(options)
94
- const methods = ['get', 'post', 'put', 'delete', 'patch', 'head', 'options']
103
+ const code = new CodeBuilder(options);
104
+ const methods = ['get', 'post', 'put', 'delete', 'patch', 'head', 'options'];
95
105
 
96
106
  if (methods.indexOf(source.method.toLowerCase()) === -1) {
97
- return code.push('Method not supported').join()
107
+ return code.push('Method not supported').join();
98
108
  }
99
109
 
100
110
  const params = {
101
111
  headers: source.allHeaders,
102
- 'query-params': source.queryObj
103
- }
112
+ 'query-params': source.queryObj,
113
+ };
104
114
 
115
+ // eslint-disable-next-line default-case
105
116
  switch (source.postData.mimeType) {
106
117
  case 'application/json':
107
- params['content-type'] = new Keyword('json')
108
- params['form-params'] = source.postData.jsonObj
109
- delete params.headers[helpers.getHeaderName(params.headers, 'content-type')]
110
- break
118
+ params['content-type'] = new Keyword('json');
119
+ params['form-params'] = source.postData.jsonObj;
120
+ delete params.headers[helpers.getHeaderName(params.headers, 'content-type')];
121
+ break;
111
122
  case 'application/x-www-form-urlencoded':
112
- params['form-params'] = source.postData.paramsObj
113
- delete params.headers[helpers.getHeaderName(params.headers, 'content-type')]
114
- break
123
+ params['form-params'] = source.postData.paramsObj;
124
+ delete params.headers[helpers.getHeaderName(params.headers, 'content-type')];
125
+ break;
115
126
  case 'text/plain':
116
- params.body = source.postData.text
117
- delete params.headers[helpers.getHeaderName(params.headers, 'content-type')]
118
- break
127
+ params.body = source.postData.text;
128
+ delete params.headers[helpers.getHeaderName(params.headers, 'content-type')];
129
+ break;
119
130
  case 'multipart/form-data':
120
- params.multipart = source.postData.params.map(function (x) {
121
- if (x.fileName && !x.value) {
122
- return {
123
- name: x.name,
124
- content: new File(x.fileName)
131
+ if (source.postData.params) {
132
+ params.multipart = source.postData.params.map(function (x) {
133
+ if (x.fileName && !x.value) {
134
+ return {
135
+ name: x.name,
136
+ content: new File(x.fileName),
137
+ };
125
138
  }
126
- } else {
139
+
127
140
  return {
128
141
  name: x.name,
129
- content: x.value
130
- }
131
- }
132
- })
133
- delete params.headers[helpers.getHeaderName(params.headers, 'content-type')]
134
- break
142
+ content: x.value,
143
+ };
144
+ });
145
+ delete params.headers[helpers.getHeaderName(params.headers, 'content-type')];
146
+ }
147
+ break;
135
148
  }
136
149
 
137
- switch (helpers.getHeader(params.headers, 'accept')) {
138
- case 'application/json':
139
- params.accept = new Keyword('json')
140
- delete params.headers[helpers.getHeaderName(params.headers, 'accept')]
141
- break
150
+ if (helpers.getHeader(params.headers, 'accept') === 'application/json') {
151
+ params.accept = new Keyword('json');
152
+ delete params.headers[helpers.getHeaderName(params.headers, 'accept')];
142
153
  }
143
154
 
144
- code.push('(require \'[clj-http.client :as client])\n')
155
+ code.push("(require '[clj-http.client :as client])\n");
145
156
 
146
157
  if (objEmpty(filterEmpty(params))) {
147
- code.push('(client/%s "%s")', source.method.toLowerCase(), source.url)
158
+ code.push('(client/%s "%s")', source.method.toLowerCase(), source.url);
148
159
  } else {
149
- code.push('(client/%s "%s" %s)', source.method.toLowerCase(), source.url, padBlock(11 + source.method.length + source.url.length, jsToEdn(filterEmpty(params))))
160
+ code.push(
161
+ '(client/%s "%s" %s)',
162
+ source.method.toLowerCase(),
163
+ source.url,
164
+ padBlock(11 + source.method.length + source.url.length, jsToEdn(filterEmpty(params)))
165
+ );
150
166
  }
151
167
 
152
- return code.join()
153
- }
168
+ return code.join();
169
+ };
154
170
 
155
171
  module.exports.info = {
156
172
  key: 'clj_http',
157
173
  title: 'clj-http',
158
174
  link: 'https://github.com/dakrone/clj-http',
159
- description: 'An idiomatic clojure http client wrapping the apache client.'
160
- }
175
+ description: 'An idiomatic clojure http client wrapping the apache client.',
176
+ };
@@ -1,12 +1,10 @@
1
- 'use strict'
2
-
3
1
  module.exports = {
4
2
  info: {
5
3
  key: 'clojure',
6
4
  title: 'Clojure',
7
5
  extname: '.clj',
8
- default: 'clj_http'
6
+ default: 'clj_http',
9
7
  },
10
8
 
11
- clj_http: require('./clj_http')
12
- }
9
+ clj_http: require('./clj_http'),
10
+ };
@@ -1,74 +1,74 @@
1
- 'use strict'
1
+ const CodeBuilder = require('../../helpers/code-builder');
2
+ const helpers = require('../../helpers/headers');
2
3
 
3
- const CodeBuilder = require('../../helpers/code-builder')
4
- const helpers = require('../../helpers/headers')
5
-
6
- function getDecompressionMethods (source) {
7
- const acceptEncoding = helpers.getHeader(source.allHeaders, 'accept-encoding')
4
+ function getDecompressionMethods(source) {
5
+ const acceptEncoding = helpers.getHeader(source.allHeaders, 'accept-encoding');
8
6
  if (!acceptEncoding) {
9
- return [] // no decompression
7
+ return []; // no decompression
10
8
  }
11
9
 
12
10
  const supportedMethods = {
13
11
  gzip: 'DecompressionMethods.GZip',
14
- deflate: 'DecompressionMethods.Deflate'
15
- }
16
- const methods = []
12
+ deflate: 'DecompressionMethods.Deflate',
13
+ };
14
+
15
+ const methods = [];
17
16
  acceptEncoding.split(',').forEach(function (encoding) {
18
- const match = /\s*([^;\s]+)/.exec(encoding)
17
+ const match = /\s*([^;\s]+)/.exec(encoding);
19
18
  if (match) {
20
- const method = supportedMethods[match[1]]
19
+ const method = supportedMethods[match[1]];
21
20
  if (method) {
22
- methods.push(method)
21
+ methods.push(method);
23
22
  }
24
23
  }
25
- })
24
+ });
26
25
 
27
- return methods
26
+ return methods;
28
27
  }
29
28
 
30
29
  module.exports = function (source, options) {
31
- const opts = Object.assign({
32
- indent: ' '
33
- }, options)
30
+ const opts = {
31
+ indent: ' ',
32
+ ...options,
33
+ };
34
34
 
35
- const code = new CodeBuilder(opts.indent)
35
+ const code = new CodeBuilder(opts.indent);
36
36
 
37
- let clienthandler = ''
38
- const cookies = !!source.allHeaders.cookie
39
- const decompressionMethods = getDecompressionMethods(source)
37
+ let clienthandler = '';
38
+ const cookies = !!source.allHeaders.cookie;
39
+ const decompressionMethods = getDecompressionMethods(source);
40
40
  if (cookies || decompressionMethods.length) {
41
- clienthandler = 'clientHandler'
42
- code.push('var clientHandler = new HttpClientHandler')
43
- code.push('{')
41
+ clienthandler = 'clientHandler';
42
+ code.push('var clientHandler = new HttpClientHandler');
43
+ code.push('{');
44
44
  if (cookies) {
45
45
  // enable setting the cookie header
46
- code.push(1, 'UseCookies = false,')
46
+ code.push(1, 'UseCookies = false,');
47
47
  }
48
48
  if (decompressionMethods.length) {
49
49
  // enable decompression for supported methods
50
- code.push(1, 'AutomaticDecompression = %s,', decompressionMethods.join(' | '))
50
+ code.push(1, 'AutomaticDecompression = %s,', decompressionMethods.join(' | '));
51
51
  }
52
- code.push('};')
52
+ code.push('};');
53
53
  }
54
54
 
55
- code.push('var client = new HttpClient(%s);', clienthandler)
55
+ code.push('var client = new HttpClient(%s);', clienthandler);
56
56
 
57
- code.push('var request = new HttpRequestMessage')
58
- code.push('{')
57
+ code.push('var request = new HttpRequestMessage');
58
+ code.push('{');
59
59
 
60
- const methods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS', 'TRACE']
61
- let method = source.method.toUpperCase()
62
- if (method && (methods.indexOf(method) !== -1)) {
60
+ const methods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS', 'TRACE'];
61
+ let method = source.method.toUpperCase();
62
+ if (method && methods.indexOf(method) !== -1) {
63
63
  // buildin method
64
- method = `HttpMethod.${method[0]}${method.substring(1).toLowerCase()}`
64
+ method = `HttpMethod.${method[0]}${method.substring(1).toLowerCase()}`;
65
65
  } else {
66
66
  // custom method
67
- method = `new HttpMethod("${method}")`
67
+ method = `new HttpMethod("${method}")`;
68
68
  }
69
- code.push(1, 'Method = %s,', method)
69
+ code.push(1, 'Method = %s,', method);
70
70
 
71
- code.push(1, 'RequestUri = new Uri("%s"),', source.fullUrl)
71
+ code.push(1, 'RequestUri = new Uri("%s"),', source.fullUrl);
72
72
 
73
73
  const headers = Object.keys(source.allHeaders).filter(function (header) {
74
74
  switch (header.toLowerCase()) {
@@ -76,82 +76,82 @@ module.exports = function (source, options) {
76
76
  case 'content-length':
77
77
  case 'accept-encoding':
78
78
  // skip these headers
79
- return false
79
+ return false;
80
80
  default:
81
- return true
81
+ return true;
82
82
  }
83
- })
83
+ });
84
84
  if (headers.length) {
85
- code.push(1, 'Headers =')
86
- code.push(1, '{')
85
+ code.push(1, 'Headers =');
86
+ code.push(1, '{');
87
87
  headers.forEach(function (key) {
88
- code.push(2, '{ "%s", "%s" },', key, source.allHeaders[key])
89
- })
90
- code.push(1, '},')
88
+ code.push(2, '{ "%s", "%s" },', key, source.allHeaders[key]);
89
+ });
90
+ code.push(1, '},');
91
91
  }
92
92
 
93
93
  if (source.postData.text) {
94
- const contentType = source.postData.mimeType
94
+ const contentType = source.postData.mimeType;
95
95
  switch (contentType) {
96
96
  case 'application/x-www-form-urlencoded':
97
- code.push(1, 'Content = new FormUrlEncodedContent(new Dictionary<string, string>')
98
- code.push(1, '{')
97
+ code.push(1, 'Content = new FormUrlEncodedContent(new Dictionary<string, string>');
98
+ code.push(1, '{');
99
99
  source.postData.params.forEach(function (param) {
100
- code.push(2, '{ "%s", "%s" },', param.name, param.value)
101
- })
102
- code.push(1, '}),')
103
- break
100
+ code.push(2, '{ "%s", "%s" },', param.name, param.value);
101
+ });
102
+ code.push(1, '}),');
103
+ break;
104
104
  case 'multipart/form-data':
105
- code.push(1, 'Content = new MultipartFormDataContent')
106
- code.push(1, '{')
105
+ code.push(1, 'Content = new MultipartFormDataContent');
106
+ code.push(1, '{');
107
107
  source.postData.params.forEach(function (param) {
108
- code.push(2, 'new StringContent(%s)', JSON.stringify(param.value || ''))
109
- code.push(2, '{')
110
- code.push(3, 'Headers =')
111
- code.push(3, '{')
108
+ code.push(2, 'new StringContent(%s)', JSON.stringify(param.value || ''));
109
+ code.push(2, '{');
110
+ code.push(3, 'Headers =');
111
+ code.push(3, '{');
112
112
  if (param.contentType) {
113
- code.push(4, 'ContentType = new MediaTypeHeaderValue("%s"),', param.contentType)
113
+ code.push(4, 'ContentType = new MediaTypeHeaderValue("%s"),', param.contentType);
114
114
  }
115
- code.push(4, 'ContentDisposition = new ContentDispositionHeaderValue("form-data")')
116
- code.push(4, '{')
117
- code.push(5, 'Name = "%s",', param.name)
115
+ code.push(4, 'ContentDisposition = new ContentDispositionHeaderValue("form-data")');
116
+ code.push(4, '{');
117
+ code.push(5, 'Name = "%s",', param.name);
118
118
  if (param.fileName) {
119
- code.push(5, 'FileName = "%s",', param.fileName)
119
+ code.push(5, 'FileName = "%s",', param.fileName);
120
120
  }
121
- code.push(4, '}')
122
- code.push(3, '}')
123
- code.push(2, '},')
124
- })
121
+ code.push(4, '}');
122
+ code.push(3, '}');
123
+ code.push(2, '},');
124
+ });
125
125
 
126
- code.push(1, '},')
127
- break
126
+ code.push(1, '},');
127
+ break;
128
128
  default:
129
- code.push(1, 'Content = new StringContent(%s)', JSON.stringify(source.postData.text || ''))
130
- code.push(1, '{')
131
- code.push(2, 'Headers =')
132
- code.push(2, '{')
133
- code.push(3, 'ContentType = new MediaTypeHeaderValue("%s")', contentType)
134
- code.push(2, '}')
135
- code.push(1, '}')
136
- break
129
+ code.push(1, 'Content = new StringContent(%s)', JSON.stringify(source.postData.text || ''));
130
+ code.push(1, '{');
131
+ code.push(2, 'Headers =');
132
+ code.push(2, '{');
133
+ code.push(3, 'ContentType = new MediaTypeHeaderValue("%s")', contentType);
134
+ code.push(2, '}');
135
+ code.push(1, '}');
136
+ break;
137
137
  }
138
138
  }
139
- code.push('};')
139
+ code.push('};');
140
140
 
141
141
  // send and read response
142
- code.push('using (var response = await client.SendAsync(request))')
143
- code.push('{')
144
- code.push(1, 'response.EnsureSuccessStatusCode();')
145
- code.push(1, 'var body = await response.Content.ReadAsStringAsync();')
146
- code.push(1, 'Console.WriteLine(body);')
147
- code.push('}')
148
-
149
- return code.join()
150
- }
142
+ code.push('using (var response = await client.SendAsync(request))');
143
+ code.push('{');
144
+ code.push(1, 'response.EnsureSuccessStatusCode();');
145
+ code.push(1, 'var body = await response.Content.ReadAsStringAsync();');
146
+ code.push(1, 'Console.WriteLine(body);');
147
+ code.push('}');
148
+
149
+ return code.join();
150
+ };
151
151
 
152
152
  module.exports.info = {
153
153
  key: 'httpclient',
154
154
  title: 'HttpClient',
155
155
  link: 'https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient',
156
- description: '.NET Standard HTTP Client'
157
- }
156
+ description: '.NET Standard HTTP Client',
157
+ };
@@ -1,13 +1,11 @@
1
- 'use strict'
2
-
3
1
  module.exports = {
4
2
  info: {
5
3
  key: 'csharp',
6
4
  title: 'C#',
7
5
  extname: '.cs',
8
- default: 'restsharp'
6
+ default: 'restsharp',
9
7
  },
10
8
 
11
9
  restsharp: require('./restsharp'),
12
- httpclient: require('./httpclient')
13
- }
10
+ httpclient: require('./httpclient'),
11
+ };
@@ -1,34 +1,32 @@
1
- 'use strict'
1
+ const CodeBuilder = require('../../helpers/code-builder');
2
+ const helpers = require('../../helpers/headers');
2
3
 
3
- const CodeBuilder = require('../../helpers/code-builder')
4
- const helpers = require('../../helpers/headers')
5
-
6
- module.exports = function (source, options) {
7
- const code = new CodeBuilder()
8
- const methods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS']
4
+ module.exports = function (source) {
5
+ const code = new CodeBuilder();
6
+ const methods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'];
9
7
 
10
8
  if (methods.indexOf(source.method.toUpperCase()) === -1) {
11
- return 'Method not supported'
12
- } else {
13
- code.push('var client = new RestClient("%s");', source.fullUrl)
14
- code.push('var request = new RestRequest(Method.%s);', source.method.toUpperCase())
9
+ return 'Method not supported';
15
10
  }
16
11
 
12
+ code.push('var client = new RestClient("%s");', source.fullUrl);
13
+ code.push('var request = new RestRequest(Method.%s);', source.method.toUpperCase());
14
+
17
15
  // Add headers, including the cookies
18
- const headers = Object.keys(source.headersObj)
16
+ const headers = Object.keys(source.headersObj);
19
17
 
20
18
  // construct headers
21
19
  if (headers.length) {
22
20
  headers.forEach(function (key) {
23
- code.push('request.AddHeader("%s", "%s");', key, source.headersObj[key])
24
- })
21
+ code.push('request.AddHeader("%s", "%s");', key, source.headersObj[key]);
22
+ });
25
23
  }
26
24
 
27
25
  // construct cookies
28
26
  if (source.cookies.length) {
29
27
  source.cookies.forEach(function (cookie) {
30
- code.push('request.AddCookie("%s", "%s");', cookie.name, cookie.value)
31
- })
28
+ code.push('request.AddCookie("%s", "%s");', cookie.name, cookie.value);
29
+ });
32
30
  }
33
31
 
34
32
  if (source.postData.text) {
@@ -36,16 +34,16 @@ module.exports = function (source, options) {
36
34
  'request.AddParameter("%s", %s, ParameterType.RequestBody);',
37
35
  helpers.getHeader(source.allHeaders, 'content-type'),
38
36
  JSON.stringify(source.postData.text)
39
- )
37
+ );
40
38
  }
41
39
 
42
- code.push('IRestResponse response = client.Execute(request);')
43
- return code.join()
44
- }
40
+ code.push('IRestResponse response = client.Execute(request);');
41
+ return code.join();
42
+ };
45
43
 
46
44
  module.exports.info = {
47
45
  key: 'restsharp',
48
46
  title: 'RestSharp',
49
47
  link: 'http://restsharp.org/',
50
- description: 'Simple REST and HTTP API Client for .NET'
51
- }
48
+ description: 'Simple REST and HTTP API Client for .NET',
49
+ };
@@ -1,12 +1,10 @@
1
- 'use strict'
2
-
3
1
  module.exports = {
4
2
  info: {
5
3
  key: 'go',
6
4
  title: 'Go',
7
5
  extname: '.go',
8
- default: 'native'
6
+ default: 'native',
9
7
  },
10
8
 
11
- native: require('./native')
12
- }
9
+ native: require('./native'),
10
+ };