@readme/httpsnippet 3.1.3 → 4.0.2
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/README.md +63 -62
- package/dist/package.json +86 -0
- package/dist/src/fixtures/customTarget.js +15 -0
- package/dist/src/fixtures/mimetypes.js +77 -0
- package/dist/src/fixtures/requests/application-form-encoded.js +69 -0
- package/dist/src/fixtures/requests/application-json.js +72 -0
- package/dist/src/fixtures/requests/cookies.js +51 -0
- package/dist/src/fixtures/requests/custom-method.js +41 -0
- package/dist/src/fixtures/requests/full.js +99 -0
- package/dist/src/fixtures/requests/headers.js +56 -0
- package/dist/src/fixtures/requests/http-insecure.js +45 -0
- package/dist/src/fixtures/requests/jsonObj-multiline.js +59 -0
- package/dist/src/fixtures/requests/jsonObj-null-value.js +61 -0
- package/dist/src/fixtures/requests/multipart-data.js +72 -0
- package/dist/src/fixtures/requests/multipart-file.js +65 -0
- package/dist/src/fixtures/requests/multipart-form-data-no-params.js +56 -0
- package/dist/src/fixtures/requests/multipart-form-data.js +64 -0
- package/dist/src/fixtures/requests/nested.js +64 -0
- package/dist/src/fixtures/requests/query-encoded.js +59 -0
- package/dist/src/fixtures/requests/query.js +64 -0
- package/dist/src/fixtures/requests/short.js +45 -0
- package/dist/src/fixtures/requests/text-plain.js +57 -0
- package/dist/src/fixtures/runCustomFixtures.js +77 -0
- package/dist/src/helpers/code-builder.js +91 -0
- package/dist/src/helpers/form-data.js +157 -0
- package/dist/src/helpers/har-validator.js +76 -0
- package/dist/src/helpers/headers.js +33 -0
- package/dist/src/helpers/reducer.js +19 -0
- package/dist/src/helpers/shell.js +20 -0
- package/dist/src/helpers/utils.js +21 -0
- package/dist/src/index.js +285 -0
- package/dist/src/targets/c/libcurl/client.js +43 -0
- package/dist/src/targets/c/target.js +15 -0
- package/dist/src/targets/clojure/clj_http/client.js +184 -0
- package/dist/src/targets/clojure/target.js +15 -0
- package/dist/src/targets/csharp/httpclient/client.js +162 -0
- package/dist/src/targets/csharp/restsharp/client.js +38 -0
- package/dist/src/targets/csharp/target.js +17 -0
- package/dist/src/targets/go/native/client.js +122 -0
- package/dist/src/targets/go/target.js +15 -0
- package/dist/src/targets/http/http1.1/client.js +79 -0
- package/dist/src/targets/http/target.js +15 -0
- package/dist/src/targets/java/asynchttp/client.js +53 -0
- package/dist/src/targets/java/nethttp/client.js +52 -0
- package/dist/src/targets/java/okhttp/client.js +79 -0
- package/dist/src/targets/java/target.js +21 -0
- package/dist/src/targets/java/unirest/client.js +53 -0
- package/dist/src/targets/javascript/axios/client.js +101 -0
- package/dist/src/targets/javascript/axios/fixtures/application-form-encoded.js +22 -0
- package/dist/src/targets/javascript/axios/fixtures/application-json.js +26 -0
- package/dist/src/targets/javascript/axios/fixtures/cookies.js +18 -0
- package/dist/src/targets/javascript/axios/fixtures/custom-method.js +14 -0
- package/dist/src/targets/javascript/axios/fixtures/full.js +26 -0
- package/dist/src/targets/javascript/axios/fixtures/headers.js +18 -0
- package/dist/src/targets/javascript/axios/fixtures/http-insecure.js +14 -0
- package/dist/src/targets/javascript/axios/fixtures/jsonObj-multiline.js +19 -0
- package/dist/src/targets/javascript/axios/fixtures/jsonObj-null-value.js +19 -0
- package/dist/src/targets/javascript/axios/fixtures/multipart-data.js +22 -0
- package/dist/src/targets/javascript/axios/fixtures/multipart-file.js +21 -0
- package/dist/src/targets/javascript/axios/fixtures/multipart-form-data-no-params.js +18 -0
- package/dist/src/targets/javascript/axios/fixtures/multipart-form-data.js +21 -0
- package/dist/src/targets/javascript/axios/fixtures/nested.js +18 -0
- package/dist/src/targets/javascript/axios/fixtures/query-encoded.js +21 -0
- package/dist/src/targets/javascript/axios/fixtures/query.js +18 -0
- package/dist/src/targets/javascript/axios/fixtures/short.js +14 -0
- package/dist/src/targets/javascript/axios/fixtures/text-plain.js +19 -0
- package/dist/src/targets/javascript/fetch/client.js +115 -0
- package/dist/src/targets/javascript/fetch/fixtures/application-form-encoded.js +9 -0
- package/dist/src/targets/javascript/fetch/fixtures/application-json.js +16 -0
- package/dist/src/targets/javascript/fetch/fixtures/cookies.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/custom-method.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/full.js +13 -0
- package/dist/src/targets/javascript/fetch/fixtures/headers.js +8 -0
- package/dist/src/targets/javascript/fetch/fixtures/http-insecure.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/jsonObj-multiline.js +9 -0
- package/dist/src/targets/javascript/fetch/fixtures/jsonObj-null-value.js +9 -0
- package/dist/src/targets/javascript/fetch/fixtures/multipart-data.js +9 -0
- package/dist/src/targets/javascript/fetch/fixtures/multipart-file.js +8 -0
- package/dist/src/targets/javascript/fetch/fixtures/multipart-form-data-no-params.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/multipart-form-data.js +8 -0
- package/dist/src/targets/javascript/fetch/fixtures/nested.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/query-encoded.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/query.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/short.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/text-plain.js +5 -0
- package/dist/src/targets/javascript/jquery/client.js +93 -0
- package/dist/src/targets/javascript/jquery/fixtures/application-form-encoded.js +17 -0
- package/dist/src/targets/javascript/jquery/fixtures/application-json.js +15 -0
- package/dist/src/targets/javascript/jquery/fixtures/cookies.js +13 -0
- package/dist/src/targets/javascript/jquery/fixtures/custom-method.js +11 -0
- package/dist/src/targets/javascript/jquery/fixtures/full.js +18 -0
- package/dist/src/targets/javascript/jquery/fixtures/headers.js +15 -0
- package/dist/src/targets/javascript/jquery/fixtures/http-insecure.js +11 -0
- package/dist/src/targets/javascript/jquery/fixtures/jsonObj-multiline.js +15 -0
- package/dist/src/targets/javascript/jquery/fixtures/jsonObj-null-value.js +15 -0
- package/dist/src/targets/javascript/jquery/fixtures/multipart-data.js +18 -0
- package/dist/src/targets/javascript/jquery/fixtures/multipart-file.js +17 -0
- package/dist/src/targets/javascript/jquery/fixtures/multipart-form-data-no-params.js +13 -0
- package/dist/src/targets/javascript/jquery/fixtures/multipart-form-data.js +17 -0
- package/dist/src/targets/javascript/jquery/fixtures/nested.js +11 -0
- package/dist/src/targets/javascript/jquery/fixtures/query-encoded.js +11 -0
- package/dist/src/targets/javascript/jquery/fixtures/query.js +11 -0
- package/dist/src/targets/javascript/jquery/fixtures/short.js +11 -0
- package/dist/src/targets/javascript/jquery/fixtures/text-plain.js +14 -0
- package/dist/src/targets/javascript/target.js +21 -0
- package/dist/src/targets/javascript/xhr/client.js +90 -0
- package/dist/src/targets/javascript/xhr/fixtures/application-form-encoded.js +12 -0
- package/dist/src/targets/javascript/xhr/fixtures/application-json.js +31 -0
- package/dist/src/targets/javascript/xhr/fixtures/cookies.js +12 -0
- package/dist/src/targets/javascript/xhr/fixtures/cors.js +10 -0
- package/dist/src/targets/javascript/xhr/fixtures/custom-method.js +11 -0
- package/dist/src/targets/javascript/xhr/fixtures/full.js +14 -0
- package/dist/src/targets/javascript/xhr/fixtures/headers.js +14 -0
- package/dist/src/targets/javascript/xhr/fixtures/http-insecure.js +11 -0
- package/dist/src/targets/javascript/xhr/fixtures/jsonObj-multiline.js +14 -0
- package/dist/src/targets/javascript/xhr/fixtures/jsonObj-null-value.js +14 -0
- package/dist/src/targets/javascript/xhr/fixtures/multipart-data.js +13 -0
- package/dist/src/targets/javascript/xhr/fixtures/multipart-file.js +12 -0
- package/dist/src/targets/javascript/xhr/fixtures/multipart-form-data-no-params.js +11 -0
- package/dist/src/targets/javascript/xhr/fixtures/multipart-form-data.js +12 -0
- package/dist/src/targets/javascript/xhr/fixtures/nested.js +11 -0
- package/dist/src/targets/javascript/xhr/fixtures/query-encoded.js +11 -0
- package/dist/src/targets/javascript/xhr/fixtures/query.js +11 -0
- package/dist/src/targets/javascript/xhr/fixtures/short.js +11 -0
- package/dist/src/targets/javascript/xhr/fixtures/text-plain.js +12 -0
- package/dist/src/targets/kotlin/okhttp/client.js +79 -0
- package/dist/src/targets/kotlin/target.js +15 -0
- package/dist/src/targets/node/axios/client.js +87 -0
- package/dist/src/targets/node/axios/fixtures/application-form-encoded.js +19 -0
- package/dist/src/targets/node/axios/fixtures/application-json.js +22 -0
- package/dist/src/targets/node/axios/fixtures/cookies.js +14 -0
- package/dist/src/targets/node/axios/fixtures/custom-method.js +10 -0
- package/dist/src/targets/node/axios/fixtures/full.js +22 -0
- package/dist/src/targets/node/axios/fixtures/headers.js +14 -0
- package/dist/src/targets/node/axios/fixtures/http-insecure.js +10 -0
- package/dist/src/targets/node/axios/fixtures/jsonObj-multiline.js +15 -0
- package/dist/src/targets/node/axios/fixtures/jsonObj-null-value.js +15 -0
- package/dist/src/targets/node/axios/fixtures/multipart-data.js +15 -0
- package/dist/src/targets/node/axios/fixtures/multipart-file.js +15 -0
- package/dist/src/targets/node/axios/fixtures/multipart-form-data-no-params.js +14 -0
- package/dist/src/targets/node/axios/fixtures/multipart-form-data.js +15 -0
- package/dist/src/targets/node/axios/fixtures/nested.js +13 -0
- package/dist/src/targets/node/axios/fixtures/query-encoded.js +13 -0
- package/dist/src/targets/node/axios/fixtures/query.js +13 -0
- package/dist/src/targets/node/axios/fixtures/short.js +10 -0
- package/dist/src/targets/node/axios/fixtures/text-plain.js +15 -0
- package/dist/src/targets/node/fetch/client.js +149 -0
- package/dist/src/targets/node/fetch/fixtures/application-form-encoded.js +15 -0
- package/dist/src/targets/node/fetch/fixtures/application-json.js +18 -0
- package/dist/src/targets/node/fetch/fixtures/cookies.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/custom-method.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/full.js +18 -0
- package/dist/src/targets/node/fetch/fixtures/headers.js +10 -0
- package/dist/src/targets/node/fetch/fixtures/http-insecure.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/jsonObj-multiline.js +11 -0
- package/dist/src/targets/node/fetch/fixtures/jsonObj-null-value.js +11 -0
- package/dist/src/targets/node/fetch/fixtures/multipart-data.js +13 -0
- package/dist/src/targets/node/fetch/fixtures/multipart-file.js +12 -0
- package/dist/src/targets/node/fetch/fixtures/multipart-form-data-no-params.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/multipart-form-data.js +11 -0
- package/dist/src/targets/node/fetch/fixtures/nested.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/query-encoded.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/query.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/short.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/text-plain.js +7 -0
- package/dist/src/targets/node/native/client.js +91 -0
- package/dist/src/targets/node/native/fixtures/application-form-encoded.js +24 -0
- package/dist/src/targets/node/native/fixtures/application-json.js +30 -0
- package/dist/src/targets/node/native/fixtures/cookies.js +22 -0
- package/dist/src/targets/node/native/fixtures/custom-method.js +20 -0
- package/dist/src/targets/node/native/fixtures/full.js +26 -0
- package/dist/src/targets/node/native/fixtures/headers.js +24 -0
- package/dist/src/targets/node/native/fixtures/http-insecure.js +20 -0
- package/dist/src/targets/node/native/fixtures/jsonObj-multiline.js +23 -0
- package/dist/src/targets/node/native/fixtures/jsonObj-null-value.js +23 -0
- package/dist/src/targets/node/native/fixtures/multipart-data.js +23 -0
- package/dist/src/targets/node/native/fixtures/multipart-file.js +23 -0
- package/dist/src/targets/node/native/fixtures/multipart-form-data-no-params.js +22 -0
- package/dist/src/targets/node/native/fixtures/multipart-form-data.js +23 -0
- package/dist/src/targets/node/native/fixtures/nested.js +20 -0
- package/dist/src/targets/node/native/fixtures/query-encoded.js +20 -0
- package/dist/src/targets/node/native/fixtures/query.js +20 -0
- package/dist/src/targets/node/native/fixtures/short.js +20 -0
- package/dist/src/targets/node/native/fixtures/text-plain.js +23 -0
- package/dist/src/targets/node/request/client.js +116 -0
- package/dist/src/targets/node/request/fixtures/application-form-encoded.js +13 -0
- package/dist/src/targets/node/request/fixtures/application-json.js +21 -0
- package/dist/src/targets/node/request/fixtures/cookies.js +11 -0
- package/dist/src/targets/node/request/fixtures/custom-method.js +8 -0
- package/dist/src/targets/node/request/fixtures/full.js +20 -0
- package/dist/src/targets/node/request/fixtures/headers.js +12 -0
- package/dist/src/targets/node/request/fixtures/http-insecure.js +8 -0
- package/dist/src/targets/node/request/fixtures/jsonObj-multiline.js +14 -0
- package/dist/src/targets/node/request/fixtures/jsonObj-null-value.js +14 -0
- package/dist/src/targets/node/request/fixtures/multipart-data.js +20 -0
- package/dist/src/targets/node/request/fixtures/multipart-file.js +19 -0
- package/dist/src/targets/node/request/fixtures/multipart-form-data-no-params.js +12 -0
- package/dist/src/targets/node/request/fixtures/multipart-form-data.js +13 -0
- package/dist/src/targets/node/request/fixtures/nested.js +11 -0
- package/dist/src/targets/node/request/fixtures/query-encoded.js +11 -0
- package/dist/src/targets/node/request/fixtures/query.js +11 -0
- package/dist/src/targets/node/request/fixtures/short.js +8 -0
- package/dist/src/targets/node/request/fixtures/text-plain.js +13 -0
- package/dist/src/targets/node/target.js +24 -0
- package/dist/src/targets/node/unirest/client.js +119 -0
- package/dist/src/targets/node/unirest/fixtures/application-form-encoded.js +15 -0
- package/dist/src/targets/node/unirest/fixtures/application-json.js +32 -0
- package/dist/src/targets/node/unirest/fixtures/cookies.js +12 -0
- package/dist/src/targets/node/unirest/fixtures/custom-method.js +8 -0
- package/dist/src/targets/node/unirest/fixtures/full.js +27 -0
- package/dist/src/targets/node/unirest/fixtures/headers.js +13 -0
- package/dist/src/targets/node/unirest/fixtures/http-insecure.js +8 -0
- package/dist/src/targets/node/unirest/fixtures/jsonObj-multiline.js +15 -0
- package/dist/src/targets/node/unirest/fixtures/jsonObj-null-value.js +15 -0
- package/dist/src/targets/node/unirest/fixtures/multipart-data.js +20 -0
- package/dist/src/targets/node/unirest/fixtures/multipart-file.js +18 -0
- package/dist/src/targets/node/unirest/fixtures/multipart-form-data-no-params.js +11 -0
- package/dist/src/targets/node/unirest/fixtures/multipart-form-data.js +16 -0
- package/dist/src/targets/node/unirest/fixtures/nested.js +13 -0
- package/dist/src/targets/node/unirest/fixtures/query-encoded.js +12 -0
- package/dist/src/targets/node/unirest/fixtures/query.js +16 -0
- package/dist/src/targets/node/unirest/fixtures/short.js +8 -0
- package/dist/src/targets/node/unirest/fixtures/text-plain.js +12 -0
- package/dist/src/targets/objc/helpers.js +59 -0
- package/dist/src/targets/objc/nsurlsession/client.js +151 -0
- package/dist/src/targets/objc/target.js +15 -0
- package/dist/src/targets/ocaml/cohttp/client.js +72 -0
- package/dist/src/targets/ocaml/target.js +15 -0
- package/dist/src/targets/php/curl/client.js +135 -0
- package/dist/src/targets/php/guzzle/client.js +126 -0
- package/dist/src/targets/php/helpers.js +63 -0
- package/dist/src/targets/php/http1/client.js +90 -0
- package/dist/src/targets/php/http2/client.js +128 -0
- package/dist/src/targets/php/target.js +22 -0
- package/dist/src/targets/powershell/common.js +49 -0
- package/dist/src/targets/powershell/restmethod/client.js +13 -0
- package/dist/src/targets/powershell/target.js +17 -0
- package/dist/src/targets/powershell/webrequest/client.js +13 -0
- package/dist/src/targets/python/helpers.js +70 -0
- package/dist/src/targets/python/requests/client.js +161 -0
- package/dist/src/targets/python/target.js +16 -0
- package/dist/src/targets/r/httr/client.js +125 -0
- package/dist/src/targets/r/target.js +15 -0
- package/dist/src/targets/ruby/native/client.js +69 -0
- package/dist/src/targets/ruby/target.js +15 -0
- package/dist/src/targets/shell/curl/client.js +171 -0
- package/dist/src/targets/shell/httpie/client.js +111 -0
- package/dist/src/targets/shell/target.js +20 -0
- package/dist/src/targets/shell/wget/client.js +55 -0
- package/dist/src/targets/swift/helpers.js +80 -0
- package/dist/src/targets/swift/nsurlsession/client.js +156 -0
- package/dist/src/targets/swift/target.js +15 -0
- package/dist/src/targets/targets.js +130 -0
- package/package.json +26 -21
- package/src/helpers/code-builder.js +0 -108
- package/src/helpers/form-data.js +0 -107
- package/src/helpers/headers.js +0 -48
- package/src/helpers/reducer.js +0 -20
- package/src/index.js +0 -361
- package/src/targets/c/index.js +0 -10
- package/src/targets/c/libcurl.js +0 -45
- package/src/targets/clojure/clj_http.js +0 -176
- package/src/targets/clojure/index.js +0 -10
- package/src/targets/csharp/httpclient.js +0 -157
- package/src/targets/csharp/index.js +0 -11
- package/src/targets/csharp/restsharp.js +0 -49
- package/src/targets/go/index.js +0 -10
- package/src/targets/go/native.js +0 -130
- package/src/targets/http/http1.1.js +0 -89
- package/src/targets/http/index.js +0 -10
- package/src/targets/index.js +0 -20
- package/src/targets/java/asynchttp.js +0 -54
- package/src/targets/java/index.js +0 -13
- package/src/targets/java/nethttp.js +0 -59
- package/src/targets/java/okhttp.js +0 -78
- package/src/targets/java/unirest.js +0 -57
- package/src/targets/javascript/axios.js +0 -101
- package/src/targets/javascript/fetch.js +0 -129
- package/src/targets/javascript/index.js +0 -13
- package/src/targets/javascript/jquery.js +0 -89
- package/src/targets/javascript/xhr.js +0 -86
- package/src/targets/kotlin/index.js +0 -10
- package/src/targets/kotlin/okhttp.js +0 -78
- package/src/targets/node/axios.js +0 -76
- package/src/targets/node/fetch.js +0 -145
- package/src/targets/node/index.js +0 -15
- package/src/targets/node/native.js +0 -92
- package/src/targets/node/request.js +0 -126
- package/src/targets/node/unirest.js +0 -120
- package/src/targets/objc/helpers.js +0 -80
- package/src/targets/objc/index.js +0 -10
- package/src/targets/objc/nsurlsession.js +0 -164
- package/src/targets/ocaml/cohttp.js +0 -73
- package/src/targets/ocaml/index.js +0 -10
- package/src/targets/php/curl.js +0 -142
- package/src/targets/php/guzzle.js +0 -135
- package/src/targets/php/helpers.js +0 -87
- package/src/targets/php/http1.js +0 -85
- package/src/targets/php/http2.js +0 -131
- package/src/targets/php/index.js +0 -14
- package/src/targets/powershell/common.js +0 -60
- package/src/targets/powershell/index.js +0 -11
- package/src/targets/powershell/restmethod.js +0 -8
- package/src/targets/powershell/webrequest.js +0 -8
- package/src/targets/python/helpers.js +0 -85
- package/src/targets/python/index.js +0 -11
- package/src/targets/python/requests.js +0 -163
- package/src/targets/r/httr.js +0 -134
- package/src/targets/r/index.js +0 -10
- package/src/targets/ruby/index.js +0 -10
- package/src/targets/ruby/native.js +0 -71
- package/src/targets/shell/curl.js +0 -157
- package/src/targets/shell/helpers.js +0 -23
- package/src/targets/shell/httpie.js +0 -129
- package/src/targets/shell/index.js +0 -13
- package/src/targets/shell/wget.js +0 -52
- package/src/targets/swift/helpers.js +0 -93
- package/src/targets/swift/index.js +0 -10
- package/src/targets/swift/nsurlsession.js +0 -152
|
@@ -1,164 +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
|
-
|
|
11
|
-
const helpers = require('./helpers');
|
|
12
|
-
const CodeBuilder = require('../../helpers/code-builder');
|
|
13
|
-
|
|
14
|
-
module.exports = function (source, options) {
|
|
15
|
-
const opts = {
|
|
16
|
-
indent: ' ',
|
|
17
|
-
pretty: true,
|
|
18
|
-
timeout: '10',
|
|
19
|
-
...options,
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const code = new CodeBuilder(opts.indent);
|
|
23
|
-
// Markers for headers to be created as literal objects and later be set on the NSURLRequest if exist
|
|
24
|
-
const req = {
|
|
25
|
-
hasHeaders: false,
|
|
26
|
-
hasBody: false,
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
// We just want to make sure people understand that is the only dependency
|
|
30
|
-
code.push('#import <Foundation/Foundation.h>');
|
|
31
|
-
|
|
32
|
-
if (Object.keys(source.allHeaders).length) {
|
|
33
|
-
req.hasHeaders = true;
|
|
34
|
-
code.blank().push(helpers.nsDeclaration('NSDictionary', 'headers', source.allHeaders, opts.pretty));
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (source.postData.text || source.postData.jsonObj || source.postData.params) {
|
|
38
|
-
req.hasBody = true;
|
|
39
|
-
|
|
40
|
-
switch (source.postData.mimeType) {
|
|
41
|
-
case 'application/x-www-form-urlencoded':
|
|
42
|
-
// By appending parameters one by one in the resulting snippet,
|
|
43
|
-
// we make it easier for the user to edit it according to his or her needs after pasting.
|
|
44
|
-
// The user can just add/remove lines adding/removing body parameters.
|
|
45
|
-
code
|
|
46
|
-
.blank()
|
|
47
|
-
.push(
|
|
48
|
-
'NSMutableData *postData = [[NSMutableData alloc] initWithData:[@"%s=%s" dataUsingEncoding:NSUTF8StringEncoding]];',
|
|
49
|
-
source.postData.params[0].name,
|
|
50
|
-
source.postData.params[0].value
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
// eslint-disable-next-line no-plusplus
|
|
54
|
-
for (let i = 1, len = source.postData.params.length; i < len; i++) {
|
|
55
|
-
code.push(
|
|
56
|
-
'[postData appendData:[@"&%s=%s" dataUsingEncoding:NSUTF8StringEncoding]];',
|
|
57
|
-
source.postData.params[i].name,
|
|
58
|
-
source.postData.params[i].value
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
break;
|
|
62
|
-
|
|
63
|
-
case 'application/json':
|
|
64
|
-
if (source.postData.jsonObj) {
|
|
65
|
-
code
|
|
66
|
-
.push(helpers.nsDeclaration('NSDictionary', 'parameters', source.postData.jsonObj, opts.pretty))
|
|
67
|
-
.blank()
|
|
68
|
-
.push('NSData *postData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:nil];');
|
|
69
|
-
}
|
|
70
|
-
break;
|
|
71
|
-
|
|
72
|
-
case 'multipart/form-data':
|
|
73
|
-
// By appending multipart parameters one by one in the resulting snippet,
|
|
74
|
-
// we make it easier for the user to edit it according to his or her needs after pasting.
|
|
75
|
-
// The user can just edit the parameters NSDictionary or put this part of a snippet in a multipart builder method.
|
|
76
|
-
code
|
|
77
|
-
.push(helpers.nsDeclaration('NSArray', 'parameters', source.postData.params, opts.pretty))
|
|
78
|
-
.push('NSString *boundary = @"%s";', source.postData.boundary)
|
|
79
|
-
.blank()
|
|
80
|
-
.push('NSError *error;')
|
|
81
|
-
.push('NSMutableString *body = [NSMutableString string];')
|
|
82
|
-
.push('for (NSDictionary *param in parameters) {')
|
|
83
|
-
.push(1, '[body appendFormat:@"--%@\\r\\n", boundary];')
|
|
84
|
-
.push(1, 'if (param[@"fileName"]) {')
|
|
85
|
-
.push(
|
|
86
|
-
2,
|
|
87
|
-
'[body appendFormat:@"Content-Disposition:form-data; name=\\"%@\\"; filename=\\"%@\\"\\r\\n", param[@"name"], param[@"fileName"]];'
|
|
88
|
-
)
|
|
89
|
-
.push(2, '[body appendFormat:@"Content-Type: %@\\r\\n\\r\\n", param[@"contentType"]];')
|
|
90
|
-
.push(
|
|
91
|
-
2,
|
|
92
|
-
'[body appendFormat:@"%@", [NSString stringWithContentsOfFile:param[@"fileName"] encoding:NSUTF8StringEncoding error:&error]];'
|
|
93
|
-
)
|
|
94
|
-
.push(2, 'if (error) {')
|
|
95
|
-
.push(3, 'NSLog(@"%@", error);')
|
|
96
|
-
.push(2, '}')
|
|
97
|
-
.push(1, '} else {')
|
|
98
|
-
.push(2, '[body appendFormat:@"Content-Disposition:form-data; name=\\"%@\\"\\r\\n\\r\\n", param[@"name"]];')
|
|
99
|
-
.push(2, '[body appendFormat:@"%@", param[@"value"]];')
|
|
100
|
-
.push(1, '}')
|
|
101
|
-
.push('}')
|
|
102
|
-
.push('[body appendFormat:@"\\r\\n--%@--\\r\\n", boundary];')
|
|
103
|
-
.push('NSData *postData = [body dataUsingEncoding:NSUTF8StringEncoding];');
|
|
104
|
-
break;
|
|
105
|
-
|
|
106
|
-
default:
|
|
107
|
-
code
|
|
108
|
-
.blank()
|
|
109
|
-
.push(
|
|
110
|
-
`NSData *postData = [[NSData alloc] initWithData:[@"${source.postData.text}" dataUsingEncoding:NSUTF8StringEncoding]];`
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
code
|
|
116
|
-
.blank()
|
|
117
|
-
.push(
|
|
118
|
-
`NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"${source.fullUrl}"]`
|
|
119
|
-
)
|
|
120
|
-
// NSURLRequestUseProtocolCachePolicy is the default policy, let's just always set it to avoid confusion.
|
|
121
|
-
.push(' cachePolicy:NSURLRequestUseProtocolCachePolicy')
|
|
122
|
-
.push(
|
|
123
|
-
` timeoutInterval:${parseInt(opts.timeout, 10).toFixed(1)}];`
|
|
124
|
-
)
|
|
125
|
-
.push(`[request setHTTPMethod:@"${source.method}"];`);
|
|
126
|
-
|
|
127
|
-
if (req.hasHeaders) {
|
|
128
|
-
code.push('[request setAllHTTPHeaderFields:headers];');
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (req.hasBody) {
|
|
132
|
-
code.push('[request setHTTPBody:postData];');
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
code
|
|
136
|
-
.blank()
|
|
137
|
-
// Retrieving the shared session will be less verbose than creating a new one.
|
|
138
|
-
.push('NSURLSession *session = [NSURLSession sharedSession];')
|
|
139
|
-
.push('NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request')
|
|
140
|
-
.push(
|
|
141
|
-
' completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {'
|
|
142
|
-
)
|
|
143
|
-
.push(1, ' if (error) {')
|
|
144
|
-
.push(2, ' NSLog(@"%@", error);')
|
|
145
|
-
.push(1, ' } else {')
|
|
146
|
-
// Casting the NSURLResponse to NSHTTPURLResponse so the user can see the status .
|
|
147
|
-
.push(
|
|
148
|
-
2,
|
|
149
|
-
' NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;'
|
|
150
|
-
)
|
|
151
|
-
.push(2, ' NSLog(@"%@", httpResponse);')
|
|
152
|
-
.push(1, ' }')
|
|
153
|
-
.push(' }];')
|
|
154
|
-
.push('[dataTask resume];');
|
|
155
|
-
|
|
156
|
-
return code.join();
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
module.exports.info = {
|
|
160
|
-
key: 'nsurlsession',
|
|
161
|
-
title: 'NSURLSession',
|
|
162
|
-
link: 'https://developer.apple.com/library/mac/documentation/Foundation/Reference/NSURLSession_class/index.html',
|
|
163
|
-
description: "Foundation's NSURLSession request",
|
|
164
|
-
};
|
|
@@ -1,73 +0,0 @@
|
|
|
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
|
-
|
|
11
|
-
const CodeBuilder = require('../../helpers/code-builder');
|
|
12
|
-
|
|
13
|
-
module.exports = function (source, options) {
|
|
14
|
-
const opts = {
|
|
15
|
-
indent: ' ',
|
|
16
|
-
...options,
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const methods = ['get', 'post', 'head', 'delete', 'patch', 'put', 'options'];
|
|
20
|
-
const code = new CodeBuilder(opts.indent);
|
|
21
|
-
|
|
22
|
-
code
|
|
23
|
-
.push('open Cohttp_lwt_unix')
|
|
24
|
-
.push('open Cohttp')
|
|
25
|
-
.push('open Lwt')
|
|
26
|
-
.blank()
|
|
27
|
-
.push('let uri = Uri.of_string "%s" in', source.fullUrl);
|
|
28
|
-
|
|
29
|
-
// Add headers, including the cookies
|
|
30
|
-
const headers = Object.keys(source.allHeaders);
|
|
31
|
-
|
|
32
|
-
if (headers.length === 1) {
|
|
33
|
-
code.push('let headers = Header.add (Header.init ()) "%s" "%s" in', headers[0], source.allHeaders[headers[0]]);
|
|
34
|
-
} else if (headers.length > 1) {
|
|
35
|
-
code.push('let headers = Header.add_list (Header.init ()) [');
|
|
36
|
-
|
|
37
|
-
headers.forEach(function (key) {
|
|
38
|
-
code.push(1, '("%s", "%s");', key, source.allHeaders[key]);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
code.push('] in');
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Add body
|
|
45
|
-
if (source.postData.text) {
|
|
46
|
-
// Just text
|
|
47
|
-
code.push('let body = Cohttp_lwt_body.of_string %s in', JSON.stringify(source.postData.text));
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Do the request
|
|
51
|
-
code.blank();
|
|
52
|
-
|
|
53
|
-
code.push(
|
|
54
|
-
'Client.call %s%s%s uri',
|
|
55
|
-
headers.length ? '~headers ' : '',
|
|
56
|
-
source.postData.text ? '~body ' : '',
|
|
57
|
-
methods.indexOf(source.method.toLowerCase()) >= 0
|
|
58
|
-
? `\`${source.method.toUpperCase()}`
|
|
59
|
-
: `(Code.method_of_string "${source.method}")`
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
// Catch result
|
|
63
|
-
code.push('>>= fun (res, body_stream) ->').push(1, '(* Do stuff with the result *)');
|
|
64
|
-
|
|
65
|
-
return code.join();
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
module.exports.info = {
|
|
69
|
-
key: 'cohttp',
|
|
70
|
-
title: 'CoHTTP',
|
|
71
|
-
link: 'https://github.com/mirage/ocaml-cohttp',
|
|
72
|
-
description: 'Cohttp is a very lightweight HTTP server using Lwt or Async for OCaml',
|
|
73
|
-
};
|
package/src/targets/php/curl.js
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description
|
|
3
|
-
* HTTP code snippet generator for PHP using curl-ext.
|
|
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
|
-
|
|
11
|
-
const { format } = require('util');
|
|
12
|
-
const CodeBuilder = require('../../helpers/code-builder');
|
|
13
|
-
|
|
14
|
-
module.exports = function (source, options) {
|
|
15
|
-
const opts = {
|
|
16
|
-
closingTag: false,
|
|
17
|
-
indent: ' ',
|
|
18
|
-
maxRedirects: 10,
|
|
19
|
-
namedErrors: false,
|
|
20
|
-
noTags: false,
|
|
21
|
-
shortTags: false,
|
|
22
|
-
timeout: 30,
|
|
23
|
-
...options,
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const code = new CodeBuilder(opts.indent);
|
|
27
|
-
|
|
28
|
-
if (!opts.noTags) {
|
|
29
|
-
code.push(opts.shortTags ? '<?' : '<?php').blank();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
code.push('$curl = curl_init();').blank();
|
|
33
|
-
|
|
34
|
-
const curlOptions = [
|
|
35
|
-
{
|
|
36
|
-
escape: true,
|
|
37
|
-
name: 'CURLOPT_PORT',
|
|
38
|
-
value: source.uriObj.port,
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
escape: true,
|
|
42
|
-
name: 'CURLOPT_URL',
|
|
43
|
-
value: source.fullUrl,
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
escape: false,
|
|
47
|
-
name: 'CURLOPT_RETURNTRANSFER',
|
|
48
|
-
value: 'true',
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
escape: true,
|
|
52
|
-
name: 'CURLOPT_ENCODING',
|
|
53
|
-
value: '',
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
escape: false,
|
|
57
|
-
name: 'CURLOPT_MAXREDIRS',
|
|
58
|
-
value: opts.maxRedirects,
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
escape: false,
|
|
62
|
-
name: 'CURLOPT_TIMEOUT',
|
|
63
|
-
value: opts.timeout,
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
escape: false,
|
|
67
|
-
name: 'CURLOPT_HTTP_VERSION',
|
|
68
|
-
value: source.httpVersion === 'HTTP/1.0' ? 'CURL_HTTP_VERSION_1_0' : 'CURL_HTTP_VERSION_1_1',
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
escape: true,
|
|
72
|
-
name: 'CURLOPT_CUSTOMREQUEST',
|
|
73
|
-
value: source.method,
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
escape: true,
|
|
77
|
-
name: 'CURLOPT_POSTFIELDS',
|
|
78
|
-
value: source.postData ? source.postData.text : undefined,
|
|
79
|
-
},
|
|
80
|
-
];
|
|
81
|
-
|
|
82
|
-
code.push('curl_setopt_array($curl, [');
|
|
83
|
-
|
|
84
|
-
const curlopts = new CodeBuilder(opts.indent, `\n${opts.indent}`);
|
|
85
|
-
|
|
86
|
-
curlOptions.forEach(function (option) {
|
|
87
|
-
if (![null, undefined].includes(option.value)) {
|
|
88
|
-
curlopts.push(format('%s => %s,', option.name, option.escape ? JSON.stringify(option.value) : option.value));
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
// construct cookies
|
|
93
|
-
if (source.allHeaders.cookie) {
|
|
94
|
-
curlopts.push(format('CURLOPT_COOKIE => "%s",', source.allHeaders.cookie));
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// construct cookies
|
|
98
|
-
const headers = Object.keys(source.headersObj)
|
|
99
|
-
.sort()
|
|
100
|
-
.map(function (key) {
|
|
101
|
-
return format('"%s: %s"', key, source.headersObj[key]);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
if (headers.length) {
|
|
105
|
-
curlopts
|
|
106
|
-
.push('CURLOPT_HTTPHEADER => [')
|
|
107
|
-
.push(1, headers.join(`,\n${opts.indent}${opts.indent}`))
|
|
108
|
-
.push('],');
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
code
|
|
112
|
-
.push(1, curlopts.join())
|
|
113
|
-
.push(']);')
|
|
114
|
-
.blank()
|
|
115
|
-
.push('$response = curl_exec($curl);')
|
|
116
|
-
.push('$err = curl_error($curl);')
|
|
117
|
-
.blank()
|
|
118
|
-
.push('curl_close($curl);')
|
|
119
|
-
.blank()
|
|
120
|
-
.push('if ($err) {');
|
|
121
|
-
|
|
122
|
-
if (opts.namedErrors) {
|
|
123
|
-
code.push(1, 'echo array_flip(get_defined_constants(true)["curl"])[$err];');
|
|
124
|
-
} else {
|
|
125
|
-
code.push(1, 'echo "cURL Error #:" . $err;');
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
code.push('} else {').push(1, 'echo $response;').push('}');
|
|
129
|
-
|
|
130
|
-
if (!opts.noTags && opts.closingTag) {
|
|
131
|
-
code.blank().push('?>');
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return code.join();
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
module.exports.info = {
|
|
138
|
-
key: 'curl',
|
|
139
|
-
title: 'cURL',
|
|
140
|
-
link: 'http://php.net/manual/en/book.curl.php',
|
|
141
|
-
description: 'PHP with ext-curl',
|
|
142
|
-
};
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description
|
|
3
|
-
* HTTP code snippet generator for PHP using Guzzle.
|
|
4
|
-
*
|
|
5
|
-
* @author
|
|
6
|
-
* @RobertoArruda
|
|
7
|
-
*
|
|
8
|
-
* for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
const { format } = require('util');
|
|
12
|
-
const helpers = require('./helpers');
|
|
13
|
-
const headerHelpers = require('../../helpers/headers');
|
|
14
|
-
const CodeBuilder = require('../../helpers/code-builder');
|
|
15
|
-
|
|
16
|
-
module.exports = function (source, options) {
|
|
17
|
-
const opts = {
|
|
18
|
-
closingTag: false,
|
|
19
|
-
indent: ' ',
|
|
20
|
-
noTags: false,
|
|
21
|
-
shortTags: false,
|
|
22
|
-
...options,
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const code = new CodeBuilder(opts.indent);
|
|
26
|
-
|
|
27
|
-
if (!opts.noTags) {
|
|
28
|
-
code.push(opts.shortTags ? '<?' : '<?php');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
code.push("require_once('vendor/autoload.php');").blank();
|
|
32
|
-
|
|
33
|
-
const requestOptions = new CodeBuilder(opts.indent);
|
|
34
|
-
|
|
35
|
-
switch (source.postData.mimeType) {
|
|
36
|
-
case 'application/x-www-form-urlencoded':
|
|
37
|
-
requestOptions.push(
|
|
38
|
-
1,
|
|
39
|
-
"'form_params' => %s,",
|
|
40
|
-
helpers.convert(source.postData.paramsObj, opts.indent + opts.indent, opts.indent)
|
|
41
|
-
);
|
|
42
|
-
break;
|
|
43
|
-
|
|
44
|
-
case 'multipart/form-data': {
|
|
45
|
-
if (source.postData.params) {
|
|
46
|
-
const fields = [];
|
|
47
|
-
|
|
48
|
-
source.postData.params.forEach(function (param) {
|
|
49
|
-
if (param.fileName) {
|
|
50
|
-
const field = {
|
|
51
|
-
name: param.name,
|
|
52
|
-
filename: param.fileName,
|
|
53
|
-
contents: param.value,
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
if (param.contentType) {
|
|
57
|
-
field.headers = { 'Content-Type': param.contentType };
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
fields.push(field);
|
|
61
|
-
} else if (param.value) {
|
|
62
|
-
fields.push({
|
|
63
|
-
name: param.name,
|
|
64
|
-
contents: param.value,
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
if (fields.length) {
|
|
70
|
-
requestOptions.push(1, "'multipart' => %s", helpers.convert(fields, opts.indent + opts.indent, opts.indent));
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Guzzle adds its own boundary for multipart requests.
|
|
74
|
-
if (headerHelpers.hasHeader(source.headersObj, 'content-type')) {
|
|
75
|
-
if (headerHelpers.getHeader(source.headersObj, 'content-type').includes('boundary')) {
|
|
76
|
-
// eslint-disable-next-line no-param-reassign
|
|
77
|
-
delete source.headersObj[headerHelpers.getHeaderName(source.headersObj, 'content-type')];
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
default:
|
|
85
|
-
if (source.postData.text) {
|
|
86
|
-
requestOptions.push(1, "'body' => %s,", helpers.convert(source.postData.text));
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// construct headers
|
|
91
|
-
const headers = Object.keys(source.headersObj)
|
|
92
|
-
.sort()
|
|
93
|
-
.map(function (key) {
|
|
94
|
-
return opts.indent + opts.indent + format("'%s' => '%s',", key, source.headersObj[key]);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
// construct cookies
|
|
98
|
-
const cookies = source.cookies.map(function (cookie) {
|
|
99
|
-
return `${encodeURIComponent(cookie.name)}=${encodeURIComponent(cookie.value)}`;
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
if (cookies.length) {
|
|
103
|
-
headers.push(opts.indent + opts.indent + format("'cookie' => '%s',", cookies.join('; ')));
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (headers.length) {
|
|
107
|
-
requestOptions.push(1, "'headers' => [").push(headers.join('\n')).push(1, '],');
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
code.push('$client = new \\GuzzleHttp\\Client();').blank();
|
|
111
|
-
|
|
112
|
-
if (requestOptions.code.length) {
|
|
113
|
-
code
|
|
114
|
-
.push(`$response = $client->request('${source.method}', '${source.fullUrl}', [`)
|
|
115
|
-
.push(requestOptions.join(','))
|
|
116
|
-
.push(']);');
|
|
117
|
-
} else {
|
|
118
|
-
code.push(`$response = $client->request('${source.method}', '${source.fullUrl}');`);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
code.blank().push('echo $response->getBody();');
|
|
122
|
-
|
|
123
|
-
if (!opts.noTags && opts.closingTag) {
|
|
124
|
-
code.blank().push('?>');
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return code.join();
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
module.exports.info = {
|
|
131
|
-
key: 'guzzle',
|
|
132
|
-
title: 'Guzzle',
|
|
133
|
-
link: 'http://docs.guzzlephp.org/en/stable/',
|
|
134
|
-
description: 'PHP with guzzle',
|
|
135
|
-
};
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
const convert = function (obj, indent, lastIndent) {
|
|
2
|
-
let i;
|
|
3
|
-
let result;
|
|
4
|
-
|
|
5
|
-
if (!lastIndent) {
|
|
6
|
-
// eslint-disable-next-line no-param-reassign
|
|
7
|
-
lastIndent = '';
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
switch (Object.prototype.toString.call(obj)) {
|
|
11
|
-
case '[object Null]':
|
|
12
|
-
result = 'null';
|
|
13
|
-
break;
|
|
14
|
-
|
|
15
|
-
case '[object Undefined]':
|
|
16
|
-
result = 'null';
|
|
17
|
-
break;
|
|
18
|
-
|
|
19
|
-
case '[object String]':
|
|
20
|
-
result = `'${obj.replace(/\\/g, '\\\\').replace(/'/g, "'")}'`;
|
|
21
|
-
break;
|
|
22
|
-
|
|
23
|
-
case '[object Number]':
|
|
24
|
-
result = obj.toString();
|
|
25
|
-
break;
|
|
26
|
-
|
|
27
|
-
case '[object Array]':
|
|
28
|
-
result = [];
|
|
29
|
-
|
|
30
|
-
obj.forEach(function (item) {
|
|
31
|
-
result.push(convert(item, indent + indent, indent));
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
result = `[\n${indent}${result.join(`,\n${indent}`)}\n${lastIndent}]`;
|
|
35
|
-
break;
|
|
36
|
-
|
|
37
|
-
case '[object Object]':
|
|
38
|
-
result = [];
|
|
39
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
40
|
-
for (i in obj) {
|
|
41
|
-
// eslint-disable-next-line no-prototype-builtins
|
|
42
|
-
if (obj.hasOwnProperty(i)) {
|
|
43
|
-
result.push(`${convert(i, indent)} => ${convert(obj[i], indent + indent, indent)}`);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
result = `[\n${indent}${result.join(`,\n${indent}`)}\n${lastIndent}]`;
|
|
47
|
-
break;
|
|
48
|
-
|
|
49
|
-
default:
|
|
50
|
-
result = 'null';
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return result;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
module.exports = {
|
|
57
|
-
convert,
|
|
58
|
-
methods: [
|
|
59
|
-
'ACL',
|
|
60
|
-
'BASELINE_CONTROL',
|
|
61
|
-
'CHECKIN',
|
|
62
|
-
'CHECKOUT',
|
|
63
|
-
'CONNECT',
|
|
64
|
-
'COPY',
|
|
65
|
-
'DELETE',
|
|
66
|
-
'GET',
|
|
67
|
-
'HEAD',
|
|
68
|
-
'LABEL',
|
|
69
|
-
'LOCK',
|
|
70
|
-
'MERGE',
|
|
71
|
-
'MKACTIVITY',
|
|
72
|
-
'MKCOL',
|
|
73
|
-
'MKWORKSPACE',
|
|
74
|
-
'MOVE',
|
|
75
|
-
'OPTIONS',
|
|
76
|
-
'POST',
|
|
77
|
-
'PROPFIND',
|
|
78
|
-
'PROPPATCH',
|
|
79
|
-
'PUT',
|
|
80
|
-
'REPORT',
|
|
81
|
-
'TRACE',
|
|
82
|
-
'UNCHECKOUT',
|
|
83
|
-
'UNLOCK',
|
|
84
|
-
'UPDATE',
|
|
85
|
-
'VERSION_CONTROL',
|
|
86
|
-
],
|
|
87
|
-
};
|
package/src/targets/php/http1.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description
|
|
3
|
-
* HTTP code snippet generator for PHP using curl-ext.
|
|
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
|
-
|
|
11
|
-
const helpers = require('./helpers');
|
|
12
|
-
const CodeBuilder = require('../../helpers/code-builder');
|
|
13
|
-
|
|
14
|
-
module.exports = function (source, options) {
|
|
15
|
-
const opts = {
|
|
16
|
-
closingTag: false,
|
|
17
|
-
indent: ' ',
|
|
18
|
-
noTags: false,
|
|
19
|
-
shortTags: false,
|
|
20
|
-
...options,
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const code = new CodeBuilder(opts.indent);
|
|
24
|
-
|
|
25
|
-
if (!opts.noTags) {
|
|
26
|
-
code.push(opts.shortTags ? '<?' : '<?php').blank();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (!helpers.methods.includes(source.method.toUpperCase())) {
|
|
30
|
-
code.push("HttpRequest::methodRegister('%s');", source.method);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
code.push('$request = new HttpRequest();').push('$request->setUrl(%s);', helpers.convert(source.url));
|
|
34
|
-
|
|
35
|
-
if (helpers.methods.includes(source.method.toUpperCase())) {
|
|
36
|
-
code.push('$request->setMethod(HTTP_METH_%s);', source.method.toUpperCase());
|
|
37
|
-
} else {
|
|
38
|
-
code.push('$request->setMethod(HttpRequest::HTTP_METH_%s);', source.method.toUpperCase());
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
code.blank();
|
|
42
|
-
|
|
43
|
-
if (Object.keys(source.queryObj).length) {
|
|
44
|
-
code.push('$request->setQueryData(%s);', helpers.convert(source.queryObj, opts.indent)).blank();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (Object.keys(source.headersObj).length) {
|
|
48
|
-
code.push('$request->setHeaders(%s);', helpers.convert(source.headersObj, opts.indent)).blank();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (Object.keys(source.cookiesObj).length) {
|
|
52
|
-
code.push('$request->setCookies(%s);', helpers.convert(source.cookiesObj, opts.indent)).blank();
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (source.postData.mimeType === 'application/x-www-form-urlencoded') {
|
|
56
|
-
code
|
|
57
|
-
.push('$request->setContentType(%s);', helpers.convert(source.postData.mimeType))
|
|
58
|
-
.push('$request->setPostFields(%s);', helpers.convert(source.postData.paramsObj, opts.indent))
|
|
59
|
-
.blank();
|
|
60
|
-
} else if (source.postData.text) {
|
|
61
|
-
code.push('$request->setBody(%s);', helpers.convert(source.postData.text)).blank();
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
code
|
|
65
|
-
.push('try {')
|
|
66
|
-
.push(1, '$response = $request->send();')
|
|
67
|
-
.blank()
|
|
68
|
-
.push(1, 'echo $response->getBody();')
|
|
69
|
-
.push('} catch (HttpException $ex) {')
|
|
70
|
-
.push(1, 'echo $ex;')
|
|
71
|
-
.push('}');
|
|
72
|
-
|
|
73
|
-
if (!opts.noTags && opts.closingTag) {
|
|
74
|
-
code.blank().push('?>');
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return code.join();
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
module.exports.info = {
|
|
81
|
-
key: 'http1',
|
|
82
|
-
title: 'HTTP v1',
|
|
83
|
-
link: 'http://php.net/manual/en/book.http.php',
|
|
84
|
-
description: 'PHP with pecl/http v1',
|
|
85
|
-
};
|