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

Commit

Permalink
Begin refactor of endpoint functions
Browse files Browse the repository at this point in the history
  • Loading branch information
uppal101 committed Oct 3, 2017
1 parent a7141e0 commit 8e7ad69
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/api-explorer-ui/src/Doc.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Doc extends React.Component {
loading: false,
showAuthBox: false,
needsAuth: false,
responseTabClass: 'hub-reference-right hub-reference-results tabber-parent',
};
this.onChange = this.onChange.bind(this);
this.oas = new Oas(this.props.oas);
Expand Down Expand Up @@ -75,8 +76,7 @@ class Doc extends React.Component {
formData={this.state.formData}
/>
</div>
{/* TODO add ClassNames*/}
<div className="hub-reference-right hub-reference-results tabber-parent">
<div className={this.state.responseTabClass}>
<div className="hub-reference-results-slider">
<div className="hub-reference-results-explorer code-sample" />
<div className="hub-reference-results-examples code-sample">
Expand Down
37 changes: 37 additions & 0 deletions packages/api-explorer-ui/src/lib/code-sample-response.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const { constructRequest } = require('fetch-har');
const { statusCodes } = require('./statuscodes');

const req = constructRequest;

function result(res) {
const data = res.responseJSON ? JSON.stringify(res.responseJSON, undefined, 2) : res.responseText;

const isBinary = !!res.getAllResponseHeaders().match(/Content-Disposition: attachment;/);

const headersFormatted = [];

req.headers.forEach((ele, i) => {
headersFormatted.push(`${i} : ${ele}`);
});

let responseHeaders = res.getAllResponseHeaders();
responseHeaders = responseHeaders
.filter(responseHeaders.split('\n'), v => !v.match(/x-final-url:/i))
.join('\n');

const results = {
init: true,
method: req.method,
requestHeaders: headersFormatted.join('\n'),
responseHeaders,
isBinary,
url: req.url,
data: res.responseText,
statusCode: statusCodes(res.status || 404),
dataString: data,
};

this.setState({ responseTabClass: 'hub-reference-right hub-reference-results tabber-parent on' });

setTab('[data-tab=result]');
}

0 comments on commit 8e7ad69

Please sign in to comment.