@scalar/snippetz 0.8.0 → 0.9.0

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 (52) hide show
  1. package/dist/clients/index.d.ts.map +1 -1
  2. package/dist/clients/index.js +5 -4
  3. package/dist/libs/javascript.d.ts.map +1 -1
  4. package/dist/libs/javascript.js +6 -3
  5. package/dist/plugins/go/native/native.d.ts.map +1 -1
  6. package/dist/plugins/go/native/native.js +191 -5
  7. package/dist/plugins/js/axios/axios.d.ts +1 -2
  8. package/dist/plugins/js/axios/axios.d.ts.map +1 -1
  9. package/dist/plugins/js/axios/axios.js +2 -11
  10. package/dist/plugins/node/axios/axios.d.ts +1 -2
  11. package/dist/plugins/node/axios/axios.d.ts.map +1 -1
  12. package/dist/plugins/node/axios/axios.js +2 -11
  13. package/dist/plugins/php/laravel/index.d.ts +2 -0
  14. package/dist/plugins/php/laravel/index.d.ts.map +1 -0
  15. package/dist/plugins/php/laravel/index.js +1 -0
  16. package/dist/plugins/php/laravel/laravel.d.ts +6 -0
  17. package/dist/plugins/php/laravel/laravel.d.ts.map +1 -0
  18. package/dist/plugins/php/laravel/laravel.js +134 -0
  19. package/dist/plugins/r/httr2/httr2.d.ts +6 -0
  20. package/dist/plugins/r/httr2/httr2.d.ts.map +1 -0
  21. package/dist/plugins/r/httr2/httr2.js +159 -0
  22. package/dist/plugins/r/httr2/index.d.ts +2 -0
  23. package/dist/plugins/r/httr2/index.d.ts.map +1 -0
  24. package/dist/plugins/r/httr2/index.js +1 -0
  25. package/dist/plugins/ruby/native/native.d.ts.map +1 -1
  26. package/dist/plugins/ruby/native/native.js +138 -5
  27. package/dist/plugins/shared/axios.d.ts +3 -0
  28. package/dist/plugins/shared/axios.d.ts.map +1 -0
  29. package/dist/plugins/shared/axios.js +148 -0
  30. package/dist/snippetz.d.ts +1 -1
  31. package/package.json +12 -7
  32. package/dist/httpsnippet-lite/targets/go/native/client.d.ts +0 -12
  33. package/dist/httpsnippet-lite/targets/go/native/client.d.ts.map +0 -1
  34. package/dist/httpsnippet-lite/targets/go/native/client.js +0 -157
  35. package/dist/httpsnippet-lite/targets/javascript/axios/client.d.ts +0 -12
  36. package/dist/httpsnippet-lite/targets/javascript/axios/client.d.ts.map +0 -1
  37. package/dist/httpsnippet-lite/targets/javascript/axios/client.js +0 -86
  38. package/dist/httpsnippet-lite/targets/node/axios/client.d.ts +0 -3
  39. package/dist/httpsnippet-lite/targets/node/axios/client.d.ts.map +0 -1
  40. package/dist/httpsnippet-lite/targets/node/axios/client.js +0 -78
  41. package/dist/httpsnippet-lite/targets/r/httr/client.d.ts +0 -12
  42. package/dist/httpsnippet-lite/targets/r/httr/client.d.ts.map +0 -1
  43. package/dist/httpsnippet-lite/targets/r/httr/client.js +0 -115
  44. package/dist/httpsnippet-lite/targets/ruby/native/client.d.ts +0 -3
  45. package/dist/httpsnippet-lite/targets/ruby/native/client.d.ts.map +0 -1
  46. package/dist/httpsnippet-lite/targets/ruby/native/client.js +0 -67
  47. package/dist/plugins/r/httr/httr.d.ts +0 -6
  48. package/dist/plugins/r/httr/httr.d.ts.map +0 -1
  49. package/dist/plugins/r/httr/httr.js +0 -14
  50. package/dist/plugins/r/httr/index.d.ts +0 -2
  51. package/dist/plugins/r/httr/index.d.ts.map +0 -1
  52. package/dist/plugins/r/httr/index.js +0 -1
@@ -1,157 +0,0 @@
1
- /**
2
- * @description
3
- * HTTP code snippet generator for native Go.
4
- *
5
- * @author
6
- * @montanaflynn
7
- *
8
- * for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
9
- */
10
- import { CodeBuilder } from '../../../../httpsnippet-lite/helpers/code-builder.js';
11
- import { escapeForDoubleQuotes } from '../../../../httpsnippet-lite/helpers/escape.js';
12
- export const native = {
13
- info: {
14
- key: 'native',
15
- title: 'NewRequest',
16
- link: 'http://golang.org/pkg/net/http/#NewRequest',
17
- description: 'Golang HTTP client request',
18
- },
19
- convert: ({ postData, method, allHeaders, fullUrl }, options = {}) => {
20
- const { blank, push, join, addPostProcessor } = new CodeBuilder({ indent: '\t' });
21
- const { showBoilerplate = true, checkErrors = false, printBody = true, timeout = -1, insecureSkipVerify = false, } = options;
22
- const errorPlaceholder = checkErrors ? 'err' : '_';
23
- const indent = showBoilerplate ? 1 : 0;
24
- const errorCheck = () => {
25
- if (checkErrors) {
26
- push('if err != nil {', indent);
27
- push('panic(err)', indent + 1);
28
- push('}', indent);
29
- }
30
- };
31
- // Create boilerplate
32
- const imports = new Set();
33
- if (showBoilerplate) {
34
- push('package main');
35
- blank();
36
- push('import ()');
37
- addPostProcessor((code) => {
38
- const importArray = [...imports];
39
- importArray.sort();
40
- const importBlock = importArray.map((line) => `\t"${line}"`).join('\n');
41
- return code.replace(/import \(\)/, `import (\n${importBlock}\n)`);
42
- });
43
- imports.add('fmt');
44
- imports.add('net/http');
45
- blank();
46
- push('func main() {');
47
- }
48
- // Create an insecure transport for the client
49
- if (insecureSkipVerify) {
50
- imports.add('crypto/tls');
51
- push('insecureTransport := http.DefaultTransport.(*http.Transport).Clone()', indent);
52
- push('insecureTransport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}', indent);
53
- }
54
- // Create client
55
- const hasTimeout = timeout > 0;
56
- const hasClient = hasTimeout || insecureSkipVerify;
57
- const client = hasClient ? 'client' : 'http.DefaultClient';
58
- if (hasClient) {
59
- push('client := http.Client{', indent);
60
- if (hasTimeout) {
61
- imports.add('time');
62
- push(`Timeout: time.Duration(${timeout} * time.Second),`, indent + 1);
63
- }
64
- if (insecureSkipVerify) {
65
- push('Transport: insecureTransport,', indent + 1);
66
- }
67
- push('}', indent);
68
- blank();
69
- }
70
- push(`url := "${fullUrl}"`, indent);
71
- blank();
72
- // If we have body content or not create the var and reader or nil
73
- if (postData !== null && postData !== void 0 && (postData.params || postData.text)) {
74
- if (postData.mimeType === 'application/x-www-form-urlencoded' && postData.params) {
75
- imports.add('net/url');
76
- imports.add('strings');
77
- push('postData := url.Values{}', indent);
78
- postData.params.forEach((param) => {
79
- push(`postData.Set("${param.name}", "${escapeForDoubleQuotes(param.value)}")`, indent);
80
- });
81
- blank();
82
- push(`req, ${errorPlaceholder} := http.NewRequest("${method}", url, strings.NewReader(postData.Encode()))`, indent);
83
- }
84
- else if (postData.mimeType === 'multipart/form-data' && postData.params) {
85
- imports.add('bytes');
86
- imports.add('mime/multipart');
87
- push('payload := &bytes.Buffer{}', indent);
88
- push('writer := multipart.NewWriter(payload)', indent);
89
- postData.params.forEach((param) => {
90
- blank();
91
- if (param.fileName) {
92
- push(`part, ${errorPlaceholder} := writer.CreateFormFile("${param.name}", "${param.fileName}")`, indent);
93
- errorCheck();
94
- blank();
95
- push(`f, ${errorPlaceholder} := os.Open("${param.fileName}")`, indent);
96
- errorCheck();
97
- push('defer f.Close()', indent);
98
- blank();
99
- push(`_, ${errorPlaceholder} = io.Copy(part, f)`, indent);
100
- errorCheck();
101
- }
102
- else {
103
- push(`${errorPlaceholder} = writer.WriteField("${param.name}", "${escapeForDoubleQuotes(param.value)}")`, indent);
104
- errorCheck();
105
- }
106
- });
107
- push('writer.Close()', indent);
108
- blank();
109
- push(`req, ${errorPlaceholder} := http.NewRequest("${method}", url, payload)`, indent);
110
- }
111
- else {
112
- imports.add('strings');
113
- push(`payload := strings.NewReader(${JSON.stringify(postData.text)})`, indent);
114
- blank();
115
- push(`req, ${errorPlaceholder} := http.NewRequest("${method}", url, payload)`, indent);
116
- }
117
- }
118
- else {
119
- push(`req, ${errorPlaceholder} := http.NewRequest("${method}", url, nil)`, indent);
120
- }
121
- errorCheck();
122
- blank();
123
- // Add headers
124
- if (postData !== null && postData !== void 0 && postData.mimeType === 'multipart/form-data' && postData.params) {
125
- push(`req.Header.Set("Content-Type", writer.FormDataContentType())`, indent);
126
- }
127
- if (Object.keys(allHeaders).length) {
128
- Object.keys(allHeaders).forEach((key) => {
129
- push(`req.Header.Add("${key}", "${escapeForDoubleQuotes(allHeaders[key])}")`, indent);
130
- });
131
- blank();
132
- }
133
- // Make request
134
- push(`res, ${errorPlaceholder} := ${client}.Do(req)`, indent);
135
- errorCheck();
136
- // Get Body
137
- if (printBody) {
138
- imports.add('io');
139
- blank();
140
- push('defer res.Body.Close()', indent);
141
- push(`body, ${errorPlaceholder} := io.ReadAll(res.Body)`, indent);
142
- errorCheck();
143
- }
144
- // Print it
145
- blank();
146
- push('fmt.Println(res)', indent);
147
- if (printBody) {
148
- push('fmt.Println(string(body))', indent);
149
- }
150
- // End main block
151
- if (showBoilerplate) {
152
- blank();
153
- push('}');
154
- }
155
- return join();
156
- },
157
- };
@@ -1,12 +0,0 @@
1
- /**
2
- * @description
3
- * HTTP code snippet generator for Javascript & Node.js using Axios.
4
- *
5
- * @author
6
- * @rohit-gohri
7
- *
8
- * for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
9
- */
10
- import type { Client } from '../../../../httpsnippet-lite/targets/target.js';
11
- export declare const axios: Client;
12
- //# sourceMappingURL=client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../src/httpsnippet-lite/targets/javascript/axios/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAA;AAE/D,eAAO,MAAM,KAAK,EAAE,MAgFnB,CAAA"}
@@ -1,86 +0,0 @@
1
- /**
2
- * @description
3
- * HTTP code snippet generator for Javascript & Node.js using Axios.
4
- *
5
- * @author
6
- * @rohit-gohri
7
- *
8
- * for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
9
- */
10
- import stringifyObject from 'stringify-object';
11
- import { CodeBuilder } from '../../../../httpsnippet-lite/helpers/code-builder.js';
12
- export const axios = {
13
- info: {
14
- key: 'axios',
15
- title: 'Axios',
16
- link: 'https://github.com/axios/axios',
17
- description: 'Promise based HTTP client for the browser and node.js',
18
- },
19
- convert: ({ allHeaders, method, url, queryObj, postData }, options) => {
20
- const opts = {
21
- indent: ' ',
22
- ...options,
23
- };
24
- const { blank, push, join, addPostProcessor } = new CodeBuilder({
25
- indent: opts.indent,
26
- });
27
- push("import axios from 'axios';");
28
- blank();
29
- const requestOptions = {
30
- method,
31
- url,
32
- };
33
- if (Object.keys(queryObj).length) {
34
- requestOptions.params = queryObj;
35
- }
36
- if (Object.keys(allHeaders).length) {
37
- requestOptions.headers = allHeaders;
38
- }
39
- switch (postData === null || postData === void 0 ? void 0 : postData.mimeType) {
40
- case 'application/x-www-form-urlencoded':
41
- if (postData?.params) {
42
- push('const encodedParams = new URLSearchParams();');
43
- postData.params.forEach((param) => {
44
- push(`encodedParams.set('${param.name}', '${param.value}');`);
45
- });
46
- blank();
47
- requestOptions.data = 'encodedParams,';
48
- addPostProcessor((code) => code.replace(/'encodedParams,'/, 'encodedParams,'));
49
- }
50
- break;
51
- case 'application/json':
52
- if (postData?.jsonObj) {
53
- requestOptions.data = postData.jsonObj;
54
- }
55
- break;
56
- case 'multipart/form-data':
57
- if (!postData?.params) {
58
- break;
59
- }
60
- push('const form = new FormData();');
61
- postData.params.forEach((param) => {
62
- push(`form.append('${param.name}', '${param.value || param.fileName || ''}');`);
63
- });
64
- blank();
65
- requestOptions.data = '[form]';
66
- break;
67
- default:
68
- if (postData === null || postData === void 0 ? void 0 : postData.text) {
69
- requestOptions.data = postData.text;
70
- }
71
- }
72
- const optionString = stringifyObject(requestOptions, {
73
- indent: ' ',
74
- inlineCharacterLimit: 80,
75
- }).replace('"[form]"', 'form');
76
- push(`const options = ${optionString};`);
77
- blank();
78
- push('try {');
79
- push('const { data } = await axios.request(options);', 1);
80
- push('console.log(data);', 1);
81
- push('} catch (error) {');
82
- push('console.error(error);', 1);
83
- push('}');
84
- return join();
85
- },
86
- };
@@ -1,3 +0,0 @@
1
- import type { Client } from '../../../../httpsnippet-lite/targets/target.js';
2
- export declare const axios: Client;
3
- //# sourceMappingURL=client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../src/httpsnippet-lite/targets/node/axios/client.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAA;AAE/D,eAAO,MAAM,KAAK,EAAE,MAwEnB,CAAA"}
@@ -1,78 +0,0 @@
1
- /**
2
- * @description
3
- * HTTP code snippet generator for Javascript & Node.js using Axios.
4
- *
5
- * @author
6
- * @rohit-gohri
7
- *
8
- * for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
9
- */
10
- import stringifyObject from 'stringify-object';
11
- import { CodeBuilder } from '../../../../httpsnippet-lite/helpers/code-builder.js';
12
- export const axios = {
13
- info: {
14
- key: 'axios',
15
- title: 'Axios',
16
- link: 'https://github.com/axios/axios',
17
- description: 'Promise based HTTP client for the browser and node.js',
18
- },
19
- convert: ({ method, url, queryObj, allHeaders, postData }, options) => {
20
- const opts = {
21
- indent: ' ',
22
- ...options,
23
- };
24
- const { blank, join, push, addPostProcessor } = new CodeBuilder({
25
- indent: opts.indent,
26
- });
27
- push("const axios = require('axios').default;");
28
- const reqOpts = {
29
- method,
30
- url,
31
- };
32
- if (Object.keys(queryObj).length) {
33
- reqOpts.params = queryObj;
34
- }
35
- if (Object.keys(allHeaders).length) {
36
- reqOpts.headers = allHeaders;
37
- }
38
- switch (postData === null || postData === void 0 ? void 0 : postData.mimeType) {
39
- case 'application/x-www-form-urlencoded':
40
- if (postData.params) {
41
- push("const { URLSearchParams } = require('url');");
42
- blank();
43
- push('const encodedParams = new URLSearchParams();');
44
- postData.params.forEach((param) => {
45
- push(`encodedParams.set('${param.name}', '${param.value}');`);
46
- });
47
- blank();
48
- reqOpts.data = 'encodedParams,';
49
- addPostProcessor((code) => code.replace(/'encodedParams,'/, 'encodedParams,'));
50
- }
51
- break;
52
- case 'application/json':
53
- blank();
54
- if (postData?.jsonObj) {
55
- reqOpts.data = postData.jsonObj;
56
- }
57
- break;
58
- default:
59
- blank();
60
- if (postData === null || postData === void 0 ? void 0 : postData.text) {
61
- reqOpts.data = postData.text;
62
- }
63
- }
64
- const stringifiedOptions = stringifyObject(reqOpts, {
65
- indent: ' ',
66
- inlineCharacterLimit: 80,
67
- });
68
- push(`const options = ${stringifiedOptions};`);
69
- blank();
70
- push('try {');
71
- push('const { data } = await axios.request(options);', 1);
72
- push('console.log(data);', 1);
73
- push('} catch (error) {');
74
- push('console.error(error);', 1);
75
- push('}');
76
- return join();
77
- },
78
- };
@@ -1,12 +0,0 @@
1
- /**
2
- * @description
3
- * HTTP code snippet generator for R using httr
4
- *
5
- * @author
6
- * @gabrielakoreeda
7
- *
8
- * for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
9
- */
10
- import type { Client } from '../../../../httpsnippet-lite/targets/target.js';
11
- export declare const httr: Client;
12
- //# sourceMappingURL=client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../src/httpsnippet-lite/targets/r/httr/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAA;AAE/D,eAAO,MAAM,IAAI,EAAE,MAuGlB,CAAA"}
@@ -1,115 +0,0 @@
1
- /**
2
- * @description
3
- * HTTP code snippet generator for R using httr
4
- *
5
- * @author
6
- * @gabrielakoreeda
7
- *
8
- * for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
9
- */
10
- import { CodeBuilder } from '../../../../httpsnippet-lite/helpers/code-builder.js';
11
- import { escapeForDoubleQuotes, escapeForSingleQuotes } from '../../../../httpsnippet-lite/helpers/escape.js';
12
- import { getHeader } from '../../../../httpsnippet-lite/helpers/headers.js';
13
- export const httr = {
14
- info: {
15
- key: 'httr',
16
- title: 'httr',
17
- link: 'https://cran.r-project.org/web/packages/httr/vignettes/quickstart.html',
18
- description: 'httr: Tools for Working with URLs and HTTP',
19
- },
20
- convert: ({ url, queryObj, queryString, postData, allHeaders, method }, options = {}) => {
21
- let _a, _b;
22
- // Start snippet
23
- const { push, blank, join } = new CodeBuilder({
24
- indent: (_a = options.indent) !== null && _a !== void 0 ? _a : ' ',
25
- });
26
- // Import httr
27
- push('library(httr)');
28
- blank();
29
- // Set URL
30
- push(`url <- "${url}"`);
31
- blank();
32
- // Construct query string
33
- const qs = queryObj;
34
- delete queryObj.key;
35
- const entries = Object.entries(qs).flatMap(([key, value]) => Array.isArray(value) ? value.map((item) => [key, item]) : [[key, value]]);
36
- const entriesCount = entries.length;
37
- if (entriesCount === 1) {
38
- const entry = entries[0];
39
- push(`queryString <- list(${entry[0]} = "${entry[1]}")`);
40
- blank();
41
- }
42
- else if (entriesCount > 1) {
43
- push('queryString <- list(');
44
- entries.forEach(([key, value], i) => {
45
- const isLastItem = i !== entriesCount - 1;
46
- const maybeComma = isLastItem ? ',' : '';
47
- push(`${key} = "${value}"${maybeComma}`, 1);
48
- });
49
- push(')');
50
- blank();
51
- }
52
- // Construct payload
53
- const payload = JSON.stringify(postData === null || postData === void 0 ? void 0 : postData.text);
54
- if (payload) {
55
- push(`payload <- ${payload}`);
56
- blank();
57
- }
58
- // Define encode
59
- if (postData && (postData.text || postData.jsonObj || postData.params)) {
60
- switch (postData.mimeType) {
61
- case 'application/x-www-form-urlencoded':
62
- push('encode <- "form"');
63
- blank();
64
- break;
65
- case 'application/json':
66
- push('encode <- "json"');
67
- blank();
68
- break;
69
- case 'multipart/form-data':
70
- push('encode <- "multipart"');
71
- blank();
72
- break;
73
- default:
74
- push('encode <- "raw"');
75
- blank();
76
- break;
77
- }
78
- }
79
- // Construct headers
80
- const cookieHeader = getHeader(allHeaders, 'cookie');
81
- const acceptHeader = getHeader(allHeaders, 'accept');
82
- const setCookies = cookieHeader
83
- ? `set_cookies(\`${String(cookieHeader).replace(/;/g, '", `').replace(/` /g, '`').replace(/[=]/g, '` = "')}")`
84
- : undefined;
85
- const setAccept = acceptHeader ? `accept("${escapeForDoubleQuotes(acceptHeader)}")` : undefined;
86
- const setContentType = `content_type("${escapeForDoubleQuotes((_b = postData === null || postData === void 0 ? void 0 : postData.mimeType) !== null && _b !== void 0 ? _b : 'application/octet-stream')}")`;
87
- const otherHeaders = Object.entries(allHeaders)
88
- // These headers are all handled separately:
89
- .filter(([key]) => !['cookie', 'accept', 'content-type'].includes(key.toLowerCase()))
90
- .map(([key, value]) => `'${key}' = '${escapeForSingleQuotes(value)}'`)
91
- .join(', ');
92
- const setHeaders = otherHeaders ? `add_headers(${otherHeaders})` : undefined;
93
- // Construct request
94
- let request = `response <- VERB("${method}", url`;
95
- if (payload) {
96
- request += ', body = payload';
97
- }
98
- if (queryString.length) {
99
- request += ', query = queryString';
100
- }
101
- const headerAdditions = [setHeaders, setContentType, setAccept, setCookies].filter((x) => !!x).join(', ');
102
- if (headerAdditions) {
103
- request += `, ${headerAdditions}`;
104
- }
105
- if (postData && (postData.text || postData.jsonObj || postData.params)) {
106
- request += ', encode = encode';
107
- }
108
- request += ')';
109
- push(request);
110
- blank();
111
- // Print response
112
- push('content(response, "text")');
113
- return join();
114
- },
115
- };
@@ -1,3 +0,0 @@
1
- import type { Client } from '../../../../httpsnippet-lite/targets/target.js';
2
- export declare const native: Client;
3
- //# sourceMappingURL=client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../src/httpsnippet-lite/targets/ruby/native/client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAA;AAE/D,eAAO,MAAM,MAAM,EAAE,MAkEpB,CAAA"}
@@ -1,67 +0,0 @@
1
- import { CodeBuilder } from '../../../../httpsnippet-lite/helpers/code-builder.js';
2
- import { escapeForSingleQuotes } from '../../../../httpsnippet-lite/helpers/escape.js';
3
- export const native = {
4
- info: {
5
- key: 'native',
6
- title: 'net::http',
7
- link: 'http://ruby-doc.org/stdlib-2.2.1/libdoc/net/http/rdoc/Net/HTTP.html',
8
- description: 'Ruby HTTP client',
9
- },
10
- convert: ({ uriObj, method: rawMethod, fullUrl, postData, allHeaders }, options = {}) => {
11
- const { insecureSkipVerify = false } = options;
12
- const { push, blank, join } = new CodeBuilder();
13
- push("require 'uri'");
14
- push("require 'net/http'");
15
- blank();
16
- // To support custom methods we check for the supported methods
17
- // and if doesn't exist then we build a custom class for it
18
- const method = rawMethod.toUpperCase();
19
- const methods = [
20
- 'GET',
21
- 'POST',
22
- 'HEAD',
23
- 'DELETE',
24
- 'PATCH',
25
- 'PUT',
26
- 'OPTIONS',
27
- 'COPY',
28
- 'LOCK',
29
- 'UNLOCK',
30
- 'MOVE',
31
- 'TRACE',
32
- ];
33
- const capMethod = method.charAt(0) + method.substring(1).toLowerCase();
34
- if (!methods.includes(method)) {
35
- push(`class Net::HTTP::${capMethod} < Net::HTTPRequest`);
36
- push(` METHOD = '${method.toUpperCase()}'`);
37
- push(` REQUEST_HAS_BODY = '${(postData === null || postData === void 0 ? void 0 : postData.text) ? 'true' : 'false'}'`);
38
- push(' RESPONSE_HAS_BODY = true');
39
- push('end');
40
- blank();
41
- }
42
- push(`url = URI("${fullUrl}")`);
43
- blank();
44
- push('http = Net::HTTP.new(url.host, url.port)');
45
- if (uriObj.protocol === 'https:') {
46
- push('http.use_ssl = true');
47
- if (insecureSkipVerify) {
48
- push('http.verify_mode = OpenSSL::SSL::VERIFY_NONE');
49
- }
50
- }
51
- blank();
52
- push(`request = Net::HTTP::${capMethod}.new(url)`);
53
- const headers = Object.keys(allHeaders);
54
- if (headers.length) {
55
- headers.forEach((key) => {
56
- push(`request["${key}"] = '${escapeForSingleQuotes(allHeaders[key])}'`);
57
- });
58
- }
59
- if (postData === null || postData === void 0 ? void 0 : postData.text) {
60
- push(`request.body = ${JSON.stringify(postData.text)}`);
61
- }
62
- blank();
63
- push('response = http.request(request)');
64
- push('puts response.read_body');
65
- return join();
66
- },
67
- };
@@ -1,6 +0,0 @@
1
- import type { Plugin } from '@scalar/types/snippetz';
2
- /**
3
- * r/httr
4
- */
5
- export declare const rHttr: Plugin;
6
- //# sourceMappingURL=httr.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"httr.d.ts","sourceRoot":"","sources":["../../../../src/plugins/r/httr/httr.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAKpD;;GAEG;AACH,eAAO,MAAM,KAAK,EAAE,MAQnB,CAAA"}
@@ -1,14 +0,0 @@
1
- import { httr } from '../../../httpsnippet-lite/targets/r/httr/client.js';
2
- import { convertWithHttpSnippetLite } from '../../../utils/convertWithHttpSnippetLite.js';
3
- /**
4
- * r/httr
5
- */
6
- export const rHttr = {
7
- target: 'r',
8
- client: 'httr',
9
- title: 'httr',
10
- generate(request) {
11
- // TODO: Write an own converter
12
- return convertWithHttpSnippetLite(httr, request);
13
- },
14
- };
@@ -1,2 +0,0 @@
1
- export { rHttr } from './httr.js';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/r/httr/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA"}
@@ -1 +0,0 @@
1
- export { rHttr } from './httr.js';