2021-04-21 03:14:43 +03:00
import * as React from "react" ;
import * as System from "~/components/system" ;
2022-06-20 13:12:08 +03:00
import * as Constants from "~/common/constants" ;
2021-04-21 03:14:43 +03:00
import CodeBlock from "~/components/system/CodeBlock" ;
const EXAMPLE _CODE _JS = ( key ) => ` const response = await fetch('https://slate.host/api/v2/get', {
2021-05-26 23:05:13 +03:00
method : 'GET' ,
2021-04-21 03:14:43 +03:00
headers : {
'Content-Type' : 'application/json' ,
2021-07-31 01:00:06 +03:00
Authorization : '${key}' ,
2021-04-21 03:14:43 +03:00
}
} ) ;
if ( ! response ) {
console . log ( "No response" ) ;
2021-05-26 23:05:13 +03:00
return ;
}
2021-04-21 03:14:43 +03:00
const json = await response . json ( ) ;
if ( json . error ) {
2021-05-27 05:33:19 +03:00
console . log ( json ) ;
2021-04-21 03:14:43 +03:00
} else {
2021-04-23 08:18:46 +03:00
const collections = json . collections ;
2021-04-21 03:14:43 +03:00
const user = json . user ;
} ` ;
const EXAMPLE _CODE _PY = ( key ) => ` import requests
import json as JSON
url = "https://slate.host/api/v2/get"
headers = {
"content-type" : "application/json" ,
2021-07-31 01:00:06 +03:00
"Authorization" : "${key}" ,
2021-04-21 03:14:43 +03:00
}
2021-05-26 23:05:13 +03:00
r = requests . get ( url , headers = headers )
2021-04-21 03:14:43 +03:00
print ( JSON . dumps ( r . json ( ) , indent = 2 ) ) ` ;
const EXAMPLE _RESPONSE = `
{
2021-11-12 01:40:39 +03:00
decorator : "V2_GET" ,
slates : [
2021-04-21 03:14:43 +03:00
{
2021-11-12 01:40:39 +03:00
id : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" ,
slatename : "public-example" ,
isPublic : true ,
objects : [
2021-04-21 03:14:43 +03:00
{
2021-11-12 01:40:39 +03:00
id : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" ,
2022-06-20 13:12:08 +03:00
cid : "bafkreibrpxcv37juaq67it2gu7xyjo5fzq7v3r55ykcgzylvsfljcv3s3a" , // the file URL is "${Constants.gateways.ipfs}/bafkreibrpxcv37juaq67it2gu7xyjo5fzq7v3r55ykcgzylvsfljcv3s3a"
2021-11-12 01:40:39 +03:00
filename : "door.jpg" ,
ownerId : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" ,
data : {
name : "Door" ,
size : 33676 ,
type : "image/jpeg" ,
blurhash : "U6BzILt700IADjWBx]oz00f6?bs:00Rj_Nt7" ,
} ,
2021-04-21 03:14:43 +03:00
} ,
2021-11-12 01:40:39 +03:00
] ,
ownerId : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" ,
data : {
2021-04-23 08:18:46 +03:00
body : "just a public collection, nothing special" ,
2021-04-21 03:14:43 +03:00
name : "Public Example" ,
url : "https://slate.host/devexamples/public-example" ,
2021-11-12 01:40:39 +03:00
} ,
2021-04-21 03:14:43 +03:00
} ,
2021-11-12 01:40:39 +03:00
] ,
user : {
2021-04-21 03:14:43 +03:00
username : "devexamples" ,
library : [
2021-11-12 01:40:39 +03:00
{
2021-04-21 03:14:43 +03:00
id : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" ,
2022-06-20 13:12:08 +03:00
cid : "bafkreibrpxcv37juaq67it2gu7xyjo5fzq7v3r55ykcgzylvsfljcv3s3a" , // the file URL is "${Constants.gateways.ipfs}/bafkreibrpxcv37juaq67it2gu7xyjo5fzq7v3r55ykcgzylvsfljcv3s3a"
2021-04-21 03:14:43 +03:00
filename : "door.jpg" ,
ownerId : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" ,
data : {
2021-11-12 01:40:39 +03:00
name : "Door" ,
size : 33676 ,
type : "image/jpeg" ,
blurhash : "U6BzILt700IADjWBx]oz00f6?bs:00Rj_Nt7" ,
2021-04-21 03:14:43 +03:00
} ,
2021-11-12 01:40:39 +03:00
} ,
2021-04-21 03:14:43 +03:00
] ,
data : {
2022-06-20 13:12:08 +03:00
photo : "${Constants.gateways.ipfs}/cid-goes-here" ,
2021-11-12 01:40:39 +03:00
body : "A user of slate" ,
name : "Bob Smith" ,
2021-04-21 03:14:43 +03:00
} ,
2021-11-12 01:40:39 +03:00
} ,
2021-04-21 03:14:43 +03:00
} ; ` ;
export default class APIDocsGet extends React . Component {
render ( ) {
2022-06-20 13:12:08 +03:00
let { APIKey } = this . props ;
let { language } = this . props ;
2021-04-21 03:14:43 +03:00
let code = {
javascript : EXAMPLE _CODE _JS ( APIKey ) ,
python : EXAMPLE _CODE _PY ( APIKey ) ,
} ;
return (
2021-08-02 05:56:55 +03:00
< div css = { this . props . cssValue } style = { this . props . style } >
2021-04-21 03:14:43 +03:00
< System . DescriptionGroup
2021-08-02 05:56:55 +03:00
style = { { maxWidth : 640 } }
2021-04-21 03:14:43 +03:00
label = "Get your data"
2021-04-23 08:18:46 +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-04-21 03:14:43 +03:00
/ >
< CodeBlock
language = { language }
style = { { maxWidth : "820px" } }
title = "Get your data"
multiLang = "true"
onLanguageChange = { this . props . onLanguageChange }
2022-06-20 13:12:08 +03:00
>
{ code }
< / C o d e B l o c k >
2021-04-21 03:14:43 +03:00
< br / >
< CodeBlock
style = { { maxWidth : "820px" } }
language = "javascript"
title = "Get your data response"
2022-06-20 13:12:08 +03:00
>
{ EXAMPLE _RESPONSE }
< / C o d e B l o c k >
2021-08-02 05:56:55 +03:00
< / d i v >
2021-04-21 03:14:43 +03:00
) ;
}
}