Skip to content

Commit

Permalink
JSDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
webdev03 committed Oct 5, 2023
1 parent 25b579f commit 0b665d8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/ScratchSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ class ScratchSession {
}[];
}

/**
* Get messages
* @param limit The limit of messages to get
* @param offset The offset of messages
*/
async getMessages(limit: number = 40, offset: number = 0) {
const request = await fetch(`https://api.scratch.mit.edu/users/${this.username}/messages?limit=${limit}&offset=${offset}`, {
headers: {
Expand All @@ -215,7 +220,11 @@ class ScratchSession {
if(!request.ok) throw Error(`Request failed with status ${request.status}`);
return (await request.json()) as Message[];
}


/**
* Get the message count
* @returns The number of messages
*/
async getMessageCount() {
const request = await fetch(`https://api.scratch.mit.edu/users/${this.username}/messages/count`);
if(!request.ok) throw Error(`Request failed with status ${request.status}`);
Expand Down
4 changes: 4 additions & 0 deletions src/classes/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ class Project {
}
}

/**
* Set the thumbnail of the project
* @param buffer The buffer of the thumbnail image file
*/
async setThumbnail(buffer: Buffer) {
const request = await fetch(
`https://scratch.mit.edu/internalapi/project/thumbnail/${this.id}/set/`,
Expand Down
9 changes: 9 additions & 0 deletions src/classes/Studio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class Studio {
this.session = session;
}

/**
* Get the API data of the studio
*/
async getAPIData() {
const response = await fetch(
`https://api.scratch.mit.edu/studios/${this.id}/`,
Expand All @@ -63,6 +66,9 @@ class Studio {
return (await response.json()) as StudioAPIResponse;
}

/**
* Follow the studio
*/
async follow() {
const request = await fetch(
`https://scratch.mit.edu/site-api/users/bookmarkers/${this.id}/add/?usernames=${this.session.sessionJSON.user.username}`,
Expand All @@ -84,6 +90,9 @@ class Studio {
throw Error(`Request failed with status ${request.status}`);
}

/**
* Unfollow the studio
*/
async unfollow() {
const request = await fetch(
`https://scratch.mit.edu/site-api/users/bookmarkers/${this.id}/remove/?usernames=${this.session.sessionJSON.user.username}`,
Expand Down

0 comments on commit 0b665d8

Please sign in to comment.