Interface IOpenTriviaClient
- Namespace
- Tudormobile.OpenTrivia
- Assembly
- Tudormobile.OpenTrivia.dll
Defines methods for interacting with the Open Trivia Database API.
public interface IOpenTriviaClient
- Extension Methods
Methods
Create(HttpClient, ILogger?, IApiDataSerializer?, bool, bool, ApiEncodingType?)
Creates and initializes an instance of the IOpenTriviaClient interface.
public static IOpenTriviaClient Create(HttpClient httpClient, ILogger? logger = null, IApiDataSerializer? serializer = null, bool manageRateLimit = false, bool autoDecode = false, ApiEncodingType? encodingType = null)
Parameters
httpClientHttpClientThe HttpClient class to use.
loggerILoggerOptional logger instance for logging diagnostic information. If null, a NullLogger will be used.
serializerIApiDataSerializerOptional serializer instance for serializing and deserializing API data. If null, the internal serializer will be used.
manageRateLimitboolAutomatically manage rate limits.
autoDecodeboolAutomatically decode API responses.
encodingTypeApiEncodingType?The encoding type to use for API requests.
Returns
Remarks
If an encodingType is provided, it will be used when not explicitly provided to method calls. If autoDecode is enabled, the client will attempt to decode API responses using the specified encoding type or the default encoding if none is specified. If autoDecode is disabled, the client will return raw API responses without decoding. When autoDecode is not enabled (default behavior), the client will return raw API responses without decoding, regardless of the specified encoding type. This allows you to specify the encoding and manage rate limits without automatically decoding responses, giving you more control over how you handle API data.
GetCategoriesAsync(CancellationToken)
Retrieves a list of all available trivia categories from the API.
Task<ApiResponse<List<TriviaCategory>>> GetCategoriesAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<ApiResponse<List<TriviaCategory>>>
An ApiResponse<T> containing the list of categories.
GetQuestionCountAsync(TriviaCategory, CancellationToken)
Asynchronously retrieves the total number of questions available in the system for a specific category.
Task<ApiResponse<TriviaQuestionCount>> GetQuestionCountAsync(TriviaCategory category, CancellationToken cancellationToken = default)
Parameters
categoryTriviaCategoryThe category to filter by.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<ApiResponse<TriviaQuestionCount>>
An ApiResponse<T> containing the total count of questions for the specified category.
GetQuestionsAsync(int, TriviaCategory?, TriviaQuestionDifficulty?, TriviaQuestionType?, ApiEncodingType?, ApiSessionToken?, CancellationToken)
Retrieves trivia questions from the API with optional filtering.
Task<ApiResponse<List<TriviaQuestion>>> GetQuestionsAsync(int amount, TriviaCategory? category = null, TriviaQuestionDifficulty? difficulty = null, TriviaQuestionType? type = null, ApiEncodingType? encoding = null, ApiSessionToken? token = null, CancellationToken cancellationToken = default)
Parameters
amountintThe number of questions to retrieve (1-50).
categoryTriviaCategoryThe category to filter by, or null for any category.
difficultyTriviaQuestionDifficulty?The difficulty level to filter by, or null for any difficulty.
typeTriviaQuestionType?The question type to filter by, or null for any type.
encodingApiEncodingType?The encoding type for the response, or null for default encoding.
tokenApiSessionTokenThe session token to use, or null for no session.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<ApiResponse<List<TriviaQuestion>>>
An ApiResponse<T> containing the list of trivia questions.
GetSessionTokenAsync(CancellationToken)
Retrieves a new session token from the API.
Task<ApiResponse<ApiSessionToken>> GetSessionTokenAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<ApiResponse<ApiSessionToken>>
An ApiResponse<T> containing the session token.
ResetSessionTokenAsync(ApiSessionToken, CancellationToken)
Resets an existing session token, clearing its question history.
Task<ApiResponse<ApiSessionToken>> ResetSessionTokenAsync(ApiSessionToken token, CancellationToken cancellationToken = default)
Parameters
tokenApiSessionTokenThe session token to reset.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<ApiResponse<ApiSessionToken>>
An ApiResponse<T> containing the reset session token.