@readme/httpsnippet 2.4.5 → 3.0.1

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