Class OpenTriviaClientExtensions
- Namespace
- Tudormobile.OpenTrivia.Extensions
- Assembly
- Tudormobile.OpenTrivia.dll
Provides extension methods for working with instances of IOpenTriviaClient.
public static class OpenTriviaClientExtensions
- Inheritance
-
OpenTriviaClientExtensions
- Inherited Members
Remarks
This class contains static methods that extend the functionality of IOpenTriviaClient implementations, enabling fluent configuration and builder patterns. These extensions are intended to simplify client setup and integration scenarios.
The code uses the newer C# extension method syntax with the 'extension' keyword for better readability and conciseness.
Methods
GetBuilder()
Creates a new builder for configuring and constructing an instance of an Open Trivia client.
public static IOpenTriviaClientBuilder GetBuilder()
Returns
- IOpenTriviaClientBuilder
An IOpenTriviaClientBuilder that can be used to configure and build an IOpenTriviaClient instance.
GetQuestionsAsync(IOpenTriviaClient, int, IEnumerable<TriviaCategory>, TriviaQuestionDifficulty?, TriviaQuestionType?, ApiEncodingType?, ApiSessionToken?, CancellationToken)
Retrieves trivia questions from the API with optional filtering across multiple categories.
public static Task<ApiResponse<List<TriviaQuestion>>> GetQuestionsAsync(this IOpenTriviaClient client, int amount, IEnumerable<TriviaCategory> categories, TriviaQuestionDifficulty? difficulty = null, TriviaQuestionType? type = null, ApiEncodingType? encoding = null, ApiSessionToken? token = null, CancellationToken cancellationToken = default)
Parameters
clientIOpenTriviaClientamountintThe number of questions to retrieve (1-50) for EACH provided category.
categoriesIEnumerable<TriviaCategory>The categories 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.
Remarks
This API call can take a long time to complete due to the rate limit of 1 request every 5 seconds. At a minimum, this method will take 5 * (n-1) seconds to complete, where n is the number of categories specified.