slate/components/api-docs/v1/update-slate.js

79 lines
2.1 KiB
JavaScript
Raw Normal View History

2021-03-24 07:10:26 +03:00
import * as React from "react";
import * as System from "~/components/system";
import CodeBlock from "~/components/system/CodeBlock";
2021-03-24 07:10:26 +03:00
2021-03-25 07:28:14 +03:00
const EXAMPLE_CODE_JS = (key, slateId) => {
2021-04-23 07:18:02 +03:00
return `const COLLECTION_ID = "${slateId}"
2021-03-24 07:10:26 +03:00
2021-04-23 07:18:02 +03:00
const collectionResponseData = getCollectionById(COLLECTION_ID);
2021-03-24 07:10:26 +03:00
2021-04-23 07:18:02 +03:00
const collection = collectionResponseData.slate;
collection.data.name = "New title"
2021-03-24 07:10:26 +03:00
const response = await fetch('https://slate.host/api/v1/update-slate', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
2021-04-21 03:14:43 +03:00
Authorization: 'Basic ${key}', // API key
2021-03-24 07:10:26 +03:00
},
2021-04-23 07:18:02 +03:00
body: JSON.stringify({ data: collection })
2021-03-30 04:35:06 +03:00
});`;
2021-03-24 07:10:26 +03:00
};
2021-03-30 04:19:36 +03:00
const EXAMPLE_CODE_PY = (key, slateId) =>
2021-03-30 04:35:06 +03:00
`import requests
headers = {
2021-03-30 04:19:36 +03:00
"content-type": "application/json",
2021-04-21 03:14:43 +03:00
"Authorization": "Basic ${key}", // API key
2021-03-30 04:19:36 +03:00
}
2021-03-30 04:35:06 +03:00
2021-04-21 03:14:43 +03:00
json = { "id": "${slateId}" } # slate ID
2021-03-30 04:35:06 +03:00
2021-04-23 07:18:02 +03:00
get_collection = requests.post(
2021-03-30 04:19:36 +03:00
"https://slate.host/api/v1/get-slate", headers=headers, json=json
)
2021-04-23 07:18:02 +03:00
get_collection_response = get_collection.json()
2021-03-30 04:19:36 +03:00
2021-03-30 04:35:06 +03:00
2021-04-23 07:18:02 +03:00
collection = get_collection_response["slate"]
collection["data"]["name"] = "New title"
2021-04-21 03:14:43 +03:00
2021-04-23 07:18:02 +03:00
postJson = { "data": collection }
2021-03-30 04:19:36 +03:00
url = "https://slate.host/api/v1/update-slate"
2021-03-24 07:10:26 +03:00
2021-04-21 03:14:43 +03:00
r = requests.post(url, headers=headers, json=postJson)`;
2021-03-30 04:19:36 +03:00
export default class APIDocsUpdateSlate extends React.Component {
render() {
let language = this.props.language;
let key = this.props.APIKey;
let slateId = this.props.slateId;
let code = {
javascript: EXAMPLE_CODE_JS(key, slateId),
python: EXAMPLE_CODE_PY(key, slateId),
};
2021-03-24 07:10:26 +03:00
return (
<React.Fragment>
<System.DescriptionGroup
2021-03-30 04:19:36 +03:00
style={{ maxWidth: 640, marginTop: 64 }}
2021-04-23 07:18:02 +03:00
label="Update collection"
description="This API endpoint allows you to modify a collection by saving the response from get-slate, modifying it, and sending it back"
2021-03-24 07:10:26 +03:00
/>
<CodeBlock
2021-03-30 04:19:36 +03:00
children={code}
style={{ maxWidth: "820px" }}
2021-03-24 07:10:26 +03:00
language={language}
2021-04-23 07:18:02 +03:00
title="Update collection"
2021-03-30 04:19:36 +03:00
multiLang="true"
onLanguageChange={this.props.onLanguageChange}
2021-03-24 07:10:26 +03:00
/>
</React.Fragment>
);
}
}