Skip to content

Commit 4381611

Browse files
committed
fix: pr feedback
1 parent e3f7991 commit 4381611

File tree

10 files changed

+25
-18
lines changed

10 files changed

+25
-18
lines changed

src/helpers/__snapshots__/utils.test.ts.snap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ exports[`availableTargets > returns all available targets 1`] = `
4444
{
4545
"description": "Simple REST and HTTP API Client for .NET",
4646
"extname": ".cs",
47+
"installation": [Function],
4748
"key": "restsharp",
4849
"link": "http://restsharp.org/",
4950
"title": "RestSharp",
@@ -129,6 +130,7 @@ exports[`availableTargets > returns all available targets 1`] = `
129130
{
130131
"description": "Promise based HTTP client for the browser and node.js",
131132
"extname": ".js",
133+
"installation": [Function],
132134
"key": "axios",
133135
"link": "https://github.com/axios/axios",
134136
"title": "Axios",
@@ -193,6 +195,7 @@ exports[`availableTargets > returns all available targets 1`] = `
193195
{
194196
"description": "Promise based HTTP client for the browser and node.js",
195197
"extname": ".js",
198+
"installation": [Function],
196199
"key": "axios",
197200
"link": "https://github.com/axios/axios",
198201
"title": "Axios",
@@ -228,6 +231,7 @@ exports[`availableTargets > returns all available targets 1`] = `
228231
{
229232
"description": "Cohttp is a very lightweight HTTP server using Lwt or Async for OCaml",
230233
"extname": ".ml",
234+
"installation": [Function],
231235
"key": "cohttp",
232236
"link": "https://github.com/mirage/ocaml-cohttp",
233237
"title": "CoHTTP",
@@ -250,6 +254,7 @@ exports[`availableTargets > returns all available targets 1`] = `
250254
{
251255
"description": "PHP with Guzzle",
252256
"extname": ".php",
257+
"installation": [Function],
253258
"key": "guzzle",
254259
"link": "http://docs.guzzlephp.org/en/stable/",
255260
"title": "Guzzle",
@@ -300,6 +305,7 @@ exports[`availableTargets > returns all available targets 1`] = `
300305
{
301306
"description": "Requests HTTP library",
302307
"extname": ".py",
308+
"installation": [Function],
303309
"key": "requests",
304310
"link": "http://docs.python-requests.org/en/latest/api/#requests.request",
305311
"title": "Requests",
@@ -350,6 +356,7 @@ exports[`availableTargets > returns all available targets 1`] = `
350356
{
351357
"description": "a CLI, cURL-like tool for humans",
352358
"extname": ".sh",
359+
"installation": [Function],
353360
"key": "httpie",
354361
"link": "http://httpie.org/",
355362
"title": "HTTPie",

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,11 @@ export class HTTPSnippet {
348348

349349
const target = targets[targetId];
350350
if (!target) {
351-
return false;
351+
return [false];
352352
}
353353

354-
const { installation } = target.clientsById[clientId || target.info.default];
355-
const results = this.requests.map(request => (installation ? installation(request, options) : false));
354+
const { info } = target.clientsById[clientId || target.info.default];
355+
const results = this.requests.map(request => (info?.installation ? info.installation(request, options) : false));
356356
return results;
357357
}
358358
}

src/targets/csharp/restsharp/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export const restsharp: Client = {
1414
link: 'http://restsharp.org/',
1515
description: 'Simple REST and HTTP API Client for .NET',
1616
extname: '.cs',
17+
installation: () => 'dotnet add package RestSharp',
1718
},
18-
installation: () => 'dotnet add package RestSharp',
1919
convert: ({ method, fullUrl, headersObj, cookies, postData, uriObj }) => {
2020
const { push, join } = new CodeBuilder();
2121
const isSupportedMethod = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'].includes(

src/targets/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,15 @@ export type TargetId = keyof typeof targets;
2626

2727
export type ClientId = string;
2828

29-
export interface ClientInfo {
29+
export interface ClientInfo<T extends Record<string, any> = Record<string, any>> {
3030
description: string;
3131
extname: Extension;
32+
/**
33+
* Retrieve or generate a command to install the client.
34+
*
35+
* @example `npm install axios`
36+
*/
37+
installation?: Converter<T>;
3238
key: ClientId;
3339
link: string;
3440
title: string;
@@ -41,13 +47,7 @@ export type Converter<T extends Record<string, any>> = (
4147

4248
export interface Client<T extends Record<string, any> = Record<string, any>> {
4349
convert: Converter<T>;
44-
info: ClientInfo;
45-
/**
46-
* Generates a command to install the client.
47-
*
48-
* @example `npm install axios`
49-
*/
50-
installation?: Converter<T>;
50+
info: ClientInfo<T>;
5151
}
5252

5353
export interface ClientPlugin<T extends Record<string, any> = Record<string, any>> {

src/targets/javascript/axios/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export const axios: Client = {
2020
link: 'https://github.com/axios/axios',
2121
description: 'Promise based HTTP client for the browser and node.js',
2222
extname: '.js',
23+
installation: () => 'npm install axios --save',
2324
},
24-
installation: () => 'npm install axios --save',
2525
convert: ({ allHeaders, method, url, queryObj, postData }, options) => {
2626
const opts = {
2727
indent: ' ',

src/targets/node/axios/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export const axios: Client = {
2020
link: 'https://github.com/axios/axios',
2121
description: 'Promise based HTTP client for the browser and node.js',
2222
extname: '.js',
23+
installation: () => 'npm install axios --save',
2324
},
24-
installation: () => 'npm install axios --save',
2525
convert: ({ method, fullUrl, allHeaders, postData }, options) => {
2626
const opts = {
2727
indent: ' ',

src/targets/ocaml/cohttp/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export const cohttp: Client = {
1919
link: 'https://github.com/mirage/ocaml-cohttp',
2020
description: 'Cohttp is a very lightweight HTTP server using Lwt or Async for OCaml',
2121
extname: '.ml',
22+
installation: () => 'opam install cohttp-lwt-unix cohttp-async',
2223
},
23-
installation: () => 'opam install cohttp-lwt-unix cohttp-async',
2424
convert: ({ fullUrl, allHeaders, postData, method }, options) => {
2525
const opts = {
2626
indent: ' ',

src/targets/php/guzzle/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export const guzzle: Client<GuzzleOptions> = {
2828
link: 'http://docs.guzzlephp.org/en/stable/',
2929
description: 'PHP with Guzzle',
3030
extname: '.php',
31+
installation: () => 'composer require guzzlehttp/guzzle',
3132
},
32-
installation: () => 'composer require guzzlehttp/guzzle',
3333
convert: ({ postData, fullUrl, method, cookies, headersObj }, options) => {
3434
const opts = {
3535
closingTag: false,

src/targets/python/requests/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ export const requests: Client<RequestsOptions> = {
2727
link: 'http://docs.python-requests.org/en/latest/api/#requests.request',
2828
description: 'Requests HTTP library',
2929
extname: '.py',
30+
installation: () => 'python -m pip install requests',
3031
},
31-
installation: () => 'python -m pip install requests',
3232
convert: ({ fullUrl, postData, allHeaders, method }, options) => {
3333
const opts = {
3434
indent: ' ',

src/targets/shell/httpie/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ export const httpie: Client<HttpieOptions> = {
3333
link: 'http://httpie.org/',
3434
description: 'a CLI, cURL-like tool for humans',
3535
extname: '.sh',
36+
installation: () => 'brew install httpie',
3637
},
37-
installation: () => 'brew install httpie',
3838
convert: ({ allHeaders, postData, queryObj, fullUrl, method, url }, options) => {
3939
const opts = {
4040
body: false,

0 commit comments

Comments
 (0)