1.5.5 • Published 3 years ago

tdb-api v1.5.5

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

TDB-API

About

A wrapper for OpenTDB API made in Javascript

Created By: ItsHisoka17, SkellyM386

Simply Usage

const TDB_API = require('tdb-api');

const trivia = new TDB_API();

trivia.getQuestions({amount: 10, category: 'Sports', difficulty: 'medium'})
.then(res => {
    console.log(res)
});

Handling Sessions

const TDB_API = require('tdb-api');

const trivia = new TDB_API();


async function start(){
    let token = await trivia.create_session_token(); //Creates a token
    trivia.getQuestions({amount: 10, category: 'Sports', difficulty: 'medium', token: token})
    .then(res => {
        console.log(res) //Returns: {category: string, type: string, difficulty: string, question: string, correct_answer: string, incorrect_answers: Array<string>}
    })
    .catch(async () => {
        let newToken = await trivia.refresh_token(token); //Requests a new token and invalidates the previous one
        trivia.getQuestions({amount: 10, category: 'Sports', difficulty: 'medium', token: newToken})
        .then(res => {
            console.log(res)
        })
    })

}
start()

Categories:

  • General Knowledge

  • Books

  • Films

  • Music

  • Musical & Theatre

  • TV

  • Video Games

  • Board Games

  • Science & Nature

  • Computers

  • Mathematics

  • Mythology

  • Sports

  • Geography

  • History

  • Politics

  • Art

  • Celebrities

  • Animals

  • Vehicles

  • Comics

  • Gadgets

  • Anime & Manga

  • Cartoons & Animations

Contact

Discord | Github

1.5.5

3 years ago

1.5.2

3 years ago

1.5.1

3 years ago

1.4.0

3 years ago