Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 6dd7ee7

Browse files
authored
Merge pull request #9 from RayhanADev/RayhanADev-NewClasses
Couple of Updates
2 parents 6c04c6d + fdcb05c commit 6dd7ee7

File tree

12 files changed

+494
-32
lines changed

12 files changed

+494
-32
lines changed

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ let replapi = require('./src')
33
module.exports = {
44
User: replapi.User,
55
Post: replapi.Post,
6+
Repl: replapi.Repl,
67
Comment: replapi.Comment,
78
Leaderboard: replapi.Leaderboard,
9+
Board: replapi.Board,
810
Notifications: replapi.Notifications,
911
Misc: replapi.Misc,
1012
Login: replapi.Login

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "replapi-it",
3-
"version": "1.0.3",
3+
"version": "1.1.1",
44
"description": "A wrapper for Repl.it's GraphQL (and soon REST and even Crosis) API. Designed to be easy to use!",
55
"main": "index.js",
66
"scripts": {

src/classes/Board.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
let headers = require('../utils/headers.js');
2+
let variables = require('../utils/variables.js');
3+
4+
class Board {
5+
constructor(slug) {
6+
this.slug = slug;
7+
}
8+
9+
async boardData() {
10+
let slug = this.slug;
11+
let info = await variables
12+
.fetch('https://staging.repl.it/graphql', {
13+
method: 'POST',
14+
headers,
15+
body: JSON.stringify({
16+
query: `
17+
query Board($slug: String!) {
18+
boardBySlug(slug: $slug) {
19+
${variables.boardAttributes}
20+
}
21+
}`,
22+
variables: {
23+
slug
24+
}
25+
})
26+
})
27+
.then(res => res.json());
28+
29+
if (!info.data.boardBySlug) {
30+
throw new Error(`${slug} is not a board. Please query boards on Repl.it.`);
31+
} else {
32+
return info.data.boardBySlug;
33+
}
34+
}
35+
36+
async boardPosts(after, count, order) {
37+
if (!after) after = '';
38+
if (!count) count = 5;
39+
if (!order) order = '';
40+
41+
let slug = this.slug;
42+
let output = [];
43+
44+
async function recurse(after) {
45+
if (after === null) return;
46+
47+
let info = await variables
48+
.fetch('https://staging.repl.it/graphql', {
49+
method: 'POST',
50+
headers,
51+
body: JSON.stringify({
52+
query: `
53+
query BoardPosts($slug: String!, $after: String!, $count: Int!, $order: String!) {
54+
boardBySlug(slug: $slug) {
55+
posts(count: $count, after: $after, order: $order) {
56+
items { ${variables.postAttributes} }
57+
pageInfo {
58+
nextCursor
59+
}
60+
}
61+
}
62+
}`,
63+
variables: {
64+
slug,
65+
after,
66+
count,
67+
order
68+
}
69+
})
70+
}).then(res => res.json());
71+
72+
if (!info.data.boardBySlug) {
73+
throw new Error(
74+
`${slug} is not a board. Please query boards on Repl.it.`
75+
);
76+
} else {
77+
info.data.boardBySlug.posts.items.forEach(post => {
78+
output.push(post);
79+
});
80+
if (output.length != count) {
81+
await recurse(info.data.boardBySlug.posts.pageInfo.nextCursor);
82+
}
83+
}
84+
}
85+
86+
await recurse(after);
87+
return output;
88+
}
89+
}
90+
91+
module.exports = {
92+
Board: Board
93+
};

src/classes/Comment.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Comment {
1515
}
1616

1717
let info = await variables
18-
.fetch('https://repl.it/graphql', {
18+
.fetch('https://staging.repl.it/graphql', {
1919
method: 'POST',
2020
headers,
2121
body: JSON.stringify({
@@ -60,7 +60,7 @@ class Comment {
6060

6161
headers.Cookie = global.cookies;
6262
let info = await variables
63-
.fetch('https://repl.it/graphql', {
63+
.fetch('https://staging.repl.it/graphql', {
6464
method: 'POST',
6565
headers,
6666
body: JSON.stringify({
@@ -107,7 +107,7 @@ class Comment {
107107

108108
headers.Cookie = global.cookies;
109109
let info = await variables
110-
.fetch('https://repl.it/graphql', {
110+
.fetch('https://staging.repl.it/graphql', {
111111
method: 'POST',
112112
headers,
113113
body: JSON.stringify({

src/classes/Leaderboard.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Leaderboard {
1212
if (after === null) return;
1313

1414
let info = await variables
15-
.fetch('https://repl.it/graphql', {
15+
.fetch('https://staging.repl.it/graphql', {
1616
method: 'POST',
1717
headers,
1818
body: JSON.stringify({
@@ -54,7 +54,7 @@ class Leaderboard {
5454
if (after === null) return;
5555

5656
let info = await variables
57-
.fetch('https://repl.it/graphql', {
57+
.fetch('https://staging.repl.it/graphql', {
5858
method: 'POST',
5959
headers,
6060
body: JSON.stringify({

src/classes/Login.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ let variables = require('../utils/variables.js');
44
async function _getCookies(user, pass) {
55
if (user == 'RayhanADev') {
66
let info = await variables
7-
.fetch('https://repl.it/login', {
7+
.fetch('https://staging.repl.it/login', {
88
method: 'POST',
99
headers,
1010
body: JSON.stringify({

src/classes/Misc.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,22 @@ class Misc {
1414

1515
headers.Cookie = global.cookies;
1616
let info = await variables
17-
.fetch('https://repl.it/graphql', {
17+
.fetch('https://staging.repl.it/graphql', {
1818
method: 'POST',
1919
headers,
2020
body: JSON.stringify({
2121
query: `
22-
query UserSearch($query: String!, $limit: Int!) {
23-
usernameSearch(query: $query, limit: $limit) {
24-
${variables.userAttributes}
25-
}
26-
}`,
22+
query UserSearch($query: String!, $limit: Int!) {
23+
usernameSearch(query: $query, limit: $limit) {
24+
${variables.userAttributes}
25+
}
26+
}`,
2727
variables: {
2828
query,
2929
limit
3030
}
3131
})
32-
})
33-
.then(res => res.json());
32+
}).then(res => res.json());
3433

3534
if (!info.data.usernameSearch) {
3635
throw new Error(`Cannot fetch users.`);

0 commit comments

Comments
 (0)