replya v1.2.1
replya
replya allows you to easily access https://repl.it's graphql api. this enables you to query information about users, repls, and talk. replya makes this process completely modular, making it super simple to get the data you need.
you can see an example of how replya is used here
docs
these are the docs for the latest release of replya. to install replya, simply type npm i replya
into the terminal/command-line to get started.
each title contains the function exactly how it is viewed in visual studio code. so if you understand that representation, you will understand the function from its title.
setup
once replya is installed, we can begin requiring and using the module. let's require replya and login to start using the api:
const replya = require("replya"); // this will get our client
// login and get our client
replya("<username>", "<password>").then(client => {
// use the client
});
insert your username and password where <username>
and <password>
are seen. always remember to keep your password safe! here is a tutorial on how you can do so using environment variables
this is all you need to start using the replya api to access https://repl.it's graphql api. from this initial setup of the client, you also get instant access to your data.
querify(type: string, ?find: [], ?send: {}): string
queryify creates query strings using the arguments provided. these query strings are formatted for use in graphql, and can be used to create any graphql formatted query string.
use:
let test = client.querify("query", [client.querify("userByUsername", ["id", "firstName", "karma"], {username: `"m3l0f1"`})]);
console.log(test); // > query{userByUsername(username: "m3l0f1"){id, firstName, karma}}
query(query: string): promise
query queries https://repl.it/graphql for the data provided in the query string. this will return data which relates to the query in a promise. the json data can be accessed in a then method.
use:
client.query(client.querify("query", [client.querify("userByUsername", ["id", "firstName", "karma"], {username: `"m3l0f1"`})]))
.then(json => console.log(json)); // > { userByUsername: { id: 2755043, firstName: null, karma: 23 } }
user(id: string | number, ?find: []): promise
this will get data for the user based on the id given. this id can be either a string of the user's username, or a number of the user's id.
by default, you will get the user's:
id
username
fullName
bio
karma
use:
client.user("amasad").then(console.log); // { user: { id: 1, username: 'amasad', fullName: 'Amjad Masad', bio: 'ceo of repl.it', karma: 1952 } } }
client.user(1).then(console.log); // { user: { id: 1, username: 'amasad', fullName: 'Amjad Masad', bio: 'ceo of repl.it', karma: 1952 } } }
repl(id: string | number, ?find: []): promise (Broken)
this will get data for the repl based on the id given. this id can be either a string of the repl's username, or a number of the repl's url.
by default, you will get the repl's:
id
language
isPrivate
isStarred
title
description
timeCreated
files
use:
client.repl().then(console.log);
enterprise(id: number, ?find: []): promise
this will get data for an enterprise based on the id given. this id can only be a number related to the enterprise's id.
by default, you will get the enterprise's:
- `id
startDate
endDate
teacherSeats
studentSeats
use:
client.enterprise(1).then(console.log()); // > { enterprise: { id: 1, startDate: '2018-01-13T23:17:47.583Z', endDate: '2019-01-13T23:17:47.583Z', teacherSeats: 50, studentSeats: 4000 } }
organization(id: number, ?find: []): promise
this will get data for an organisation based on the id given. this id can only be a number related to the organisation's id.
by default, you will get the organisation's:
id
name
country
city
timeCreated
timeDeleted
use:
client.organization(1).then(console.log); // { organization: { id: 1, name: 'Hero City at Draper University', country: 'US', city: 'San Mateo', timeCreated: '2016-08-02T07:14:20.000Z', timeDeleted: null } }
board(id: number, ?find: []): promise
this will get data for a board based on the id given. this id can only be a number related to the board's id. each board's id can be referenced by it's name in the client, these are the following ids:
LEARN
- 17CHALLENGE
- 16ANNOUNCEMENTS
- 14SHARE
- 3ASK
- 6
by default, you will get the board's:
id
name
description
color
isLocked
timeCreated
url
use:
client.board(client.SHARE).then(console.log); // > { board: { id: 3, name: 'Share', description: 'Share your repls and programming experiences', color: '#68afd4', isLocked: false, timeCreated: '2018-04-19T14:44:48.000Z', url: '/talk/share' } }
post(id: number, ?find: []): promise
this will get data for a post based on the id given. this id can only be a number related to the post's id.
by default, you will get the post's:
id
title
body
voteCount
commentCount
isLocked
timeCreated
url
use:
client.post(22109).then(console.log); // > { post: { id: 22109, title: 'Repl Talk Rules and Guidelines [README]', body: 'this is not the acctual post body because it is too long to show here', voteCount: 1, commentCount: 115, isLocked: false, timeCreated: '2019-11-15T03:47:13.512Z', url: '/talk/announcements/Repl-Talk-Rules-and-Guidelines-README/22109' } }
comment(id: number, ?find: []): promise
this will get data for a comment based on the id given. this id can only be a number related to the comment's id.
by default, you will get the comment's:
id
body
voteCount
timeCreated
url
isAnswer
use:
client.comment(64339).then(console.log); // > { comment: { id: 64339, body: '@Scoder12 :)', voteCount: 5, timeCreated: '2019-11-15T04:23:31.978Z', url: '/talk/announcements/Scoder12/22109/64339', isAnswer: false } }