0.1.0 • Published 2 years ago

@errorgamer2000/scratch-cloud v0.1.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

scratch-cloud

A TypeScript library that allows communication with the scratch cloud servers.

A short example:

import { ScratchCloud } from "@errorgamer2000/scratch-cloud";

async function main() {
  const cloud = new ScratchCloud();

  await cloud.login("<username>", "<password>");

  const session = cloud.createSession(
    "<project_id>",
    false /* do not use TurboWarp servers */
  );

  session.on("set", (name: string, value: string) => {
    console.log(`${name} was set to ${value}.`);
  });
}

This is a rewrite of the cloudsession api from my original scratch3-api module. This module provides only methods to communicate with the Scratch/TurboWarp cloud servers. To use methods that are not centered around the cloud servers, use scratch-connect(not yet published). For string to number conversions, see stringstonumbers.

Installation

Install with npm or other package manager:

npm install @errorgamer2000/scratch-cloud

Or by cloning this repository:

git clone https://github.com/ErrorGamer2000/scratch-cloud.git

Exports:

Classes

ScratchCloud

Kind: global class

new ScratchCloud()

scratchCloud.login(username, password)

Kind: instance method of ScratchCloud Throws:

  • TypeError If the username or password are incorrect.
  • Error If the scratch server gives an invalid response.
ParamDescription
usernameThe username of the account to log in with.
passwordThe password of the account to log in with.

scratchCloud.createSession(project, turbowarp)

Kind: instance method of ScratchCloud

ParamDefaultDescription
projectThe ID of the project to connect to.
turbowarpfalseUse the TurboWarp cloud servers rather than the Scratch cloud servers.

Session

Kind: global class

new Session(userData, projectId, turbowarp)

ParamDefaultDescription
userDataData used to validate the user's login and connect using the correct account.
projectIdThe ID of the project to connect to.
turbowarpfalseUse the TurboWarp cloud servers rather than the Scratch cloud servers.

session.set(name, value)

Kind: instance method of Session

ParamDescription
nameThe name of the cloud variable.
valueThe value to set it to. Can be a string or a number, but can only include numerical digits.

session.get(name)

Kind: instance method of Session

ParamDescription
nameThe name of the cloud variable

session.enableAutoPrefix()

Kind: instance method of Session See: Session.autoPrefix

session.disableAutoPrefix()

Kind: instance method of Session See: Session.autoPrefix

session.on(eventName, listener)

Kind: instance method of Session

ParamDescription
eventNameThe name of the event.
listenerThe callback function.

session.once(eventName, listener)

Kind: instance method of Session

ParamDescription
eventNamethe name of the event.
listenerthe callback listener.

© 2022 ErrorGamer2000