@scalar/snippetz 0.7.4 → 0.7.6
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/clients/index.js +168 -169
- package/dist/httpsnippet-lite/helpers/code-builder.js +86 -74
- package/dist/httpsnippet-lite/helpers/escape.js +69 -44
- package/dist/httpsnippet-lite/helpers/headers.js +17 -14
- package/dist/httpsnippet-lite/helpers/reducer.js +1 -1
- package/dist/httpsnippet-lite/helpers/shell.js +13 -13
- package/dist/httpsnippet-lite/helpers/snippet-request.js +1 -1
- package/dist/httpsnippet-lite/helpers/url.js +4 -8
- package/dist/httpsnippet-lite/targets/c/libcurl/client.js +69 -67
- package/dist/httpsnippet-lite/targets/clojure/clj_http/client.js +165 -154
- package/dist/httpsnippet-lite/targets/csharp/restsharp/client.js +35 -38
- package/dist/httpsnippet-lite/targets/go/native/client.js +151 -147
- package/dist/httpsnippet-lite/targets/java/asynchttp/client.js +32 -35
- package/dist/httpsnippet-lite/targets/java/nethttp/client.js +40 -39
- package/dist/httpsnippet-lite/targets/java/okhttp/client.js +83 -73
- package/dist/httpsnippet-lite/targets/java/unirest/client.js +41 -34
- package/dist/httpsnippet-lite/targets/javascript/axios/client.js +81 -76
- package/dist/httpsnippet-lite/targets/javascript/jquery/client.js +77 -71
- package/dist/httpsnippet-lite/targets/javascript/xhr/client.js +73 -71
- package/dist/httpsnippet-lite/targets/kotlin/okhttp/client.js +83 -73
- package/dist/httpsnippet-lite/targets/node/axios/client.js +74 -69
- package/dist/httpsnippet-lite/targets/objc/helpers.js +52 -33
- package/dist/httpsnippet-lite/targets/objc/nsurlsession/client.js +123 -121
- package/dist/httpsnippet-lite/targets/ocaml/cohttp/client.js +60 -49
- package/dist/httpsnippet-lite/targets/powershell/common.js +46 -56
- package/dist/httpsnippet-lite/targets/powershell/restmethod/client.js +9 -13
- package/dist/httpsnippet-lite/targets/powershell/webrequest/client.js +9 -13
- package/dist/httpsnippet-lite/targets/python/python3/client.js +85 -68
- package/dist/httpsnippet-lite/targets/r/httr/client.js +114 -95
- package/dist/httpsnippet-lite/targets/ruby/native/client.js +66 -70
- package/dist/httpsnippet-lite/targets/shell/httpie/client.js +121 -107
- package/dist/httpsnippet-lite/targets/shell/wget/client.js +48 -43
- package/dist/httpsnippet-lite/targets/swift/helpers.js +62 -44
- package/dist/httpsnippet-lite/targets/swift/nsurlsession/client.js +126 -112
- package/dist/httpsnippet-lite/targets/target.js +1 -1
- package/dist/index.js +2 -9
- package/dist/libs/http.js +68 -56
- package/dist/libs/javascript.js +77 -60
- package/dist/libs/php.js +59 -49
- package/dist/libs/rust.js +60 -33
- package/dist/libs/shell.js +14 -5
- package/dist/plugins/c/libcurl/index.js +1 -5
- package/dist/plugins/c/libcurl/libcurl.js +13 -13
- package/dist/plugins/clojure/clj_http/clj_http.js +13 -13
- package/dist/plugins/clojure/clj_http/index.js +1 -5
- package/dist/plugins/csharp/httpclient/httpclient.js +206 -150
- package/dist/plugins/csharp/httpclient/index.js +1 -5
- package/dist/plugins/csharp/restsharp/index.js +1 -5
- package/dist/plugins/csharp/restsharp/restsharp.js +13 -13
- package/dist/plugins/dart/http/http.js +95 -93
- package/dist/plugins/dart/http/index.js +1 -5
- package/dist/plugins/fsharp/httpclient/httpclient.js +169 -122
- package/dist/plugins/fsharp/httpclient/index.js +1 -5
- package/dist/plugins/go/native/index.js +1 -5
- package/dist/plugins/go/native/native.js +13 -13
- package/dist/plugins/http/http11/http11.d.ts.map +1 -1
- package/dist/plugins/http/http11/http11.js +104 -85
- package/dist/plugins/http/http11/index.js +1 -5
- package/dist/plugins/java/asynchttp/asynchttp.js +13 -13
- package/dist/plugins/java/asynchttp/index.js +1 -5
- package/dist/plugins/java/nethttp/index.js +1 -5
- package/dist/plugins/java/nethttp/nethttp.js +13 -13
- package/dist/plugins/java/okhttp/index.js +1 -5
- package/dist/plugins/java/okhttp/okhttp.js +13 -13
- package/dist/plugins/java/unirest/index.js +1 -5
- package/dist/plugins/java/unirest/unirest.js +13 -13
- package/dist/plugins/js/axios/axios.js +13 -13
- package/dist/plugins/js/axios/index.js +1 -5
- package/dist/plugins/js/fetch/fetch.js +82 -68
- package/dist/plugins/js/fetch/index.js +1 -5
- package/dist/plugins/js/jquery/index.js +1 -5
- package/dist/plugins/js/jquery/jquery.js +13 -13
- package/dist/plugins/js/ofetch/index.js +1 -5
- package/dist/plugins/js/ofetch/ofetch.js +61 -48
- package/dist/plugins/js/xhr/index.js +1 -5
- package/dist/plugins/js/xhr/xhr.js +13 -13
- package/dist/plugins/kotlin/okhttp/index.js +1 -5
- package/dist/plugins/kotlin/okhttp/okhttp.js +13 -13
- package/dist/plugins/node/axios/axios.js +13 -13
- package/dist/plugins/node/axios/index.js +1 -5
- package/dist/plugins/node/fetch/fetch.js +86 -74
- package/dist/plugins/node/fetch/index.js +1 -5
- package/dist/plugins/node/ofetch/index.js +1 -5
- package/dist/plugins/node/ofetch/ofetch.js +61 -48
- package/dist/plugins/node/undici/index.js +1 -5
- package/dist/plugins/node/undici/undici.js +60 -47
- package/dist/plugins/objc/nsurlsession/index.js +1 -5
- package/dist/plugins/objc/nsurlsession/nsurlsession.js +13 -13
- package/dist/plugins/ocaml/cohttp/cohttp.js +13 -13
- package/dist/plugins/ocaml/cohttp/index.js +1 -5
- package/dist/plugins/php/curl/curl.js +143 -101
- package/dist/plugins/php/curl/index.js +1 -5
- package/dist/plugins/php/guzzle/guzzle.d.ts.map +1 -1
- package/dist/plugins/php/guzzle/guzzle.js +109 -83
- package/dist/plugins/php/guzzle/index.js +1 -5
- package/dist/plugins/powershell/restmethod/index.js +1 -5
- package/dist/plugins/powershell/restmethod/restmethod.js +13 -13
- package/dist/plugins/powershell/webrequest/index.js +1 -5
- package/dist/plugins/powershell/webrequest/webrequest.js +13 -13
- package/dist/plugins/python/httpx/async.js +17 -15
- package/dist/plugins/python/httpx/index.js +2 -7
- package/dist/plugins/python/httpx/sync.js +11 -12
- package/dist/plugins/python/python3/index.js +1 -5
- package/dist/plugins/python/python3/python3.js +13 -13
- package/dist/plugins/python/requests/index.js +1 -5
- package/dist/plugins/python/requests/requests.js +11 -12
- package/dist/plugins/python/requestsLike.d.ts.map +1 -1
- package/dist/plugins/python/requestsLike.js +145 -112
- package/dist/plugins/r/httr/httr.js +13 -13
- package/dist/plugins/r/httr/index.js +1 -5
- package/dist/plugins/ruby/native/index.js +1 -5
- package/dist/plugins/ruby/native/native.js +13 -13
- package/dist/plugins/rust/reqwest/index.js +1 -5
- package/dist/plugins/rust/reqwest/reqwest.js +126 -83
- package/dist/plugins/shell/curl/curl.d.ts.map +1 -1
- package/dist/plugins/shell/curl/curl.js +129 -97
- package/dist/plugins/shell/curl/index.js +1 -5
- package/dist/plugins/shell/httpie/httpie.js +13 -13
- package/dist/plugins/shell/httpie/index.js +1 -5
- package/dist/plugins/shell/wget/index.js +1 -5
- package/dist/plugins/shell/wget/wget.js +13 -13
- package/dist/plugins/swift/nsurlsession/index.js +1 -5
- package/dist/plugins/swift/nsurlsession/nsurlsession.js +13 -13
- package/dist/snippetz.js +25 -28
- package/dist/utils/convertWithHttpSnippetLite.js +100 -96
- package/dist/utils/index.js +1 -5
- package/package.json +8 -12
- package/dist/clients/index.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/code-builder.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/escape.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/headers.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/reducer.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/shell.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/snippet-request.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/url.js.map +0 -7
- package/dist/httpsnippet-lite/targets/c/libcurl/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/clojure/clj_http/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/csharp/restsharp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/go/native/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/java/asynchttp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/java/nethttp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/java/okhttp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/java/unirest/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/javascript/axios/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/javascript/jquery/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/javascript/xhr/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/kotlin/okhttp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/node/axios/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/objc/helpers.js.map +0 -7
- package/dist/httpsnippet-lite/targets/objc/nsurlsession/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/ocaml/cohttp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/powershell/common.js.map +0 -7
- package/dist/httpsnippet-lite/targets/powershell/restmethod/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/powershell/webrequest/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/python/python3/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/r/httr/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/ruby/native/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/shell/httpie/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/shell/wget/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/swift/helpers.js.map +0 -7
- package/dist/httpsnippet-lite/targets/swift/nsurlsession/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/target.js.map +0 -7
- package/dist/index.js.map +0 -7
- package/dist/libs/http.js.map +0 -7
- package/dist/libs/javascript.js.map +0 -7
- package/dist/libs/php.js.map +0 -7
- package/dist/libs/rust.js.map +0 -7
- package/dist/libs/shell.js.map +0 -7
- package/dist/plugins/c/libcurl/index.js.map +0 -7
- package/dist/plugins/c/libcurl/libcurl.js.map +0 -7
- package/dist/plugins/clojure/clj_http/clj_http.js.map +0 -7
- package/dist/plugins/clojure/clj_http/index.js.map +0 -7
- package/dist/plugins/csharp/httpclient/httpclient.js.map +0 -7
- package/dist/plugins/csharp/httpclient/index.js.map +0 -7
- package/dist/plugins/csharp/restsharp/index.js.map +0 -7
- package/dist/plugins/csharp/restsharp/restsharp.js.map +0 -7
- package/dist/plugins/dart/http/http.js.map +0 -7
- package/dist/plugins/dart/http/index.js.map +0 -7
- package/dist/plugins/fsharp/httpclient/httpclient.js.map +0 -7
- package/dist/plugins/fsharp/httpclient/index.js.map +0 -7
- package/dist/plugins/go/native/index.js.map +0 -7
- package/dist/plugins/go/native/native.js.map +0 -7
- package/dist/plugins/http/http11/http11.js.map +0 -7
- package/dist/plugins/http/http11/index.js.map +0 -7
- package/dist/plugins/java/asynchttp/asynchttp.js.map +0 -7
- package/dist/plugins/java/asynchttp/index.js.map +0 -7
- package/dist/plugins/java/nethttp/index.js.map +0 -7
- package/dist/plugins/java/nethttp/nethttp.js.map +0 -7
- package/dist/plugins/java/okhttp/index.js.map +0 -7
- package/dist/plugins/java/okhttp/okhttp.js.map +0 -7
- package/dist/plugins/java/unirest/index.js.map +0 -7
- package/dist/plugins/java/unirest/unirest.js.map +0 -7
- package/dist/plugins/js/axios/axios.js.map +0 -7
- package/dist/plugins/js/axios/index.js.map +0 -7
- package/dist/plugins/js/fetch/fetch.js.map +0 -7
- package/dist/plugins/js/fetch/index.js.map +0 -7
- package/dist/plugins/js/jquery/index.js.map +0 -7
- package/dist/plugins/js/jquery/jquery.js.map +0 -7
- package/dist/plugins/js/ofetch/index.js.map +0 -7
- package/dist/plugins/js/ofetch/ofetch.js.map +0 -7
- package/dist/plugins/js/xhr/index.js.map +0 -7
- package/dist/plugins/js/xhr/xhr.js.map +0 -7
- package/dist/plugins/kotlin/okhttp/index.js.map +0 -7
- package/dist/plugins/kotlin/okhttp/okhttp.js.map +0 -7
- package/dist/plugins/node/axios/axios.js.map +0 -7
- package/dist/plugins/node/axios/index.js.map +0 -7
- package/dist/plugins/node/fetch/fetch.js.map +0 -7
- package/dist/plugins/node/fetch/index.js.map +0 -7
- package/dist/plugins/node/ofetch/index.js.map +0 -7
- package/dist/plugins/node/ofetch/ofetch.js.map +0 -7
- package/dist/plugins/node/undici/index.js.map +0 -7
- package/dist/plugins/node/undici/undici.js.map +0 -7
- package/dist/plugins/objc/nsurlsession/index.js.map +0 -7
- package/dist/plugins/objc/nsurlsession/nsurlsession.js.map +0 -7
- package/dist/plugins/ocaml/cohttp/cohttp.js.map +0 -7
- package/dist/plugins/ocaml/cohttp/index.js.map +0 -7
- package/dist/plugins/php/curl/curl.js.map +0 -7
- package/dist/plugins/php/curl/index.js.map +0 -7
- package/dist/plugins/php/guzzle/guzzle.js.map +0 -7
- package/dist/plugins/php/guzzle/index.js.map +0 -7
- package/dist/plugins/powershell/restmethod/index.js.map +0 -7
- package/dist/plugins/powershell/restmethod/restmethod.js.map +0 -7
- package/dist/plugins/powershell/webrequest/index.js.map +0 -7
- package/dist/plugins/powershell/webrequest/webrequest.js.map +0 -7
- package/dist/plugins/python/httpx/async.js.map +0 -7
- package/dist/plugins/python/httpx/index.js.map +0 -7
- package/dist/plugins/python/httpx/sync.js.map +0 -7
- package/dist/plugins/python/python3/index.js.map +0 -7
- package/dist/plugins/python/python3/python3.js.map +0 -7
- package/dist/plugins/python/requests/index.js.map +0 -7
- package/dist/plugins/python/requests/requests.js.map +0 -7
- package/dist/plugins/python/requestsLike.js.map +0 -7
- package/dist/plugins/r/httr/httr.js.map +0 -7
- package/dist/plugins/r/httr/index.js.map +0 -7
- package/dist/plugins/ruby/native/index.js.map +0 -7
- package/dist/plugins/ruby/native/native.js.map +0 -7
- package/dist/plugins/rust/reqwest/index.js.map +0 -7
- package/dist/plugins/rust/reqwest/reqwest.js.map +0 -7
- package/dist/plugins/shell/curl/curl.js.map +0 -7
- package/dist/plugins/shell/curl/index.js.map +0 -7
- package/dist/plugins/shell/httpie/httpie.js.map +0 -7
- package/dist/plugins/shell/httpie/index.js.map +0 -7
- package/dist/plugins/shell/wget/index.js.map +0 -7
- package/dist/plugins/shell/wget/wget.js.map +0 -7
- package/dist/plugins/swift/nsurlsession/index.js.map +0 -7
- package/dist/plugins/swift/nsurlsession/nsurlsession.js.map +0 -7
- package/dist/snippetz.js.map +0 -7
- package/dist/utils/convertWithHttpSnippetLite.js.map +0 -7
- package/dist/utils/index.js.map +0 -7
|
@@ -1,123 +1,125 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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;
|
|
34
37
|
blank();
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
+
},
|
|
122
125
|
};
|
|
123
|
-
//# sourceMappingURL=client.js.map
|
|
@@ -1,50 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
push(`
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* HTTP code snippet generator for OCaml using CoHTTP.
|
|
4
|
+
*
|
|
5
|
+
* @author
|
|
6
|
+
* @SGrondin
|
|
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 cohttp = {
|
|
13
|
+
info: {
|
|
14
|
+
key: 'cohttp',
|
|
15
|
+
title: 'CoHTTP',
|
|
16
|
+
link: 'https://github.com/mirage/ocaml-cohttp',
|
|
17
|
+
description: 'Cohttp is a very lightweight HTTP server using Lwt or Async for OCaml',
|
|
18
|
+
},
|
|
19
|
+
convert: ({ fullUrl, allHeaders, postData, method }, options) => {
|
|
20
|
+
const opts = {
|
|
21
|
+
indent: ' ',
|
|
22
|
+
...options,
|
|
23
|
+
};
|
|
24
|
+
const methods = ['get', 'post', 'head', 'delete', 'patch', 'put', 'options'];
|
|
25
|
+
const { push, blank, join } = new CodeBuilder({ indent: opts.indent });
|
|
26
|
+
push('open Cohttp_lwt_unix');
|
|
27
|
+
push('open Cohttp');
|
|
28
|
+
push('open Lwt');
|
|
29
|
+
blank();
|
|
30
|
+
push(`let uri = Uri.of_string "${fullUrl}" in`);
|
|
31
|
+
// Add headers, including the cookies
|
|
32
|
+
const headers = Object.keys(allHeaders);
|
|
33
|
+
if (headers.length === 1) {
|
|
34
|
+
push(`let headers = Header.add (Header.init ()) "${headers[0]}" "${escapeForDoubleQuotes(allHeaders[headers[0]])}" in`);
|
|
35
|
+
}
|
|
36
|
+
else if (headers.length > 1) {
|
|
37
|
+
push('let headers = Header.add_list (Header.init ()) [');
|
|
38
|
+
headers.forEach((key) => {
|
|
39
|
+
push(`("${key}", "${escapeForDoubleQuotes(allHeaders[key])}");`, 1);
|
|
40
|
+
});
|
|
41
|
+
push('] in');
|
|
42
|
+
}
|
|
43
|
+
// Add body
|
|
44
|
+
if (postData === null || postData === void 0 ? void 0 : postData.text) {
|
|
45
|
+
// Just text
|
|
46
|
+
push(`let body = Cohttp_lwt_body.of_string ${JSON.stringify(postData.text)} in`);
|
|
47
|
+
}
|
|
48
|
+
// Do the request
|
|
49
|
+
blank();
|
|
50
|
+
const h = headers.length ? '~headers ' : '';
|
|
51
|
+
const b = (postData === null || postData === void 0 ? void 0 : postData.text) ? '~body ' : '';
|
|
52
|
+
const m = methods.includes(method.toLowerCase())
|
|
53
|
+
? `\`${method.toUpperCase()}`
|
|
54
|
+
: `(Code.method_of_string "${method}")`;
|
|
55
|
+
push(`Client.call ${h}${b}${m} uri`);
|
|
56
|
+
// Catch result
|
|
57
|
+
push('>>= fun (res, body_stream) ->');
|
|
58
|
+
push('(* Do stuff with the result *)', 1);
|
|
59
|
+
return join();
|
|
60
|
+
},
|
|
46
61
|
};
|
|
47
|
-
export {
|
|
48
|
-
cohttp
|
|
49
|
-
};
|
|
50
|
-
//# sourceMappingURL=client.js.map
|
|
@@ -1,58 +1,48 @@
|
|
|
1
|
-
import { CodeBuilder } from
|
|
2
|
-
import { escapeString } from
|
|
3
|
-
import { getHeader } from
|
|
4
|
-
const generatePowershellConvert = (command) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
fullUrl,
|
|
11
|
-
postData,
|
|
12
|
-
allHeaders
|
|
13
|
-
}) => {
|
|
14
|
-
const { push, join } = new CodeBuilder();
|
|
15
|
-
const methods = ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"];
|
|
16
|
-
if (!methods.includes(method.toUpperCase())) {
|
|
17
|
-
return "Method not supported";
|
|
18
|
-
}
|
|
19
|
-
const commandOptions = [];
|
|
20
|
-
const headers = Object.keys(headersObj);
|
|
21
|
-
if (headers.length) {
|
|
22
|
-
push("$headers=@{}");
|
|
23
|
-
headers.forEach((key) => {
|
|
24
|
-
if (key !== "connection") {
|
|
25
|
-
push(`$headers.Add("${key}", "${escapeString(headersObj[key], { escapeChar: "`" })}")`);
|
|
1
|
+
import { CodeBuilder } from '../../../httpsnippet-lite/helpers/code-builder.js';
|
|
2
|
+
import { escapeString } from '../../../httpsnippet-lite/helpers/escape.js';
|
|
3
|
+
import { getHeader } from '../../../httpsnippet-lite/helpers/headers.js';
|
|
4
|
+
export const generatePowershellConvert = (command) => {
|
|
5
|
+
const convert = ({ method, headersObj, cookies, uriObj, fullUrl, postData, allHeaders, }) => {
|
|
6
|
+
const { push, join } = new CodeBuilder();
|
|
7
|
+
const methods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'];
|
|
8
|
+
if (!methods.includes(method.toUpperCase())) {
|
|
9
|
+
return 'Method not supported';
|
|
26
10
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
11
|
+
const commandOptions = [];
|
|
12
|
+
// Add headers, including the cookies
|
|
13
|
+
const headers = Object.keys(headersObj);
|
|
14
|
+
// construct headers
|
|
15
|
+
if (headers.length) {
|
|
16
|
+
push('$headers=@{}');
|
|
17
|
+
headers.forEach((key) => {
|
|
18
|
+
if (key !== 'connection') {
|
|
19
|
+
// Not allowed
|
|
20
|
+
push(`$headers.Add("${key}", "${escapeString(headersObj[key], { escapeChar: '`' })}")`);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
commandOptions.push('-Headers $headers');
|
|
24
|
+
}
|
|
25
|
+
// construct cookies
|
|
26
|
+
if (cookies.length) {
|
|
27
|
+
push('$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession');
|
|
28
|
+
cookies.forEach((cookie) => {
|
|
29
|
+
push('$cookie = New-Object System.Net.Cookie');
|
|
30
|
+
push(`$cookie.Name = '${cookie.name}'`);
|
|
31
|
+
push(`$cookie.Value = '${cookie.value}'`);
|
|
32
|
+
push(`$cookie.Domain = '${uriObj.host}'`);
|
|
33
|
+
push('$session.Cookies.Add($cookie)');
|
|
34
|
+
});
|
|
35
|
+
commandOptions.push('-WebSession $session');
|
|
36
|
+
}
|
|
37
|
+
if (postData === null || postData === void 0 ? void 0 : postData.text) {
|
|
38
|
+
commandOptions.push(`-ContentType '${escapeString(getHeader(allHeaders, 'content-type'), {
|
|
39
|
+
delimiter: "'",
|
|
40
|
+
escapeChar: '`',
|
|
41
|
+
})}'`);
|
|
42
|
+
commandOptions.push(`-Body '${postData.text}'`);
|
|
43
|
+
}
|
|
44
|
+
push(`$response = ${command} -Uri '${fullUrl}' -Method ${method} ${commandOptions.join(' ')}`);
|
|
45
|
+
return join();
|
|
46
|
+
};
|
|
47
|
+
return convert;
|
|
57
48
|
};
|
|
58
|
-
//# sourceMappingURL=common.js.map
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import { generatePowershellConvert } from
|
|
2
|
-
const restmethod = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { generatePowershellConvert } from '../common.js';
|
|
2
|
+
export const restmethod = {
|
|
3
|
+
info: {
|
|
4
|
+
key: 'restmethod',
|
|
5
|
+
title: 'Invoke-RestMethod',
|
|
6
|
+
link: 'https://docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Utility/Invoke-RestMethod',
|
|
7
|
+
description: 'Powershell Invoke-RestMethod client',
|
|
8
|
+
},
|
|
9
|
+
convert: generatePowershellConvert('Invoke-RestMethod'),
|
|
10
10
|
};
|
|
11
|
-
export {
|
|
12
|
-
restmethod
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=client.js.map
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import { generatePowershellConvert } from
|
|
2
|
-
const webrequest = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { generatePowershellConvert } from '../common.js';
|
|
2
|
+
export const webrequest = {
|
|
3
|
+
info: {
|
|
4
|
+
key: 'webrequest',
|
|
5
|
+
title: 'Invoke-WebRequest',
|
|
6
|
+
link: 'https://docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Utility/Invoke-WebRequest',
|
|
7
|
+
description: 'Powershell Invoke-WebRequest client',
|
|
8
|
+
},
|
|
9
|
+
convert: generatePowershellConvert('Invoke-WebRequest'),
|
|
10
10
|
};
|
|
11
|
-
export {
|
|
12
|
-
webrequest
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=client.js.map
|