OpenTDB-Wrapper
1.0.0
See the version list below for details.
dotnet add package OpenTDB-Wrapper --version 1.0.0
NuGet\Install-Package OpenTDB-Wrapper -Version 1.0.0
<PackageReference Include="OpenTDB-Wrapper" Version="1.0.0" />
paket add OpenTDB-Wrapper --version 1.0.0
#r "nuget: OpenTDB-Wrapper, 1.0.0"
// Install OpenTDB-Wrapper as a Cake Addin #addin nuget:?package=OpenTDB-Wrapper&version=1.0.0 // Install OpenTDB-Wrapper as a Cake Tool #tool nuget:?package=OpenTDB-Wrapper&version=1.0.0
OpenTDB-Wrapper
An async C# wrapper for the Open Trivia DB API.
For a more detailed README checkout the GitHub.
Usage
Setup
As a good rule of thumb, add these using
statements.
using OpenTDB; // For fetching questions from the API
using OpenTDB.Enumerators; // For specifying optional paramters
using OpenTDB.Exceptions; // For handling OpenTDB exceptions
using OpenTDB.Models; // For interacting with the Question class
Create an instance of OpenTDB
.
OpenTDB.OpenTDB openTDB = new(); // This contains an HttpClient and it is good practice to not duplicate it.
Getting Questions
Use GetQuestionsAsync()
to get a list of questions. This method has default values of Category.Any
, Difficulty.Any
, and QuestionType.Any
.
await openTDB.GetQuestionsAsync(10);
// returns a List<Question> with a Count of 10.
Here is a more complicated example. If you wanted to get 10 Nature questions, that were of easy difficulty, and in the form of multiple-choice questions, it would look like so:
await openTDB.GetQuestionsAsync(10, Category.Nature, Difficulty.Easy, QuestionType.MultipleChoice);
// returns a List<Question> with a Count of 10.
Here is a more complicated example. If you wanted to get 10 Nature questions, that were of easy difficulty, in the form of a multiple-choice questions, and had legacy URL encoding it would look like so:
await openTDB.GetQuestionsWithEncodingAsync(10, Category.Nature, Difficulty.Easy, QuestionType.MultipleChoice, Encoding.LegacyURL);
// returns a List<Question> with a Count of 10.
Questions
The Question
class looks like this:
public class Question
{
public string Type { get; set; }
public string Difficulty { get; set; }
public string Category { get; set; }
public string QuestionTitle { get; set; }
public string CorrectAnswer { get; set; }
public string[] IncorrectAnswers { get; set; }
}
Legal Stuff
- Open Trivia DB API uses Creative Commons Attribution-ShareAlike 4.0 International License.
- OpenTDB-Wrapper uses GPL-3.0 License and is not affiliated with the Open Trivia Database.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Add GetQuestionsAsync() for ease of use.