slate/components/api-docs/v2/get-slate.js

84 lines
2.0 KiB
JavaScript
Raw Normal View History

2021-04-21 03:14:43 +03:00
import * as React from "react";
import * as System from "~/components/system";
import CodeBlock from "~/components/system/CodeBlock";
const EXAMPLE_CODE_JS = (
key,
slateId
) => `const response = await fetch('https://slate.host/api/v2/get-collection', {
2021-04-21 03:14:43 +03:00
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Basic ${key}',
},
body: JSON.stringify({ data: {
id: '${slateId}' // collection ID
2021-04-21 03:14:43 +03:00
}})
});
if (!response) {
console.log("No response");
2021-05-26 23:05:13 +03:00
return;
}
if (!response.ok) {
console.log(response.error);
return response.error;
2021-04-21 03:14:43 +03:00
}
const json = await response.json();
if (json.error) {
console.log(json.error);
} else {
const collection = json.collection;
2021-04-21 03:14:43 +03:00
}`;
const EXAMPLE_CODE_PY = (key, slateId) => `import requests
import json as JSON
url = 'https://slate.host/api/v2/get-collection'
2021-04-21 03:14:43 +03:00
headers = {
'content-type': 'application/json',
'Authorization': 'Basic ${key}'
}
json = {
"data": {
"id": "${slateId}" # collection ID
2021-04-21 03:14:43 +03:00
}
}
r = requests.post(url, headers=headers, json=json)`;
export default class APIDocsGetCollection extends React.Component {
2021-04-21 03:14:43 +03:00
render() {
let APIKey = this.props.APIKey;
let slateId = this.props.slateId;
let language = this.props.language;
let code = {
javascript: EXAMPLE_CODE_JS(APIKey, slateId),
python: EXAMPLE_CODE_PY(APIKey, slateId),
};
return (
<React.Fragment>
<System.DescriptionGroup
style={{ maxWidth: 640, marginTop: 64 }}
label="Get collection by ID"
description="This API request will return a specific collection. You can save the response locally and send this JSON back to our API server using the route /api/v2/update-collection to update your collection."
2021-04-21 03:14:43 +03:00
/>
<CodeBlock
children={code}
style={{ maxWidth: "820px" }}
language={language}
title="Get collection by ID"
2021-04-21 03:14:43 +03:00
onLanguageChange={this.props.onLanguageChange}
multiLang="true"
/>
</React.Fragment>
);
}
}