0.1.1 • Published 6 years ago

opentriviaapi v0.1.1

Weekly downloads
9
License
MIT
Repository
github
Last release
6 years ago

OpenTrivia API

Build Status Coverage Status

Special thanks to wKovacs64, he saved me hours of google time!

Install

    yarn add opentriviaapi

or

    npm install opentriviaapi --save

File structure:

    ./src
        index.js
        openTriviaAPI.js
        responses.js
    ./test
        test.js

index.js

Application entry point.

openTrivia.js

Core Functions:
FunctionDescription
_axios()Create axios instance. (Not for General use)
_fetchFromAPI()Makes our calls to API. (Not for General use)
getQuestions()Get questions from API.
listCategories()Get a list of available categories (No options)
Helper functions:
FunctionDescription
getToken()Get a token from API.
resetToken()Reset token.

responses.js

    Exposes the API response values to our app.

getQuestions API query specifics:

    options = {
        amount: {Number}        // Amount of questions, null=1,
        category: {Number}      // use category.js, null=any,
        difficulty: {String}    // (easy, medium, hard), null=any,
        type: {String}          // (multiple, boolean), null=any,
        encode: {string}        // (url3986, base64), null=default encoding
    }

getQuestions Query options:

Amount {Number}:

ValueDescription
1 - 50any Integer between 1 and 50.
Example:   options = {
                amount: 35
            }

Category {Number}:

ValueName
"null"Any category
9General Knowledge
10Entertainment: Books
11Entertainment: Film
12Entertainment: Music
13Entertainment: Musicals & Theatres
14Entertainment: Television
15Entertainment: Video Games
16Entertainment: Board Games
17Science & Nature
18Science: Computers
19Science: Mathematics
20Mythology
21Sports
22Geography
23History
24Politics
25Art
26Celebrities
27Animals
Example:   options = {
                category: 18
            }

Difficulty {String}:

ValuesDescription
"null"Any difficulty
easyOnly easy questions
mediumOnly medium questions
difficultOnly difficult questions
Example:   options = {
                type: 'medium'
            }

Type {String}:

ValueDescription
"null"Any type of questions
multipleMultiple choice questions only
booleanTrue / False questions only
Example:   options = {
                type: 'multiple'
            }

Encode {String}:

ValueDescription
"null"Default Encoding HTML codes
url3986URL Encoding (RFC 3986)
base64Base64 encoding
Example:   options = {
                encode: 'url3986'
            }

Token {String}:

ValueDescription
"null"No token in query
"token"Use getToken() to get a token
Example:
     let token;
     opentriviaapi.getToken()
       .then((data) => {
           token = data.token;
       });

     opentriviaapi.getQuestions({token: token})
       .then((data) => {
           console.log(data);
       });

Combined:

Example:   options = {
                amount: 35,
                category: 18,
                difficulty: 'easy',
                type: 'multiple',
                encode: 'url3986',
                token: token,
            }
0.1.1

6 years ago

0.1.0

6 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago