@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.
Files changed (319) hide show
  1. package/README.md +63 -62
  2. package/dist/package.json +86 -0
  3. package/dist/src/fixtures/customTarget.js +15 -0
  4. package/dist/src/fixtures/mimetypes.js +77 -0
  5. package/dist/src/fixtures/requests/application-form-encoded.js +69 -0
  6. package/dist/src/fixtures/requests/application-json.js +72 -0
  7. package/dist/src/fixtures/requests/cookies.js +51 -0
  8. package/dist/src/fixtures/requests/custom-method.js +41 -0
  9. package/dist/src/fixtures/requests/full.js +99 -0
  10. package/dist/src/fixtures/requests/headers.js +56 -0
  11. package/dist/src/fixtures/requests/http-insecure.js +45 -0
  12. package/dist/src/fixtures/requests/jsonObj-multiline.js +59 -0
  13. package/dist/src/fixtures/requests/jsonObj-null-value.js +61 -0
  14. package/dist/src/fixtures/requests/multipart-data.js +72 -0
  15. package/dist/src/fixtures/requests/multipart-file.js +65 -0
  16. package/dist/src/fixtures/requests/multipart-form-data-no-params.js +56 -0
  17. package/dist/src/fixtures/requests/multipart-form-data.js +64 -0
  18. package/dist/src/fixtures/requests/nested.js +64 -0
  19. package/dist/src/fixtures/requests/query-encoded.js +59 -0
  20. package/dist/src/fixtures/requests/query.js +64 -0
  21. package/dist/src/fixtures/requests/short.js +45 -0
  22. package/dist/src/fixtures/requests/text-plain.js +57 -0
  23. package/dist/src/fixtures/runCustomFixtures.js +77 -0
  24. package/dist/src/helpers/code-builder.js +91 -0
  25. package/dist/src/helpers/form-data.js +157 -0
  26. package/dist/src/helpers/har-validator.js +76 -0
  27. package/dist/src/helpers/headers.js +33 -0
  28. package/dist/src/helpers/reducer.js +19 -0
  29. package/dist/src/helpers/shell.js +20 -0
  30. package/dist/src/helpers/utils.js +21 -0
  31. package/dist/src/index.js +285 -0
  32. package/dist/src/targets/c/libcurl/client.js +43 -0
  33. package/dist/src/targets/c/target.js +15 -0
  34. package/dist/src/targets/clojure/clj_http/client.js +184 -0
  35. package/dist/src/targets/clojure/target.js +15 -0
  36. package/dist/src/targets/csharp/httpclient/client.js +162 -0
  37. package/dist/src/targets/csharp/restsharp/client.js +38 -0
  38. package/dist/src/targets/csharp/target.js +17 -0
  39. package/dist/src/targets/go/native/client.js +122 -0
  40. package/dist/src/targets/go/target.js +15 -0
  41. package/dist/src/targets/http/http1.1/client.js +79 -0
  42. package/dist/src/targets/http/target.js +15 -0
  43. package/dist/src/targets/java/asynchttp/client.js +53 -0
  44. package/dist/src/targets/java/nethttp/client.js +52 -0
  45. package/dist/src/targets/java/okhttp/client.js +79 -0
  46. package/dist/src/targets/java/target.js +21 -0
  47. package/dist/src/targets/java/unirest/client.js +53 -0
  48. package/dist/src/targets/javascript/axios/client.js +101 -0
  49. package/dist/src/targets/javascript/axios/fixtures/application-form-encoded.js +22 -0
  50. package/dist/src/targets/javascript/axios/fixtures/application-json.js +26 -0
  51. package/dist/src/targets/javascript/axios/fixtures/cookies.js +18 -0
  52. package/dist/src/targets/javascript/axios/fixtures/custom-method.js +14 -0
  53. package/dist/src/targets/javascript/axios/fixtures/full.js +26 -0
  54. package/dist/src/targets/javascript/axios/fixtures/headers.js +18 -0
  55. package/dist/src/targets/javascript/axios/fixtures/http-insecure.js +14 -0
  56. package/dist/src/targets/javascript/axios/fixtures/jsonObj-multiline.js +19 -0
  57. package/dist/src/targets/javascript/axios/fixtures/jsonObj-null-value.js +19 -0
  58. package/dist/src/targets/javascript/axios/fixtures/multipart-data.js +22 -0
  59. package/dist/src/targets/javascript/axios/fixtures/multipart-file.js +21 -0
  60. package/dist/src/targets/javascript/axios/fixtures/multipart-form-data-no-params.js +18 -0
  61. package/dist/src/targets/javascript/axios/fixtures/multipart-form-data.js +21 -0
  62. package/dist/src/targets/javascript/axios/fixtures/nested.js +18 -0
  63. package/dist/src/targets/javascript/axios/fixtures/query-encoded.js +21 -0
  64. package/dist/src/targets/javascript/axios/fixtures/query.js +18 -0
  65. package/dist/src/targets/javascript/axios/fixtures/short.js +14 -0
  66. package/dist/src/targets/javascript/axios/fixtures/text-plain.js +19 -0
  67. package/dist/src/targets/javascript/fetch/client.js +115 -0
  68. package/dist/src/targets/javascript/fetch/fixtures/application-form-encoded.js +9 -0
  69. package/dist/src/targets/javascript/fetch/fixtures/application-json.js +16 -0
  70. package/dist/src/targets/javascript/fetch/fixtures/cookies.js +5 -0
  71. package/dist/src/targets/javascript/fetch/fixtures/custom-method.js +5 -0
  72. package/dist/src/targets/javascript/fetch/fixtures/full.js +13 -0
  73. package/dist/src/targets/javascript/fetch/fixtures/headers.js +8 -0
  74. package/dist/src/targets/javascript/fetch/fixtures/http-insecure.js +5 -0
  75. package/dist/src/targets/javascript/fetch/fixtures/jsonObj-multiline.js +9 -0
  76. package/dist/src/targets/javascript/fetch/fixtures/jsonObj-null-value.js +9 -0
  77. package/dist/src/targets/javascript/fetch/fixtures/multipart-data.js +9 -0
  78. package/dist/src/targets/javascript/fetch/fixtures/multipart-file.js +8 -0
  79. package/dist/src/targets/javascript/fetch/fixtures/multipart-form-data-no-params.js +5 -0
  80. package/dist/src/targets/javascript/fetch/fixtures/multipart-form-data.js +8 -0
  81. package/dist/src/targets/javascript/fetch/fixtures/nested.js +5 -0
  82. package/dist/src/targets/javascript/fetch/fixtures/query-encoded.js +5 -0
  83. package/dist/src/targets/javascript/fetch/fixtures/query.js +5 -0
  84. package/dist/src/targets/javascript/fetch/fixtures/short.js +5 -0
  85. package/dist/src/targets/javascript/fetch/fixtures/text-plain.js +5 -0
  86. package/dist/src/targets/javascript/jquery/client.js +93 -0
  87. package/dist/src/targets/javascript/jquery/fixtures/application-form-encoded.js +17 -0
  88. package/dist/src/targets/javascript/jquery/fixtures/application-json.js +15 -0
  89. package/dist/src/targets/javascript/jquery/fixtures/cookies.js +13 -0
  90. package/dist/src/targets/javascript/jquery/fixtures/custom-method.js +11 -0
  91. package/dist/src/targets/javascript/jquery/fixtures/full.js +18 -0
  92. package/dist/src/targets/javascript/jquery/fixtures/headers.js +15 -0
  93. package/dist/src/targets/javascript/jquery/fixtures/http-insecure.js +11 -0
  94. package/dist/src/targets/javascript/jquery/fixtures/jsonObj-multiline.js +15 -0
  95. package/dist/src/targets/javascript/jquery/fixtures/jsonObj-null-value.js +15 -0
  96. package/dist/src/targets/javascript/jquery/fixtures/multipart-data.js +18 -0
  97. package/dist/src/targets/javascript/jquery/fixtures/multipart-file.js +17 -0
  98. package/dist/src/targets/javascript/jquery/fixtures/multipart-form-data-no-params.js +13 -0
  99. package/dist/src/targets/javascript/jquery/fixtures/multipart-form-data.js +17 -0
  100. package/dist/src/targets/javascript/jquery/fixtures/nested.js +11 -0
  101. package/dist/src/targets/javascript/jquery/fixtures/query-encoded.js +11 -0
  102. package/dist/src/targets/javascript/jquery/fixtures/query.js +11 -0
  103. package/dist/src/targets/javascript/jquery/fixtures/short.js +11 -0
  104. package/dist/src/targets/javascript/jquery/fixtures/text-plain.js +14 -0
  105. package/dist/src/targets/javascript/target.js +21 -0
  106. package/dist/src/targets/javascript/xhr/client.js +90 -0
  107. package/dist/src/targets/javascript/xhr/fixtures/application-form-encoded.js +12 -0
  108. package/dist/src/targets/javascript/xhr/fixtures/application-json.js +31 -0
  109. package/dist/src/targets/javascript/xhr/fixtures/cookies.js +12 -0
  110. package/dist/src/targets/javascript/xhr/fixtures/cors.js +10 -0
  111. package/dist/src/targets/javascript/xhr/fixtures/custom-method.js +11 -0
  112. package/dist/src/targets/javascript/xhr/fixtures/full.js +14 -0
  113. package/dist/src/targets/javascript/xhr/fixtures/headers.js +14 -0
  114. package/dist/src/targets/javascript/xhr/fixtures/http-insecure.js +11 -0
  115. package/dist/src/targets/javascript/xhr/fixtures/jsonObj-multiline.js +14 -0
  116. package/dist/src/targets/javascript/xhr/fixtures/jsonObj-null-value.js +14 -0
  117. package/dist/src/targets/javascript/xhr/fixtures/multipart-data.js +13 -0
  118. package/dist/src/targets/javascript/xhr/fixtures/multipart-file.js +12 -0
  119. package/dist/src/targets/javascript/xhr/fixtures/multipart-form-data-no-params.js +11 -0
  120. package/dist/src/targets/javascript/xhr/fixtures/multipart-form-data.js +12 -0
  121. package/dist/src/targets/javascript/xhr/fixtures/nested.js +11 -0
  122. package/dist/src/targets/javascript/xhr/fixtures/query-encoded.js +11 -0
  123. package/dist/src/targets/javascript/xhr/fixtures/query.js +11 -0
  124. package/dist/src/targets/javascript/xhr/fixtures/short.js +11 -0
  125. package/dist/src/targets/javascript/xhr/fixtures/text-plain.js +12 -0
  126. package/dist/src/targets/kotlin/okhttp/client.js +79 -0
  127. package/dist/src/targets/kotlin/target.js +15 -0
  128. package/dist/src/targets/node/axios/client.js +87 -0
  129. package/dist/src/targets/node/axios/fixtures/application-form-encoded.js +19 -0
  130. package/dist/src/targets/node/axios/fixtures/application-json.js +22 -0
  131. package/dist/src/targets/node/axios/fixtures/cookies.js +14 -0
  132. package/dist/src/targets/node/axios/fixtures/custom-method.js +10 -0
  133. package/dist/src/targets/node/axios/fixtures/full.js +22 -0
  134. package/dist/src/targets/node/axios/fixtures/headers.js +14 -0
  135. package/dist/src/targets/node/axios/fixtures/http-insecure.js +10 -0
  136. package/dist/src/targets/node/axios/fixtures/jsonObj-multiline.js +15 -0
  137. package/dist/src/targets/node/axios/fixtures/jsonObj-null-value.js +15 -0
  138. package/dist/src/targets/node/axios/fixtures/multipart-data.js +15 -0
  139. package/dist/src/targets/node/axios/fixtures/multipart-file.js +15 -0
  140. package/dist/src/targets/node/axios/fixtures/multipart-form-data-no-params.js +14 -0
  141. package/dist/src/targets/node/axios/fixtures/multipart-form-data.js +15 -0
  142. package/dist/src/targets/node/axios/fixtures/nested.js +13 -0
  143. package/dist/src/targets/node/axios/fixtures/query-encoded.js +13 -0
  144. package/dist/src/targets/node/axios/fixtures/query.js +13 -0
  145. package/dist/src/targets/node/axios/fixtures/short.js +10 -0
  146. package/dist/src/targets/node/axios/fixtures/text-plain.js +15 -0
  147. package/dist/src/targets/node/fetch/client.js +149 -0
  148. package/dist/src/targets/node/fetch/fixtures/application-form-encoded.js +15 -0
  149. package/dist/src/targets/node/fetch/fixtures/application-json.js +18 -0
  150. package/dist/src/targets/node/fetch/fixtures/cookies.js +7 -0
  151. package/dist/src/targets/node/fetch/fixtures/custom-method.js +7 -0
  152. package/dist/src/targets/node/fetch/fixtures/full.js +18 -0
  153. package/dist/src/targets/node/fetch/fixtures/headers.js +10 -0
  154. package/dist/src/targets/node/fetch/fixtures/http-insecure.js +7 -0
  155. package/dist/src/targets/node/fetch/fixtures/jsonObj-multiline.js +11 -0
  156. package/dist/src/targets/node/fetch/fixtures/jsonObj-null-value.js +11 -0
  157. package/dist/src/targets/node/fetch/fixtures/multipart-data.js +13 -0
  158. package/dist/src/targets/node/fetch/fixtures/multipart-file.js +12 -0
  159. package/dist/src/targets/node/fetch/fixtures/multipart-form-data-no-params.js +7 -0
  160. package/dist/src/targets/node/fetch/fixtures/multipart-form-data.js +11 -0
  161. package/dist/src/targets/node/fetch/fixtures/nested.js +7 -0
  162. package/dist/src/targets/node/fetch/fixtures/query-encoded.js +7 -0
  163. package/dist/src/targets/node/fetch/fixtures/query.js +7 -0
  164. package/dist/src/targets/node/fetch/fixtures/short.js +7 -0
  165. package/dist/src/targets/node/fetch/fixtures/text-plain.js +7 -0
  166. package/dist/src/targets/node/native/client.js +91 -0
  167. package/dist/src/targets/node/native/fixtures/application-form-encoded.js +24 -0
  168. package/dist/src/targets/node/native/fixtures/application-json.js +30 -0
  169. package/dist/src/targets/node/native/fixtures/cookies.js +22 -0
  170. package/dist/src/targets/node/native/fixtures/custom-method.js +20 -0
  171. package/dist/src/targets/node/native/fixtures/full.js +26 -0
  172. package/dist/src/targets/node/native/fixtures/headers.js +24 -0
  173. package/dist/src/targets/node/native/fixtures/http-insecure.js +20 -0
  174. package/dist/src/targets/node/native/fixtures/jsonObj-multiline.js +23 -0
  175. package/dist/src/targets/node/native/fixtures/jsonObj-null-value.js +23 -0
  176. package/dist/src/targets/node/native/fixtures/multipart-data.js +23 -0
  177. package/dist/src/targets/node/native/fixtures/multipart-file.js +23 -0
  178. package/dist/src/targets/node/native/fixtures/multipart-form-data-no-params.js +22 -0
  179. package/dist/src/targets/node/native/fixtures/multipart-form-data.js +23 -0
  180. package/dist/src/targets/node/native/fixtures/nested.js +20 -0
  181. package/dist/src/targets/node/native/fixtures/query-encoded.js +20 -0
  182. package/dist/src/targets/node/native/fixtures/query.js +20 -0
  183. package/dist/src/targets/node/native/fixtures/short.js +20 -0
  184. package/dist/src/targets/node/native/fixtures/text-plain.js +23 -0
  185. package/dist/src/targets/node/request/client.js +116 -0
  186. package/dist/src/targets/node/request/fixtures/application-form-encoded.js +13 -0
  187. package/dist/src/targets/node/request/fixtures/application-json.js +21 -0
  188. package/dist/src/targets/node/request/fixtures/cookies.js +11 -0
  189. package/dist/src/targets/node/request/fixtures/custom-method.js +8 -0
  190. package/dist/src/targets/node/request/fixtures/full.js +20 -0
  191. package/dist/src/targets/node/request/fixtures/headers.js +12 -0
  192. package/dist/src/targets/node/request/fixtures/http-insecure.js +8 -0
  193. package/dist/src/targets/node/request/fixtures/jsonObj-multiline.js +14 -0
  194. package/dist/src/targets/node/request/fixtures/jsonObj-null-value.js +14 -0
  195. package/dist/src/targets/node/request/fixtures/multipart-data.js +20 -0
  196. package/dist/src/targets/node/request/fixtures/multipart-file.js +19 -0
  197. package/dist/src/targets/node/request/fixtures/multipart-form-data-no-params.js +12 -0
  198. package/dist/src/targets/node/request/fixtures/multipart-form-data.js +13 -0
  199. package/dist/src/targets/node/request/fixtures/nested.js +11 -0
  200. package/dist/src/targets/node/request/fixtures/query-encoded.js +11 -0
  201. package/dist/src/targets/node/request/fixtures/query.js +11 -0
  202. package/dist/src/targets/node/request/fixtures/short.js +8 -0
  203. package/dist/src/targets/node/request/fixtures/text-plain.js +13 -0
  204. package/dist/src/targets/node/target.js +24 -0
  205. package/dist/src/targets/node/unirest/client.js +119 -0
  206. package/dist/src/targets/node/unirest/fixtures/application-form-encoded.js +15 -0
  207. package/dist/src/targets/node/unirest/fixtures/application-json.js +32 -0
  208. package/dist/src/targets/node/unirest/fixtures/cookies.js +12 -0
  209. package/dist/src/targets/node/unirest/fixtures/custom-method.js +8 -0
  210. package/dist/src/targets/node/unirest/fixtures/full.js +27 -0
  211. package/dist/src/targets/node/unirest/fixtures/headers.js +13 -0
  212. package/dist/src/targets/node/unirest/fixtures/http-insecure.js +8 -0
  213. package/dist/src/targets/node/unirest/fixtures/jsonObj-multiline.js +15 -0
  214. package/dist/src/targets/node/unirest/fixtures/jsonObj-null-value.js +15 -0
  215. package/dist/src/targets/node/unirest/fixtures/multipart-data.js +20 -0
  216. package/dist/src/targets/node/unirest/fixtures/multipart-file.js +18 -0
  217. package/dist/src/targets/node/unirest/fixtures/multipart-form-data-no-params.js +11 -0
  218. package/dist/src/targets/node/unirest/fixtures/multipart-form-data.js +16 -0
  219. package/dist/src/targets/node/unirest/fixtures/nested.js +13 -0
  220. package/dist/src/targets/node/unirest/fixtures/query-encoded.js +12 -0
  221. package/dist/src/targets/node/unirest/fixtures/query.js +16 -0
  222. package/dist/src/targets/node/unirest/fixtures/short.js +8 -0
  223. package/dist/src/targets/node/unirest/fixtures/text-plain.js +12 -0
  224. package/dist/src/targets/objc/helpers.js +59 -0
  225. package/dist/src/targets/objc/nsurlsession/client.js +151 -0
  226. package/dist/src/targets/objc/target.js +15 -0
  227. package/dist/src/targets/ocaml/cohttp/client.js +72 -0
  228. package/dist/src/targets/ocaml/target.js +15 -0
  229. package/dist/src/targets/php/curl/client.js +135 -0
  230. package/dist/src/targets/php/guzzle/client.js +126 -0
  231. package/dist/src/targets/php/helpers.js +63 -0
  232. package/dist/src/targets/php/http1/client.js +90 -0
  233. package/dist/src/targets/php/http2/client.js +128 -0
  234. package/dist/src/targets/php/target.js +22 -0
  235. package/dist/src/targets/powershell/common.js +49 -0
  236. package/dist/src/targets/powershell/restmethod/client.js +13 -0
  237. package/dist/src/targets/powershell/target.js +17 -0
  238. package/dist/src/targets/powershell/webrequest/client.js +13 -0
  239. package/dist/src/targets/python/helpers.js +70 -0
  240. package/dist/src/targets/python/requests/client.js +161 -0
  241. package/dist/src/targets/python/target.js +16 -0
  242. package/dist/src/targets/r/httr/client.js +125 -0
  243. package/dist/src/targets/r/target.js +15 -0
  244. package/dist/src/targets/ruby/native/client.js +69 -0
  245. package/dist/src/targets/ruby/target.js +15 -0
  246. package/dist/src/targets/shell/curl/client.js +171 -0
  247. package/dist/src/targets/shell/httpie/client.js +111 -0
  248. package/dist/src/targets/shell/target.js +20 -0
  249. package/dist/src/targets/shell/wget/client.js +55 -0
  250. package/dist/src/targets/swift/helpers.js +80 -0
  251. package/dist/src/targets/swift/nsurlsession/client.js +156 -0
  252. package/dist/src/targets/swift/target.js +15 -0
  253. package/dist/src/targets/targets.js +130 -0
  254. package/package.json +26 -21
  255. package/src/helpers/code-builder.js +0 -108
  256. package/src/helpers/form-data.js +0 -107
  257. package/src/helpers/headers.js +0 -48
  258. package/src/helpers/reducer.js +0 -20
  259. package/src/index.js +0 -361
  260. package/src/targets/c/index.js +0 -10
  261. package/src/targets/c/libcurl.js +0 -45
  262. package/src/targets/clojure/clj_http.js +0 -176
  263. package/src/targets/clojure/index.js +0 -10
  264. package/src/targets/csharp/httpclient.js +0 -157
  265. package/src/targets/csharp/index.js +0 -11
  266. package/src/targets/csharp/restsharp.js +0 -49
  267. package/src/targets/go/index.js +0 -10
  268. package/src/targets/go/native.js +0 -130
  269. package/src/targets/http/http1.1.js +0 -89
  270. package/src/targets/http/index.js +0 -10
  271. package/src/targets/index.js +0 -20
  272. package/src/targets/java/asynchttp.js +0 -54
  273. package/src/targets/java/index.js +0 -13
  274. package/src/targets/java/nethttp.js +0 -59
  275. package/src/targets/java/okhttp.js +0 -78
  276. package/src/targets/java/unirest.js +0 -57
  277. package/src/targets/javascript/axios.js +0 -101
  278. package/src/targets/javascript/fetch.js +0 -129
  279. package/src/targets/javascript/index.js +0 -13
  280. package/src/targets/javascript/jquery.js +0 -89
  281. package/src/targets/javascript/xhr.js +0 -86
  282. package/src/targets/kotlin/index.js +0 -10
  283. package/src/targets/kotlin/okhttp.js +0 -78
  284. package/src/targets/node/axios.js +0 -76
  285. package/src/targets/node/fetch.js +0 -145
  286. package/src/targets/node/index.js +0 -15
  287. package/src/targets/node/native.js +0 -92
  288. package/src/targets/node/request.js +0 -126
  289. package/src/targets/node/unirest.js +0 -120
  290. package/src/targets/objc/helpers.js +0 -80
  291. package/src/targets/objc/index.js +0 -10
  292. package/src/targets/objc/nsurlsession.js +0 -164
  293. package/src/targets/ocaml/cohttp.js +0 -73
  294. package/src/targets/ocaml/index.js +0 -10
  295. package/src/targets/php/curl.js +0 -142
  296. package/src/targets/php/guzzle.js +0 -135
  297. package/src/targets/php/helpers.js +0 -87
  298. package/src/targets/php/http1.js +0 -85
  299. package/src/targets/php/http2.js +0 -131
  300. package/src/targets/php/index.js +0 -14
  301. package/src/targets/powershell/common.js +0 -60
  302. package/src/targets/powershell/index.js +0 -11
  303. package/src/targets/powershell/restmethod.js +0 -8
  304. package/src/targets/powershell/webrequest.js +0 -8
  305. package/src/targets/python/helpers.js +0 -85
  306. package/src/targets/python/index.js +0 -11
  307. package/src/targets/python/requests.js +0 -163
  308. package/src/targets/r/httr.js +0 -134
  309. package/src/targets/r/index.js +0 -10
  310. package/src/targets/ruby/index.js +0 -10
  311. package/src/targets/ruby/native.js +0 -71
  312. package/src/targets/shell/curl.js +0 -157
  313. package/src/targets/shell/helpers.js +0 -23
  314. package/src/targets/shell/httpie.js +0 -129
  315. package/src/targets/shell/index.js +0 -13
  316. package/src/targets/shell/wget.js +0 -52
  317. package/src/targets/swift/helpers.js +0 -93
  318. package/src/targets/swift/index.js +0 -10
  319. package/src/targets/swift/nsurlsession.js +0 -152
@@ -1,71 +0,0 @@
1
- const CodeBuilder = require('../../helpers/code-builder');
2
-
3
- module.exports = function (source) {
4
- const code = new CodeBuilder();
5
-
6
- code.push("require 'uri'").push("require 'net/http'");
7
-
8
- if (source.uriObj.protocol === 'https:') {
9
- code.push("require 'openssl'");
10
- }
11
-
12
- code.blank();
13
-
14
- // To support custom methods we check for the supported methods
15
- // and if doesn't exist then we build a custom class for it
16
- const method = source.method.toUpperCase();
17
- const methods = [
18
- 'GET',
19
- 'POST',
20
- 'HEAD',
21
- 'DELETE',
22
- 'PATCH',
23
- 'PUT',
24
- 'OPTIONS',
25
- 'COPY',
26
- 'LOCK',
27
- 'UNLOCK',
28
- 'MOVE',
29
- 'TRACE',
30
- ];
31
- const capMethod = method.charAt(0) + method.substring(1).toLowerCase();
32
- if (methods.indexOf(method) < 0) {
33
- code
34
- .push('class Net::HTTP::%s < Net::HTTPRequest', capMethod)
35
- .push(" METHOD = '%s'", method.toUpperCase())
36
- .push(" REQUEST_HAS_BODY = '%s'", source.postData.text ? 'true' : 'false')
37
- .push(' RESPONSE_HAS_BODY = true')
38
- .push('end')
39
- .blank();
40
- }
41
-
42
- code.push('url = URI("%s")', source.fullUrl).blank().push('http = Net::HTTP.new(url.host, url.port)');
43
-
44
- if (source.uriObj.protocol === 'https:') {
45
- code.push('http.use_ssl = true');
46
- }
47
-
48
- code.blank().push('request = Net::HTTP::%s.new(url)', capMethod);
49
-
50
- const headers = Object.keys(source.allHeaders);
51
- if (headers.length) {
52
- headers.forEach(function (key) {
53
- code.push('request["%s"] = \'%s\'', key, source.allHeaders[key]);
54
- });
55
- }
56
-
57
- if (source.postData.text) {
58
- code.push('request.body = %s', JSON.stringify(source.postData.text));
59
- }
60
-
61
- code.blank().push('response = http.request(request)').push('puts response.read_body');
62
-
63
- return code.join();
64
- };
65
-
66
- module.exports.info = {
67
- key: 'native',
68
- title: 'net::http',
69
- link: 'http://ruby-doc.org/stdlib-2.2.1/libdoc/net/http/rdoc/Net/HTTP.html',
70
- description: 'Ruby HTTP client',
71
- };
@@ -1,157 +0,0 @@
1
- /**
2
- * @description
3
- * HTTP code snippet generator for the Shell using cURL.
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 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
- indent: ' ',
19
- short: false,
20
- binary: false,
21
- globOff: false,
22
- escapeBrackets: false,
23
- ...options,
24
- };
25
-
26
- const code = new CodeBuilder(opts.indent, opts.indent !== false ? ` \\\n${opts.indent}` : ' ');
27
-
28
- const globOption = opts.short ? '-g' : '--globoff';
29
- const requestOption = opts.short ? '-X' : '--request';
30
- let formattedUrl = helpers.quote(source.fullUrl);
31
-
32
- if (opts.escapeBrackets) {
33
- formattedUrl = formattedUrl.replace(/\[/g, '\\[').replace(/\]/g, '\\]');
34
- }
35
-
36
- code.push('curl %s %s', requestOption, source.method);
37
- if (opts.globOff) {
38
- formattedUrl = unescape(formattedUrl);
39
- code.push(globOption);
40
- }
41
- code.push(format('%s%s', opts.short ? '' : '--url ', formattedUrl));
42
-
43
- if (source.httpVersion === 'HTTP/1.0') {
44
- code.push(opts.short ? '-0' : '--http1.0');
45
- }
46
-
47
- // if multipart form data, we want to remove the boundary
48
- if (source.postData.mimeType === 'multipart/form-data') {
49
- const contentTypeHeaderName = headerHelpers.getHeaderName(source.headersObj, 'content-type');
50
- const contentTypeHeader = source.headersObj[contentTypeHeaderName];
51
-
52
- if (contentTypeHeaderName && contentTypeHeader) {
53
- // remove the leading semi colon and boundary
54
- // up to the next semi colon or the end of string
55
- const noBoundary = contentTypeHeader.replace(/; boundary.+?(?=(;|$))/, '');
56
-
57
- // replace the content-type header with no boundary in both headersObj and allHeaders
58
- source.headersObj[contentTypeHeaderName] = noBoundary; // eslint-disable-line no-param-reassign
59
- source.allHeaders[contentTypeHeaderName] = noBoundary; // eslint-disable-line no-param-reassign
60
- }
61
- }
62
-
63
- // construct headers
64
- Object.keys(source.headersObj)
65
- .sort()
66
- .forEach(function (key) {
67
- const header = format('%s: %s', key, source.headersObj[key]);
68
- code.push('%s %s', opts.short ? '-H' : '--header', helpers.quote(header));
69
- });
70
-
71
- if (source.allHeaders.cookie) {
72
- code.push('%s %s', opts.short ? '-b' : '--cookie', helpers.quote(source.allHeaders.cookie));
73
- }
74
-
75
- // construct post params
76
- switch (source.postData.mimeType) {
77
- case 'multipart/form-data':
78
- if (source.postData.params) {
79
- source.postData.params.forEach(function (param) {
80
- let post = '';
81
- if (param.fileName) {
82
- post = format('%s=@%s', param.name, param.fileName);
83
- } else {
84
- post = format('%s=%s', param.name, param.value);
85
- }
86
-
87
- code.push('%s %s', opts.short ? '-F' : '--form', helpers.quote(post));
88
- });
89
- }
90
- break;
91
-
92
- case 'application/x-www-form-urlencoded':
93
- if (source.postData.params) {
94
- source.postData.params.forEach(function (param) {
95
- code.push(
96
- '%s %s',
97
- opts.binary ? '--data-binary' : opts.short ? '-d' : '--data',
98
- helpers.quote(format('%s=%s', param.name, param.value))
99
- );
100
- });
101
- } else {
102
- code.push(
103
- '%s %s',
104
- opts.binary ? '--data-binary' : opts.short ? '-d' : '--data',
105
- helpers.quote(source.postData.text)
106
- );
107
- }
108
- break;
109
-
110
- default:
111
- // raw request body
112
- if (source.postData.text) {
113
- let builtPayload = false;
114
-
115
- // If we're dealing with a JSON variant, and our payload is JSON let's make it look a little nicer.
116
- if (headerHelpers.isMimeTypeJson(source.postData.mimeType)) {
117
- // If our postData is less than 20 characters, let's keep it all on one line so as to not make the snippet
118
- // overly lengthy
119
- if (source.postData.text.length > 20) {
120
- try {
121
- const jsonPayload = JSON.parse(source.postData.text);
122
-
123
- // If the JSON object has a single quote we should prepare it inside of a HEREDOC because the single
124
- // quote in something like `string's` can't be escaped when used with `--data`.
125
- //
126
- // Basically this boils down to `--data @- <<EOF...EOF` vs `--data '...'`.
127
- builtPayload = true;
128
- code.push(
129
- source.postData.text.indexOf("'") > 0 ? '%s @- <<EOF\n%s\nEOF' : "%s '\n%s\n'",
130
- opts.binary ? '--data-binary' : opts.short ? '-d' : '--data',
131
- JSON.stringify(jsonPayload, null, opts.indent)
132
- );
133
- } catch (err) {
134
- // no-op
135
- }
136
- }
137
- }
138
-
139
- if (!builtPayload) {
140
- code.push(
141
- '%s %s',
142
- opts.binary ? '--data-binary' : opts.short ? '-d' : '--data',
143
- helpers.quote(source.postData.text)
144
- );
145
- }
146
- }
147
- }
148
-
149
- return code.join();
150
- };
151
-
152
- module.exports.info = {
153
- key: 'curl',
154
- title: 'cURL',
155
- link: 'http://curl.haxx.se/',
156
- description: 'cURL is a command line tool and library for transferring data with URL syntax',
157
- };
@@ -1,23 +0,0 @@
1
- const { format } = require('util');
2
-
3
- module.exports = {
4
- /**
5
- * Use 'strong quoting' using single quotes so that we only need
6
- * to deal with nested single quote characters.
7
- * http://wiki.bash-hackers.org/syntax/quoting#strong_quoting
8
- */
9
- quote: function (value) {
10
- const safe = /^[a-z0-9-_/.@%^=:]+$/i;
11
-
12
- // Unless `value` is a simple shell-safe string, quote it.
13
- if (!safe.test(value)) {
14
- return format("'%s'", value.replace(/'/g, "'\\''"));
15
- }
16
-
17
- return value;
18
- },
19
-
20
- escape: function (value) {
21
- return value.replace(/\r/g, '\\r').replace(/\n/g, '\\n');
22
- },
23
- };
@@ -1,129 +0,0 @@
1
- /**
2
- * @description
3
- * HTTP code snippet generator for the Shell using HTTPie.
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 shell = require('./helpers');
13
- const CodeBuilder = require('../../helpers/code-builder');
14
-
15
- module.exports = function (source, options) {
16
- const opts = {
17
- body: false,
18
- cert: false,
19
- headers: false,
20
- indent: ' ',
21
- pretty: false,
22
- print: false,
23
- queryParams: false,
24
- short: false,
25
- style: false,
26
- timeout: false,
27
- verbose: false,
28
- verify: false,
29
- ...options,
30
- };
31
-
32
- const code = new CodeBuilder(opts.indent, opts.indent !== false ? ` \\\n${opts.indent}` : ' ');
33
-
34
- let raw = false;
35
- const flags = [];
36
-
37
- if (opts.headers) {
38
- flags.push(opts.short ? '-h' : '--headers');
39
- }
40
-
41
- if (opts.body) {
42
- flags.push(opts.short ? '-b' : '--body');
43
- }
44
-
45
- if (opts.verbose) {
46
- flags.push(opts.short ? '-v' : '--verbose');
47
- }
48
-
49
- if (opts.print) {
50
- flags.push(format('%s=%s', opts.short ? '-p' : '--print', opts.print));
51
- }
52
-
53
- if (opts.verify) {
54
- flags.push(format('--verify=%s', opts.verify));
55
- }
56
-
57
- if (opts.cert) {
58
- flags.push(format('--cert=%s', opts.cert));
59
- }
60
-
61
- if (opts.pretty) {
62
- flags.push(format('--pretty=%s', opts.pretty));
63
- }
64
-
65
- if (opts.style) {
66
- flags.push(format('--style=%s', opts.pretty));
67
- }
68
-
69
- if (opts.timeout) {
70
- flags.push(format('--timeout=%s', opts.timeout));
71
- }
72
-
73
- // construct query params
74
- if (opts.queryParams) {
75
- const queryStringKeys = Object.keys(source.queryObj);
76
-
77
- queryStringKeys.forEach(function (name) {
78
- const value = source.queryObj[name];
79
-
80
- if (Array.isArray(value)) {
81
- value.forEach(function (val) {
82
- code.push('%s==%s', name, shell.quote(val));
83
- });
84
- } else {
85
- code.push('%s==%s', name, shell.quote(value));
86
- }
87
- });
88
- }
89
-
90
- // construct headers
91
- Object.keys(source.allHeaders)
92
- .sort()
93
- .forEach(function (key) {
94
- code.push('%s:%s', key, shell.quote(source.allHeaders[key]));
95
- });
96
-
97
- if (source.postData.mimeType === 'application/x-www-form-urlencoded') {
98
- // construct post params
99
- if (source.postData.params && source.postData.params.length) {
100
- flags.push(opts.short ? '-f' : '--form');
101
-
102
- source.postData.params.forEach(function (param) {
103
- code.push('%s=%s', param.name, shell.quote(param.value));
104
- });
105
- }
106
- } else {
107
- raw = true;
108
- }
109
-
110
- code.unshift(
111
- 'http %s%s %s',
112
- flags.length ? `${flags.join(' ')} ` : '',
113
- source.method,
114
- shell.quote(opts.queryParams ? source.url : source.fullUrl)
115
- );
116
-
117
- if (raw && source.postData.text) {
118
- code.unshift('echo %s | ', shell.quote(source.postData.text));
119
- }
120
-
121
- return code.join();
122
- };
123
-
124
- module.exports.info = {
125
- key: 'httpie',
126
- title: 'HTTPie',
127
- link: 'http://httpie.org/',
128
- description: 'a CLI, cURL-like tool for humans',
129
- };
@@ -1,13 +0,0 @@
1
- module.exports = {
2
- info: {
3
- key: 'shell',
4
- title: 'Shell',
5
- extname: '.sh',
6
- default: 'curl',
7
- cli: '%s',
8
- },
9
-
10
- curl: require('./curl'),
11
- httpie: require('./httpie'),
12
- wget: require('./wget'),
13
- };
@@ -1,52 +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
-
11
- const { format } = require('util');
12
- const helpers = require('./helpers');
13
- const CodeBuilder = require('../../helpers/code-builder');
14
-
15
- module.exports = function (source, options) {
16
- const opts = {
17
- indent: ' ',
18
- short: false,
19
- verbose: false,
20
- ...options,
21
- };
22
-
23
- const code = new CodeBuilder(opts.indent, opts.indent !== false ? ` \\\n${opts.indent}` : ' ');
24
-
25
- if (opts.verbose) {
26
- code.push('wget %s', opts.short ? '-v' : '--verbose');
27
- } else {
28
- code.push('wget %s', opts.short ? '-q' : '--quiet');
29
- }
30
-
31
- code.push('--method %s', helpers.quote(source.method));
32
-
33
- Object.keys(source.allHeaders).forEach(function (key) {
34
- const header = format('%s: %s', key, source.allHeaders[key]);
35
- code.push('--header %s', helpers.quote(header));
36
- });
37
-
38
- if (source.postData.text) {
39
- code.push(`--body-data ${helpers.escape(helpers.quote(source.postData.text))}`);
40
- }
41
-
42
- code.push(opts.short ? '-O' : '--output-document').push('- %s', helpers.quote(source.fullUrl));
43
-
44
- return code.join();
45
- };
46
-
47
- module.exports.info = {
48
- key: 'wget',
49
- title: 'Wget',
50
- link: 'https://www.gnu.org/software/wget/',
51
- description: 'a free software package for retrieving files using HTTP, HTTPS',
52
- };
@@ -1,93 +0,0 @@
1
- const { format } = require('util');
2
-
3
- /**
4
- * Create an string of given length filled with blank spaces
5
- *
6
- * @param {number} length Length of the array to return
7
- * @param {string} str String to pad out with
8
- * @return {string}
9
- */
10
- function buildString(length, str) {
11
- // eslint-disable-next-line prefer-spread
12
- return Array.apply(null, new Array(length)).map(String.prototype.valueOf, str).join('');
13
- }
14
-
15
- /**
16
- * Create a string corresponding to a Dictionary or Array literal representation with pretty option
17
- * and indentation.
18
- */
19
- function concatArray(arr, pretty, indentation, indentLevel) {
20
- const currentIndent = buildString(indentLevel, indentation);
21
- const closingBraceIndent = buildString(indentLevel - 1, indentation);
22
- const join = pretty ? `,\n${currentIndent}` : ', ';
23
-
24
- if (pretty) {
25
- return `[\n${currentIndent}${arr.join(join)}\n${closingBraceIndent}]`;
26
- }
27
-
28
- return `[${arr.join(join)}]`;
29
- }
30
-
31
- module.exports = {
32
- /**
33
- * Create a string corresponding to a valid declaration and initialization of a Swift array or dictionary literal
34
- *
35
- * @param {string} name Desired name of the instance
36
- * @param {Object} parameters Key-value object of parameters to translate to a Swift object litearal
37
- * @param {Object} opts Target options
38
- * @return {string}
39
- */
40
- literalDeclaration: function (name, parameters, opts) {
41
- return format('let %s = %s', name, this.literalRepresentation(parameters, opts));
42
- },
43
-
44
- /**
45
- * Create a valid Swift string of a literal value according to its type.
46
- *
47
- * @param {*} value Any JavaScript literal
48
- * @param {Object} opts Target options
49
- * @return {string}
50
- */
51
- literalRepresentation: function (value, opts, indentLevel) {
52
- // eslint-disable-next-line no-param-reassign
53
- indentLevel = indentLevel === undefined ? 1 : indentLevel + 1;
54
-
55
- switch (Object.prototype.toString.call(value)) {
56
- case '[object Number]':
57
- return value;
58
-
59
- case '[object Array]': {
60
- // Don't prettify arrays nto not take too much space
61
- let pretty = false;
62
- const valuesRepresentation = value.map(
63
- function (v) {
64
- // Switch to prettify if the value is a dictionary with multiple keys
65
- if (Object.prototype.toString.call(v) === '[object Object]') {
66
- pretty = Object.keys(v).length > 1;
67
- }
68
- return this.literalRepresentation(v, opts, indentLevel);
69
- }.bind(this)
70
- );
71
- return concatArray(valuesRepresentation, pretty, opts.indent, indentLevel);
72
- }
73
-
74
- case '[object Object]': {
75
- const keyValuePairs = [];
76
- // eslint-disable-next-line guard-for-in, no-restricted-syntax
77
- for (const k in value) {
78
- keyValuePairs.push(format('"%s": %s', k, this.literalRepresentation(value[k], opts, indentLevel)));
79
- }
80
- return concatArray(keyValuePairs, opts.pretty && keyValuePairs.length > 1, opts.indent, indentLevel);
81
- }
82
-
83
- case '[object Boolean]':
84
- return value.toString();
85
-
86
- default:
87
- if (value === null || value === undefined) {
88
- return '';
89
- }
90
- return `"${value.toString().replace(/"/g, '\\"')}"`;
91
- }
92
- },
93
- };
@@ -1,10 +0,0 @@
1
- module.exports = {
2
- info: {
3
- key: 'swift',
4
- title: 'Swift',
5
- extname: '.swift',
6
- default: 'nsurlsession',
7
- },
8
-
9
- nsurlsession: require('./nsurlsession'),
10
- };