@scalar/snippetz 0.9.12 → 0.9.13
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.
- package/dist/httpsnippet-lite/helpers/shell.d.ts +0 -1
- package/dist/httpsnippet-lite/helpers/shell.d.ts.map +1 -1
- package/dist/httpsnippet-lite/helpers/shell.js +0 -1
- package/dist/plugins/clojure/clj_http/clj_http.d.ts.map +1 -1
- package/dist/plugins/clojure/clj_http/clj_http.js +197 -5
- package/dist/plugins/csharp/restsharp/restsharp.d.ts.map +1 -1
- package/dist/plugins/csharp/restsharp/restsharp.js +134 -5
- package/dist/plugins/kotlin/okhttp/okhttp.d.ts.map +1 -1
- package/dist/plugins/kotlin/okhttp/okhttp.js +65 -5
- package/dist/plugins/objc/nsurlsession/nsurlsession.d.ts.map +1 -1
- package/dist/plugins/objc/nsurlsession/nsurlsession.js +124 -5
- package/dist/plugins/shell/curl/curl.d.ts.map +1 -1
- package/dist/plugins/shell/curl/curl.js +8 -5
- package/dist/plugins/shell/wget/wget.d.ts.map +1 -1
- package/dist/plugins/shell/wget/wget.js +103 -5
- package/package.json +2 -2
- package/dist/httpsnippet-lite/targets/clojure/clj_http/client.d.ts +0 -12
- package/dist/httpsnippet-lite/targets/clojure/clj_http/client.d.ts.map +0 -1
- package/dist/httpsnippet-lite/targets/clojure/clj_http/client.js +0 -186
- package/dist/httpsnippet-lite/targets/csharp/restsharp/client.d.ts +0 -3
- package/dist/httpsnippet-lite/targets/csharp/restsharp/client.d.ts.map +0 -1
- package/dist/httpsnippet-lite/targets/csharp/restsharp/client.js +0 -36
- package/dist/httpsnippet-lite/targets/kotlin/okhttp/client.d.ts +0 -12
- package/dist/httpsnippet-lite/targets/kotlin/okhttp/client.d.ts.map +0 -1
- package/dist/httpsnippet-lite/targets/kotlin/okhttp/client.js +0 -87
- package/dist/httpsnippet-lite/targets/objc/helpers.d.ts +0 -21
- package/dist/httpsnippet-lite/targets/objc/helpers.d.ts.map +0 -1
- package/dist/httpsnippet-lite/targets/objc/helpers.js +0 -57
- package/dist/httpsnippet-lite/targets/objc/nsurlsession/client.d.ts +0 -12
- package/dist/httpsnippet-lite/targets/objc/nsurlsession/client.d.ts.map +0 -1
- package/dist/httpsnippet-lite/targets/objc/nsurlsession/client.js +0 -125
- package/dist/httpsnippet-lite/targets/shell/wget/client.d.ts +0 -12
- package/dist/httpsnippet-lite/targets/shell/wget/client.d.ts.map +0 -1
- package/dist/httpsnippet-lite/targets/shell/wget/client.js +0 -49
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description
|
|
3
|
-
* HTTP code snippet generator for Objective-C using NSURLSession.
|
|
4
|
-
*
|
|
5
|
-
* @author
|
|
6
|
-
* @thibaultCha
|
|
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 { nsDeclaration } from '../../../../httpsnippet-lite/targets/objc/helpers.js';
|
|
12
|
-
export const nsurlsession = {
|
|
13
|
-
info: {
|
|
14
|
-
key: 'nsurlsession',
|
|
15
|
-
title: 'NSURLSession',
|
|
16
|
-
link: 'https://developer.apple.com/library/mac/documentation/Foundation/Reference/NSURLSession_class/index.html',
|
|
17
|
-
description: "Foundation's NSURLSession request",
|
|
18
|
-
},
|
|
19
|
-
convert: ({ allHeaders, postData, method, fullUrl }, options) => {
|
|
20
|
-
let _a;
|
|
21
|
-
const opts = {
|
|
22
|
-
indent: ' ',
|
|
23
|
-
pretty: true,
|
|
24
|
-
timeout: 10,
|
|
25
|
-
...options,
|
|
26
|
-
};
|
|
27
|
-
const { push, join, blank } = new CodeBuilder({ indent: opts.indent });
|
|
28
|
-
// Markers for headers to be created as literal objects and later be set on the NSURLRequest if exist
|
|
29
|
-
const req = {
|
|
30
|
-
hasHeaders: false,
|
|
31
|
-
hasBody: false,
|
|
32
|
-
};
|
|
33
|
-
// We just want to make sure people understand that is the only dependency
|
|
34
|
-
push('#import <Foundation/Foundation.h>');
|
|
35
|
-
if (Object.keys(allHeaders).length) {
|
|
36
|
-
req.hasHeaders = true;
|
|
37
|
-
blank();
|
|
38
|
-
push(nsDeclaration('NSDictionary', 'headers', allHeaders, opts.pretty));
|
|
39
|
-
}
|
|
40
|
-
if (postData && (postData.text || postData.jsonObj || postData.params)) {
|
|
41
|
-
req.hasBody = true;
|
|
42
|
-
switch (postData.mimeType) {
|
|
43
|
-
case 'application/x-www-form-urlencoded':
|
|
44
|
-
if ((_a = postData.params) === null || _a === void 0 ? void 0 : _a.length) {
|
|
45
|
-
// By appending parameters one by one in the resulting snippet,
|
|
46
|
-
// we make it easier for the user to edit it according to his or her needs after pasting.
|
|
47
|
-
// The user can just add/remove lines adding/removing body parameters.
|
|
48
|
-
blank();
|
|
49
|
-
const [head, ...tail] = postData.params;
|
|
50
|
-
push(`NSMutableData *postData = [[NSMutableData alloc] initWithData:[@"${head.name}=${head.value}" dataUsingEncoding:NSUTF8StringEncoding]];`);
|
|
51
|
-
tail.forEach(({ name, value }) => {
|
|
52
|
-
push(`[postData appendData:[@"&${name}=${value}" dataUsingEncoding:NSUTF8StringEncoding]];`);
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
req.hasBody = false;
|
|
57
|
-
}
|
|
58
|
-
break;
|
|
59
|
-
case 'application/json':
|
|
60
|
-
if (postData.jsonObj) {
|
|
61
|
-
push(nsDeclaration('NSDictionary', 'parameters', postData.jsonObj, opts.pretty));
|
|
62
|
-
blank();
|
|
63
|
-
push('NSData *postData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:nil];');
|
|
64
|
-
}
|
|
65
|
-
break;
|
|
66
|
-
case 'multipart/form-data':
|
|
67
|
-
// By appending multipart parameters one by one in the resulting snippet,
|
|
68
|
-
// we make it easier for the user to edit it according to his or her needs after pasting.
|
|
69
|
-
// The user can just edit the parameters NSDictionary or put this part of a snippet in a multipart builder method.
|
|
70
|
-
push(nsDeclaration('NSArray', 'parameters', postData.params || [], opts.pretty));
|
|
71
|
-
push(`NSString *boundary = @"${postData.boundary}";`);
|
|
72
|
-
blank();
|
|
73
|
-
push('NSError *error;');
|
|
74
|
-
push('NSMutableString *body = [NSMutableString string];');
|
|
75
|
-
push('for (NSDictionary *param in parameters) {');
|
|
76
|
-
push('[body appendFormat:@"--%@\\r\\n", boundary];', 1);
|
|
77
|
-
push('if (param[@"fileName"]) {', 1);
|
|
78
|
-
push('[body appendFormat:@"Content-Disposition:form-data; name=\\"%@\\"; filename=\\"%@\\"\\r\\n", param[@"name"], param[@"fileName"]];', 2);
|
|
79
|
-
push('[body appendFormat:@"Content-Type: %@\\r\\n\\r\\n", param[@"contentType"]];', 2);
|
|
80
|
-
push('[body appendFormat:@"%@", [NSString stringWithContentsOfFile:param[@"fileName"] encoding:NSUTF8StringEncoding error:&error]];', 2);
|
|
81
|
-
push('if (error) {', 2);
|
|
82
|
-
push('NSLog(@"%@", error);', 3);
|
|
83
|
-
push('}', 2);
|
|
84
|
-
push('} else {', 1);
|
|
85
|
-
push('[body appendFormat:@"Content-Disposition:form-data; name=\\"%@\\"\\r\\n\\r\\n", param[@"name"]];', 2);
|
|
86
|
-
push('[body appendFormat:@"%@", param[@"value"]];', 2);
|
|
87
|
-
push('}', 1);
|
|
88
|
-
push('}');
|
|
89
|
-
push('[body appendFormat:@"\\r\\n--%@--\\r\\n", boundary];');
|
|
90
|
-
push('NSData *postData = [body dataUsingEncoding:NSUTF8StringEncoding];');
|
|
91
|
-
break;
|
|
92
|
-
default:
|
|
93
|
-
blank();
|
|
94
|
-
push(`NSData *postData = [[NSData alloc] initWithData:[@"${postData.text}" dataUsingEncoding:NSUTF8StringEncoding]];`);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
blank();
|
|
98
|
-
push(`NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"${fullUrl}"]`);
|
|
99
|
-
// NSURLRequestUseProtocolCachePolicy is the default policy, let's just always set it to avoid confusion.
|
|
100
|
-
push(' cachePolicy:NSURLRequestUseProtocolCachePolicy');
|
|
101
|
-
push(` timeoutInterval:${opts.timeout.toFixed(1)}];`);
|
|
102
|
-
push(`[request setHTTPMethod:@"${method}"];`);
|
|
103
|
-
if (req.hasHeaders) {
|
|
104
|
-
push('[request setAllHTTPHeaderFields:headers];');
|
|
105
|
-
}
|
|
106
|
-
if (req.hasBody) {
|
|
107
|
-
push('[request setHTTPBody:postData];');
|
|
108
|
-
}
|
|
109
|
-
blank();
|
|
110
|
-
// Retrieving the shared session will be less verbose than creating a new one.
|
|
111
|
-
push('NSURLSession *session = [NSURLSession sharedSession];');
|
|
112
|
-
push('NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request');
|
|
113
|
-
push(' completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {');
|
|
114
|
-
push(' if (error) {', 1);
|
|
115
|
-
push(' NSLog(@"%@", error);', 2);
|
|
116
|
-
push(' } else {', 1);
|
|
117
|
-
// Casting the NSURLResponse to NSHTTPURLResponse so the user can see the status .
|
|
118
|
-
push(' NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;', 2);
|
|
119
|
-
push(' NSLog(@"%@", httpResponse);', 2);
|
|
120
|
-
push(' }', 1);
|
|
121
|
-
push(' }];');
|
|
122
|
-
push('[dataTask resume];');
|
|
123
|
-
return join();
|
|
124
|
-
},
|
|
125
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description
|
|
3
|
-
* HTTP code snippet generator for the Shell using Wget.
|
|
4
|
-
*
|
|
5
|
-
* @author
|
|
6
|
-
* @AhmadNassri
|
|
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 wget: Client;
|
|
12
|
-
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../src/httpsnippet-lite/targets/shell/wget/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAA;AAE/D,eAAO,MAAM,IAAI,EAAE,MAoClB,CAAA"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description
|
|
3
|
-
* HTTP code snippet generator for the Shell using Wget.
|
|
4
|
-
*
|
|
5
|
-
* @author
|
|
6
|
-
* @AhmadNassri
|
|
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 { shellEscape, shellQuote } from '../../../../httpsnippet-lite/helpers/shell.js';
|
|
12
|
-
export const wget = {
|
|
13
|
-
info: {
|
|
14
|
-
key: 'wget',
|
|
15
|
-
title: 'Wget',
|
|
16
|
-
link: 'https://www.gnu.org/software/wget/',
|
|
17
|
-
description: 'a free software package for retrieving files using HTTP, HTTPS',
|
|
18
|
-
},
|
|
19
|
-
convert: ({ method, postData, allHeaders, fullUrl }, options) => {
|
|
20
|
-
const opts = {
|
|
21
|
-
indent: ' ',
|
|
22
|
-
short: false,
|
|
23
|
-
verbose: false,
|
|
24
|
-
...options,
|
|
25
|
-
};
|
|
26
|
-
const { push, join } = new CodeBuilder({
|
|
27
|
-
indent: opts.indent,
|
|
28
|
-
// @ts-expect-error SEEMS LEGIT
|
|
29
|
-
join: opts.indent !== false ? ` \\\n${opts.indent}` : ' ',
|
|
30
|
-
});
|
|
31
|
-
if (opts.verbose) {
|
|
32
|
-
push(`wget ${opts.short ? '-v' : '--verbose'}`);
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
push(`wget ${opts.short ? '-q' : '--quiet'}`);
|
|
36
|
-
}
|
|
37
|
-
push(`--method ${shellQuote(method)}`);
|
|
38
|
-
Object.keys(allHeaders).forEach((key) => {
|
|
39
|
-
const header = `${key}: ${allHeaders[key]}`;
|
|
40
|
-
push(`--header ${shellQuote(header)}`);
|
|
41
|
-
});
|
|
42
|
-
if (postData === null || postData === void 0 ? void 0 : postData.text) {
|
|
43
|
-
push(`--body-data ${shellEscape(shellQuote(postData.text))}`);
|
|
44
|
-
}
|
|
45
|
-
push(opts.short ? '-O' : '--output-document');
|
|
46
|
-
push(`- ${shellQuote(fullUrl)}`);
|
|
47
|
-
return join();
|
|
48
|
-
},
|
|
49
|
-
};
|