Table of Contents

Interface IOpenTriviaService

Namespace
Tudormobile.OpenTrivia.UI.Services
Assembly
Tudormobile.OpenTrivia.UI.dll

Provides access to the Open Trivia Database API for retrieving trivia categories and questions.

public interface IOpenTriviaService

Methods

Create(IOpenTriviaClient, ILogger<IOpenTriviaService>?)

Creates and initializes a new instance of the IOpenTriviaService interface.

public static IOpenTriviaService Create(IOpenTriviaClient client, ILogger<IOpenTriviaService>? logger = null)

Parameters

client IOpenTriviaClient

The Open Trivia API client.

logger ILogger<IOpenTriviaService>

The logger for diagnostic information.

Returns

IOpenTriviaService

GetCategoriesAsync(CancellationToken)

Retrieves all available trivia categories from the Open Trivia Database.

Task<ServiceResult<IReadOnlyList<TriviaCategory>>> GetCategoriesAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token to cancel the asynchronous operation.

Returns

Task<ServiceResult<IReadOnlyList<TriviaCategory>>>

A service result containing a read-only list of trivia categories, or an error if the operation failed.

GetQuestionsAsync(int, IEnumerable<TriviaCategory>, CancellationToken)

Retrieves a specified number of trivia questions from the given categories.

Task<ServiceResult<IReadOnlyList<TriviaQuestion>>> GetQuestionsAsync(int amount, IEnumerable<TriviaCategory> categories, CancellationToken cancellationToken = default)

Parameters

amount int

The number of questions to retrieve.

categories IEnumerable<TriviaCategory>

The categories from which to retrieve questions.

cancellationToken CancellationToken

A token to cancel the asynchronous operation.

Returns

Task<ServiceResult<IReadOnlyList<TriviaQuestion>>>

A service result containing a read-only list of trivia questions, or an error if the operation failed.