2021-03-22 21:17:42 +03:00
import * as React from "react" ;
import * as System from "~/components/system" ;
2021-04-20 04:07:19 +03:00
import CodeBlock from "~/components/system/CodeBlock" ;
2021-03-22 21:17:42 +03:00
2021-03-24 07:10:26 +03:00
const EXAMPLE _CODE _JS = ( key ) => ` const response = await fetch('https://slate.host/api/v1/get', {
2021-03-22 21:17:42 +03:00
method : 'POST' ,
headers : {
'Content-Type' : 'application/json' ,
Authorization : 'Basic ${key}' ,
} ,
body : JSON . stringify ( { data : {
2021-04-23 07:18:02 +03:00
private : false // set private = true to include private collections
2021-03-22 21:17:42 +03:00
} } )
} ) ;
2021-04-21 03:14:43 +03:00
if ( ! response ) {
console . log ( "No response" ) ;
}
2021-03-22 21:17:42 +03:00
const json = await response . json ( ) ;
2021-04-21 03:14:43 +03:00
if ( json . error ) {
console . log ( json . error ) ;
} else {
2021-04-23 07:18:02 +03:00
const collections = json . slates ;
2021-04-21 03:14:43 +03:00
const user = json . user ;
} ` ;
2021-03-22 21:17:42 +03:00
2021-03-24 07:10:26 +03:00
const EXAMPLE _CODE _PY = ( key ) => ` import requests
2021-03-30 04:19:36 +03:00
import json as JSON
url = "https://slate.host/api/v1/get"
2021-03-24 07:10:26 +03:00
headers = {
2021-03-30 04:19:36 +03:00
"content-type" : "application/json" ,
2021-04-05 23:21:23 +03:00
"Authorization" : "Basic ${key}" ,
2021-03-30 04:19:36 +03:00
}
2021-03-24 07:10:26 +03:00
2021-04-21 03:14:43 +03:00
json = {
"data" : {
2021-04-23 07:18:02 +03:00
"private" : "false" # set private = true to include private collections
2021-04-21 03:14:43 +03:00
}
}
2021-03-24 07:10:26 +03:00
2021-03-30 04:35:06 +03:00
r = requests . post ( url , headers = headers , json = json )
2021-03-24 07:10:26 +03:00
2021-03-30 04:35:06 +03:00
print ( JSON . dumps ( r . json ( ) , indent = 2 ) ) ` ;
2021-03-24 07:10:26 +03:00
2021-04-21 03:14:43 +03:00
const EXAMPLE _RESPONSE = `
{
"decorator" : "V1_GET" ,
"slates" : [
{
"id" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" ,
"slatename" : "public-example" ,
"data" : {
2021-04-23 07:18:02 +03:00
"body" : "just a public collection, nothing special" ,
2021-04-21 03:14:43 +03:00
"name" : "Public Example" ,
"public" : true ,
"layouts" : {
"ver" : "2.0" ,
"layout" : [
{
"h" : 200 ,
"w" : 200 ,
"x" : 0 ,
"y" : 0 ,
"z" : 0 ,
"id" : "fce946be-7212-4f62-a74c-adfafd8d0d15"
}
] ,
"fileNames" : false ,
"defaultLayout" : true
} ,
"objects" : [
{
"id" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" ,
"cid" : "bafkreibrpxcv37juaq67it2gu7xyjo5fzq7v3r55ykcgzylvsfljcv3s3a" ,
"url" : "https://slate.textile.io/ipfs/cid-goes-here" ,
"name" : "door.jpg" ,
"size" : 33676 ,
"type" : "image/jpeg" ,
"title" : "Door" ,
"ownerId" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" ,
"blurhash" : "U6BzILt700IADjWBx]oz00f6?bs:00Rj_Nt7"
}
] ,
"ownerId" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" ,
"url" : "https://slate.host/devexamples/public-example"
}
}
] ,
"user" : {
"username" : "devexamples" ,
"data" : {
"photo" : "https://slate.textile.io/ipfs/cid-goes-here" ,
"body" : "A user of slate" ,
"name" : "Bob Smith"
}
}
} ` ;
2021-03-30 04:19:36 +03:00
export default class APIDocsGet extends React . Component {
render ( ) {
let APIKey = this . props . APIKey ;
let language = this . props . language ;
let code = {
javascript : EXAMPLE _CODE _JS ( APIKey ) ,
python : EXAMPLE _CODE _PY ( APIKey ) ,
} ;
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-20 04:07:19 +03:00
label = "Get your data"
2021-04-23 07:18:02 +03:00
description = "This API request returns your user data and collections. If the request body is omitted, the request will return only your public collections by default."
2021-03-24 07:10:26 +03:00
/ >
< CodeBlock
2021-03-30 04:19:36 +03:00
children = { code }
2021-03-24 07:10:26 +03:00
language = { language }
2021-03-30 04:19:36 +03:00
style = { { maxWidth : "820px" } }
2021-04-20 04:07:19 +03:00
title = "Get your data"
2021-03-30 04:19:36 +03:00
multiLang = "true"
onLanguageChange = { this . props . onLanguageChange }
2021-03-24 07:10:26 +03:00
/ >
2021-04-21 03:14:43 +03:00
< br / >
< CodeBlock
children = { EXAMPLE _RESPONSE }
style = { { maxWidth : "820px" } }
language = "json"
title = "Get your data response"
/ >
2021-03-24 07:10:26 +03:00
< / R e a c t . F r a g m e n t >
) ;
2021-03-22 21:17:42 +03:00
}
}