Skip to content

Commit

Permalink
tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
filfreire committed Jul 12, 2024
1 parent 578a8a6 commit bbc985b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"clean": "tsc --build tsconfig.build.json --clean",
"prebuild": "npm run clean",
"lint": "npm run lint:prettify && npm run lint:code && npm run lint:markdown",
"lint:prettify": "prettier --check --max-warnings=0 .",
"lint:prettify": "prettier --check .",
"lint:code": "eslint . --ext ts,d.ts,test.ts",
"lint:markdown": "markdownlint-cli2 \"**/*.md\" \"#**/node_modules\"",
"lint:fix": "npm run lint:prettify:fix && npm run lint:code:fix && npm run lint:markdown:fix",
Expand Down
6 changes: 4 additions & 2 deletions src/targets/powershell/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const generatePowershellConvert = (command: PowershellCommand) => {
'PATCH',
'POST',
'PUT',
'TRACE'
'TRACE',
];
const methodArg = methods.includes(method.toUpperCase()) ? '-Method' : '-CustomMethod';

Expand Down Expand Up @@ -73,7 +73,9 @@ export const generatePowershellConvert = (command: PowershellCommand) => {
commandOptions.push(`-Body '${postData.text}'`);
}

push(`$response = ${command} -Uri '${fullUrl}' ${methodArg} ${method} ${commandOptions.join(' ')}`);
push(
`$response = ${command} -Uri '${fullUrl}' ${methodArg} ${method} ${commandOptions.join(' ')}`,
);
return join();
};
return convert;
Expand Down
24 changes: 14 additions & 10 deletions src/targets/ruby/faraday/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const faraday: Client = {
link: 'https://github.com/lostisland/faraday',
description: 'Faraday HTTP client',
},
convert: ({ uriObj, queryObj, method: rawMethod, fullUrl, postData, allHeaders }, options = {}) => {
convert: ({ uriObj, queryObj, method: rawMethod, postData, allHeaders }) => {
const { push, blank, join } = new CodeBuilder();

// To support custom methods we check for the supported methods
Expand All @@ -30,16 +30,16 @@ export const faraday: Client = {
'TRACE',
];

if(!methods.includes(method)) {
push(`# Faraday cannot currently run ${method} requests. Please use another client.`)
if (!methods.includes(method)) {
push(`# Faraday cannot currently run ${method} requests. Please use another client.`);
return join();
}

push("require 'faraday'");
blank();

// Write body to beginning of script
if(postData.mimeType === 'application/x-www-form-urlencoded') {
if (postData.mimeType === 'application/x-www-form-urlencoded') {
if (postData.params) {
push(`data = {`);
postData.params.forEach(param => {
Expand All @@ -52,8 +52,12 @@ export const faraday: Client = {

push(`conn = Faraday.new(`);
push(` url: '${uriObj.protocol}//${uriObj.host}',`);
if(allHeaders['content-type'] || allHeaders['Content-Type']) {
push(` headers: {'Content-Type' => '${allHeaders['content-type'] || allHeaders['Content-Type']}'}`);
if (allHeaders['content-type'] || allHeaders['Content-Type']) {
push(
` headers: {'Content-Type' => '${
allHeaders['content-type'] || allHeaders['Content-Type']
}'}`,
);
}
push(`)`);

Expand All @@ -63,7 +67,7 @@ export const faraday: Client = {
const headers = Object.keys(allHeaders);
if (headers.length) {
headers.forEach(key => {
if(key.toLowerCase() !== 'content-type') {
if (key.toLowerCase() !== 'content-type') {
push(` req.headers['${key}'] = '${escapeForSingleQuotes(allHeaders[key])}'`);
}
});
Expand All @@ -72,9 +76,9 @@ export const faraday: Client = {
Object.keys(queryObj).forEach(name => {
const value = queryObj[name];
if (Array.isArray(value)) {
push(` req.params['${name}'] = ${JSON.stringify(value)}`)
push(` req.params['${name}'] = ${JSON.stringify(value)}`);
} else {
push(` req.params['${name}'] = '${value}'`)
push(` req.params['${name}'] = '${value}'`);
}
});

Expand All @@ -98,7 +102,7 @@ export const faraday: Client = {
}

push('end');
blank()
blank();
push('puts response.status');
push('puts response.body');

Expand Down
4 changes: 2 additions & 2 deletions src/targets/ruby/target.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Target } from '../targets';
import { native } from './native/client';
import { faraday } from './faraday/client';
import { native } from './native/client';

export const ruby: Target = {
info: {
Expand All @@ -11,6 +11,6 @@ export const ruby: Target = {
},
clientsById: {
native,
faraday
faraday,
},
};

0 comments on commit bbc985b

Please sign in to comment.