Skip to content

angelsflyinhell/OpenTDB4j

Repository files navigation

Maven Central

OpenTDB4j

A Simple Wrapper for the OpenTDB API in Java Maven. Full Documentation

Status: Discontinued

Download

Apache Maven

<dependency>
  <groupId>com.github.shinixsensei-dev</groupId>
  <artifactId>OpenTDB4j</artifactId>
  <version>VERSION</version>
</dependency>

Gradle

Kotlin DSL

implementation("com.github.shinixsensei-dev:OpenTDB4j:VERSION")

Groovy DSL

implementation 'com.github.shinixsensei-dev:OpenTDB4j:VERSION'

It's recommended to use the newest Version in the Release Tab.

Usage

   public static void main(String[] Args) throws LoginException {
       OpenTDB obj = new OpenTDB();
       obj.setCategory(29);
       obj.setDifficulty("easy");

       obj.getTrivia();

       System.out.println(obj.getQuestion());
       System.out.println(obj.getCorrectAnswer());

       String[] incorrectAnswers = obj.getIncorrectAnswers();
       for (int i = 0; i < obj.incorrectAnswers.length ; i++) {
           System.out.println(obj.incorrectAnswers[i]);
       }

       System.out.println(obj.getCategory());
       System.out.println(obj.getDifficulty());
       System.out.println(obj.getType());

   }

View OpenTDB to see available selections for .setCategory() and .setDifficulty().

Configuration

First, create a new OpenTDB Object

   OpenTDB obj = new OpenTDB();

After that, you can set a category and a difficulty (optional (Will be random if none is set))

   obj.setCategory(29);
   obj.setDifficulty("easy");

Get Response

Now run the method by using

    obj.getTrivia();

You can now read out the API Response by using obj as follows

   System.out.println(obj.getQuestion());
   System.out.println(obj.getCorrectAnswer());
              
       String[] incorrectAnswers = obj.getIncorrectAnswers();
       for (int i = 0; i < obj.incorrectAnswers.length ; i++) {
           System.out.println(obj.incorrectAnswers[i]);
       }
              
   System.out.println(obj.getCategory());
   System.out.println(obj.getDifficulty());