-
Notifications
You must be signed in to change notification settings - Fork 1
/
189036dd.0bd2ba24.js
1 lines (1 loc) · 7.6 KB
/
189036dd.0bd2ba24.js
1
(window.webpackJsonp=window.webpackJsonp||[]).push([[6],{110:function(e,t,a){"use strict";a.r(t),a.d(t,"frontMatter",(function(){return s})),a.d(t,"metadata",(function(){return c})),a.d(t,"rightToc",(function(){return i})),a.d(t,"default",(function(){return m}));var n=a(1),r=a(6),l=(a(0),a(136)),o=a(141),s={id:"login",title:"Acquire authorization token"},c={id:"login",title:"Acquire authorization token",description:"import Request from '../src/core/components/Request';\r",source:"@site/docs\\login.mdx",permalink:"/api-4p/docs/login",editUrl:"https://github.com/Danon/api-4p/edit/master/docs/login.mdx",sidebar:"someSidebar",previous:{title:"Style Guide",permalink:"/api-4p/docs/style"},next:{title:"Microblogs",permalink:"/api-4p/docs/microblogs"}},i=[],u={rightToc:i};function m(e){var t=e.components,a=Object(r.a)(e,["components"]);return Object(l.b)("wrapper",Object(n.a)({},u,a,{components:t,mdxType:"MDXLayout"}),Object(l.b)("p",null,"Perform a ",Object(l.b)("inlineCode",{parentName:"p"},"/login")," request to retrieve an authorization token."),Object(l.b)(o.a,{post:!0,url:"/login",parameters:{name:"user",password:"root"},mdxType:"Request"}))}m.isMDXComponent=!0},141:function(e,t,a){"use strict";a.d(t,"a",(function(){return J}));var n=a(0),r=a.n(n),l=a(147),o=a(148),s=a(241),c=a(253);function i(e){const[t,a]=r.a.useState("prod");return r.a.useEffect(()=>a(e.env),[e.env]),r.a.createElement(c.a,{value:t,onChange:function(t,n){n&&(a(n),e.onChange(n))},size:"small",exclusive:!0},r.a.createElement(s.a,{value:"local"},"Local"),r.a.createElement(s.a,{value:"dev"},"Dev"),r.a.createElement(s.a,{value:"prod"},"Prod"))}var u=a(152),m=a.n(u),p=a(93),d=a.n(p),h=({color:e,children:t})=>r.a.createElement("div",{className:d.a.badge,style:{backgroundColor:e}},r.a.createElement("div",{className:d.a.wrapper},t)),g=(a(12),a(249)),E=a(242),f=a(252),v=a(248),b=a(246),y=a(247),j=a(244);function C({children:e}){const[t,a]=r.a.useState(!1),n=r.a.useRef(null);return r.a.useEffect(()=>{if(t){const{current:e}=n;null!==e&&e.focus()}},[t]),r.a.createElement("div",null,r.a.createElement(E.a,{onClick:()=>a(!0)},"Edit schema"),r.a.createElement(f.a,{open:t,onClose:()=>a(!1),scroll:"body","aria-labelledby":"scroll-dialog-title","aria-describedby":"scroll-dialog-description"},r.a.createElement(j.a,{id:"scroll-dialog-title"},"Resource schema"),r.a.createElement(b.a,{dividers:!1},r.a.createElement(y.a,{id:"scroll-dialog-description",ref:n,tabIndex:-1}),e),r.a.createElement(v.a,null,r.a.createElement(E.a,{onClick:()=>a(!1),color:"primary",disabled:!0},"Make a request"),r.a.createElement(E.a,{onClick:()=>a(!1),color:"primary"},"Cancel"))))}function T(e,t){t=Object.assign({},t);const a=[];return[e=e.replace(/:([a-z]+)/g,(e,n)=>{if(n in t){let e=t[n];return a.push(n),delete t[n],e}throw new Error(`Missing replacement for '${n}'`)}),t,a]}function O(e){return function(e,t){const a=[];for(let n of t.matchAll(e))a.push(n[1]);return a}(/:([a-z]+)/g,e)}var x=a(140),k=({children:e,language:t})=>r.a.createElement(x.a,{className:`language-${t}`},e);function q(e){for(const t in e)return!0;return!1}var N=a(94),w=a.n(N),S=function({method:e,url:t,parameters:a,schema:n}){return q(a)||q(n)?function({parameters:e,suffix:t,schema:a}){return r.a.createElement("table",{className:w.a.parameters},r.a.createElement("thead",null,r.a.createElement("tr",null,r.a.createElement("th",null,"parameter"),r.a.createElement("th",null,"example value"))),r.a.createElement("tbody",null,Object.entries(e).map(([e,a])=>r.a.createElement("tr",{key:e},r.a.createElement("td",null,G(t(e)),G(function(e){const t=typeof e;if("number"===t)return"int";return t}(a)),e),r.a.createElement("td",null,r.a.createElement(g.a,{label:e,value:a})))),q(a)?r.a.createElement("tr",null,r.a.createElement("td",null,r.a.createElement("code",null,"schema","{}")," ","{","...}"),r.a.createElement("td",null,r.a.createElement(C,null,r.a.createElement("div",{className:w.a.minWidthCode},r.a.createElement(k,{language:"json"},JSON.stringify(a,null,2)))))):null))}({parameters:a,suffix:function(a){return O(t).includes(a)?"path/":"GET"===e?"query?":null},schema:n}):r.a.createElement("p",{className:w.a.noParams},"This resource doesn't take any parameters :)")};function G(e){return null===e?null:r.a.createElement("code",{style:{marginRight:"3px"}},e)}var R=a(95),P=a.n(R),$=class extends r.a.Component{suffix(e){return O(this.props.url).includes(e)?"path/":"GET"===this.props.method?"query?":null}get badgeColor(){return{POST:"#49cc90",GET:"#61affe",PUT:"#fca130"}[this.props.method]}get placeholders(){return O(this.props.url)}render(){const{url:e,method:t,parameters:a,schema:n,pagination:l,requiresLogin:o}=this.props;return r.a.createElement("div",{className:P.a.params},r.a.createElement("header",null,r.a.createElement(h,{color:this.badgeColor},t),r.a.createElement("span",{className:P.a.endpoint},e)),r.a.createElement(S,{method:t,url:e,parameters:a,schema:n}),r.a.createElement("div",{style:{display:"flex"}},o?r.a.createElement(h,{color:"#ffcccc"},r.a.createElement(m.a,{fontSize:"small"})," Requires Login"):null,l?r.a.createElement(h,{color:"#49cc90"},"+ Pagination"):null))}};function M(e){const t=Object.entries(e).map(([e,t])=>encodeURIComponent(e)+"="+encodeURIComponent(t));return t.length?"?"+t.join("&"):""}function L({method:e,url:t,parameters:a}){const[n,l]=T(t,a);return"GET"===e?function(e,t){return r.a.createElement(k,{language:"js"},`fetch("${e+M(t)}", {\n "method": "GET",\n "headers": {\n "Accept": "application/json",\n "Content-type": "application/json"\n }\n})`)}(n,l):function(e,t,a){return r.a.createElement(k,{language:"js"},`fetch("${t}", {\n "method": "${e}",\n "headers": {\n "Accept": "application/json",\n "Content-type": "application/json"\n },\n "body": JSON.stringify(${n=JSON.stringify(a,null,2),l=2,n.split("\n").map(e=>" ".repeat(l)+e).join("\n").substr(l)})\n})`);var n,l}(e,n,l)}var z=class extends r.a.Component{render(){let{method:e,url:t,parameters:a}=this.props;const[n,r]=T(t,a);return"GET"===e?this.codeMethodGet(n,r):this.code(e,n,r)}code(e,t,a){return r.a.createElement(k,{language:"bash"},`curl -X ${e} ${t} \\\n -H "Accept: application/json" \\\n -H "Content-Type: application/json" \\\n -d '${JSON.stringify(a)}'`)}codeMethodGet(e,t){return r.a.createElement(k,{language:"bash"},`curl -X GET ${e+M(t)} \\\n -H "Accept: application/json" \\\n -H "Content-Type: application/json"`)}},A=a(96),U=a.n(A);class J extends r.a.Component{constructor(e){super(e),this.state={env:"prod"}}get method(){if(this.props.get)return"GET";if(this.props.post)return"POST";if(this.props.put)return"PUT";throw"Missing HTTP method"}render(){return this.doRender({url:this.baseUrl+this.props.url,parameters:this.props.parameters||{},schema:this.props.schema||{},pagination:this.props.pagination,requiresLogin:this.props.requiresLogin})}get baseUrl(){return{prod:"https://api.4programmers.net/v1",dev:"https://api.4programmers.dev/v1",local:"http://localhost:8080/v1"}[this.state.env]}doRender({url:e,parameters:t,schema:a,pagination:n,requiresLogin:s}){return r.a.createElement("div",null,r.a.createElement(l.a,{defaultValue:"params",values:[{label:"Params",value:"params"},{label:"fetch()",value:"fetch"},{label:"curl",value:"curl"}]},r.a.createElement(o.a,{value:"params"},r.a.createElement($,{method:this.method,url:e,parameters:t,schema:a,pagination:n,requiresLogin:s})),r.a.createElement(o.a,{value:"fetch"},r.a.createElement(L,{method:this.method,url:e,parameters:Object.assign({},t,a)})),r.a.createElement(o.a,{value:"curl"},r.a.createElement(z,{method:this.method,url:e,parameters:Object.assign({},t,a)}))),r.a.createElement("div",{className:U.a.wrapper},r.a.createElement(i,{env:this.state.env,onChange:e=>this.setState({env:e})})))}}}}]);