Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

Commit

Permalink
include formData in client
Browse files Browse the repository at this point in the history
  • Loading branch information
taylordowns2000 committed Dec 6, 2019
1 parent d57e81b commit c73cfc9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 33 deletions.
1 change: 1 addition & 0 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function req(method, params) {
qs: query,
method: method,
json: body,
formData: formData,
jar: j
}, rest), function (error, response, body) {
error = (0, _Utils.assembleError)({ error: error, response: response });
Expand Down
72 changes: 39 additions & 33 deletions src/Client.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,59 @@
import request from 'request'
import request from 'request';
import { assembleError, tryJson } from './Utils';

export function rawRequest(params) {
return new Promise((resolve, reject) => {
request(params, (error, response, body) => {
error = assembleError({error, response})
error = assembleError({ error, response });
error && reject(error);

console.log(`✓ Request succeeded.`);
console.log(`Server responded with: \n${JSON.stringify(response, null, 2)}`);
console.log(
`Server responded with: \n${JSON.stringify(response, null, 2)}`
);
const resp = tryJson(body);
resolve(resp);
})
})
});
});
}

export function req( method, params ) {
export function req(method, params) {
const { url, headers, body, auth, query, rest } = params;
return new Promise((resolve, reject) => {
const j = request.jar();
request ({
url,
headers,
auth,
qs: query,
method: method,
json: body,
jar: j,
...rest
}, function(error, response, body){
error = assembleError({error, response})
if(error) {
reject(error);
} else {
console.log(`✓ ${method} succeeded.`);
console.log(`Server responded with: \n${JSON.stringify(response, null, 2)}`);
const resp = tryJson(body);
if(rest.keepCookie) {
const __cookie = j.getCookieString(url);
resolve({
__cookie,
...resp
});
request(
{
url,
headers,
auth,
qs: query,
method: method,
json: body,
formData: formData,
jar: j,
...rest,
},
function(error, response, body) {
error = assembleError({ error, response });
if (error) {
reject(error);
} else {
resolve(
resp
console.log(`✓ ${method} succeeded.`);
console.log(
`Server responded with: \n${JSON.stringify(response, null, 2)}`
);
const resp = tryJson(body);
if (rest.keepCookie) {
const __cookie = j.getCookieString(url);
resolve({
__cookie,
...resp,
});
} else {
resolve(resp);
}
}
}
})
})
);
});
}

0 comments on commit c73cfc9

Please sign in to comment.