This repository was archived by the owner on Sep 6, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +74
-0
lines changed
Expand file tree Collapse file tree 1 file changed +74
-0
lines changed Original file line number Diff line number Diff line change 1+ let headers = require ( '../utils/headers.js' ) ;
2+ let variables = require ( '../utils/variables.js' ) ;
3+
4+ async function _getReplId ( username , slug ) {
5+ let info = await variables
6+ . fetch ( `https://staging.repl.it/data/repls/@${ username } /${ slug } ` , {
7+ method : 'GET' ,
8+ headers
9+ } )
10+ . then ( res => res . json ( ) ) ;
11+
12+ return info . id ;
13+ }
14+
15+ class Repl {
16+ constructor ( username , slug ) {
17+ this . username = username ;
18+ this . slug = slug ;
19+ }
20+
21+ async replGraphQLData ( ) {
22+ let username = this . username ;
23+ let slug = this . slug ;
24+
25+ let id = await _getReplId ( username , slug ) ;
26+ let info = await variables
27+ . fetch ( 'https://staging.repl.it/graphql' , {
28+ method : 'POST' ,
29+ headers,
30+ body : JSON . stringify ( {
31+ query : `
32+ query Repl($id: String!) {
33+ repl(id: $id) {
34+ ... on Repl {
35+ ${ variables . replAttributes }
36+ }
37+ }
38+ }` ,
39+ variables : {
40+ id
41+ }
42+ } )
43+ } )
44+ . then ( res => res . json ( ) ) ;
45+
46+ if ( ! info . data . repl ) {
47+ throw new Error ( `${ slug } is not a repl. Please query repls on Repl.it.` ) ;
48+ } else {
49+ return info . data . repl ;
50+ }
51+ }
52+
53+ async replRESTData ( ) {
54+ let username = this . username ;
55+ let slug = this . slug ;
56+
57+ let info = await variables
58+ . fetch ( `https://staging.repl.it/data/repls/@${ username } /${ slug } ` , {
59+ method : 'GET' ,
60+ headers
61+ } )
62+ . then ( res => res . json ( ) ) ;
63+
64+ if ( ! info ) {
65+ throw new Error ( `${ slug } is not a repl. Please query repls on Repl.it.` ) ;
66+ } else {
67+ return info ;
68+ }
69+ }
70+ }
71+
72+ module . exports = {
73+ Repl : Repl
74+ } ;
You can’t perform that action at this time.
0 commit comments