Table of Contents

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

client IOpenTriviaClient
amount int

The number of questions to retrieve (1-50) for EACH provided category.

categories IEnumerable<TriviaCategory>

The categories to filter by, or null for any category.

difficulty TriviaQuestionDifficulty?

The difficulty level to filter by, or null for any difficulty.

type TriviaQuestionType?

The question type to filter by, or null for any type.

encoding ApiEncodingType?

The encoding type for the response, or null for default encoding.

token ApiSessionToken

The session token to use, or null for no session.

cancellationToken CancellationToken

The 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.