GithubHelp home page GithubHelp logo

scratchlib's Introduction

A powerful library to interact with the Scratch API ๐Ÿš€

npm shit npm

Table of contents

About

ScratchLib is a powerful Node.JS module to work with the Scratch API. It provides many methods and properties you never heard of, and does requests for you.

Installation

NPM

Open a terminal, and enter the following command: npm install scratchlib

How to use

Start by requiring the module.

const Scratchlib = require("scratchlib");

๐ŸŽ‰ Congrats - you can now access to the many properties this module offers!

Documentation

In order to use a method, you must choose between creating an async function or by adding a callback with .then().

async function():

async function test() {
    try {
	let info = await ScratchLib.getStatus();
	console.log(info);
    } catch (err) {
        console.error(err);
    }
}

test();

.then() callback:

ScratchLib.getStatus().then(info => {
	console.log(info);
}).catch(err => {
	console.error(err);
});

Both equals to:

{
  version: '1d96065a1ea1d017949e2bd8e179762744d231f0',
  uptime: 1013664,
  load: [ 0.1611328125, 0.134765625, 0.09619140625 ],
  sql: { ssl: true, min: 0, max: 40 },
  cache: { connected: true, ready: true }
}

โš ๏ธ Don't forget to catch the promise.

ScratchLib.getUserFollowers().then(info => {
	console.log(info);
}).catch(err => {
	console.error(err);
});
Output: Parameter of type string is missing!

Methods

โ€ข getFeatured() - Returns information regarding the projects currently visible on the front page of the website.
โ€ข getNews() - Returns information regarding the "Scratch News" section of the homepage.
โ€ข getProfile(username: string) - Returns information about the specified user.
โ€ข getProject(id: string) - Returns information relevant to the given project.
โ€ข getProjectsCount() - Returns the total number of shared projects on the Scratch website.
โ€ข getRoot() - The root of the api interface provides basic information regarding the API and the Scratch website.
โ€ข getStatus() - Used to return the status of the Scratch website. (really? :P)
โ€ข getUserFavorites(username: string) - Returns an array of details regarding the projects that a given user has favourited on the website.
โ€ข getUserFollowers(username: string) - Returns a list of a user's most recent followers.
โ€ข getUserFollowing(username: string) - Returns a list of the users that the specified user has most recently followed.
โ€ข getUserMessages(username: string) - This returns the number of unread messages a user currently has.
โ€ข getUserProjects(username: string) - Returns an array with information regarding the projects that a given user has shared on the Scratch website.

โš ๏ธ The following methods are returning JSON data.

TypeScript

๐Ÿ’ก This module can be used with TypeScript! It even provides quality types that can be auto-completed from Visual Studio Code, or any editor that supports IntelliSense/autocompletion.

Web

๐ŸŒ This library can also be used on the Web! You'll need help from browserify though.

CORS

If you use this module in the browser, you'll probably encounter a problem: CORS, which means 'Cross-origin resource sharing'.
Thanks to @locness3 (#3), this library now supports proxies.
You just have to specify a parameter, which must be equal to your proxy URL as follows: http://host:port.

ScratchLib.getFeatured("http://localhost:8080").then(info => {
	console.log(info);
}).catch(err => {
	console.error(err);
});

Contributing

You can contribute to this project by doing a PR โค๏ธ

Help

Do you need help? Create an issue!

scratchlib's People

Contributors

dependabot[bot] avatar depfu[bot] avatar fowled avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

scratchlib's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.