Interface IOpenTriviaClientBuilder
- Namespace
- Tudormobile.OpenTrivia
- Assembly
- Tudormobile.OpenTrivia.dll
Provides a fluent interface for configuring and building instances of IOpenTriviaClient.
public interface IOpenTriviaClientBuilder
Methods
AddLogging(ILogger)
Adds the specified logger to the client builder for capturing diagnostic and operational messages.
IOpenTriviaClientBuilder AddLogging(ILogger logger)
Parameters
loggerILoggerThe logger instance to use for logging client activity. Cannot be null.
Returns
- IOpenTriviaClientBuilder
The current instance of the client builder for method chaining.
Build()
Builds and returns a configured instance of IOpenTriviaClient using the settings specified through the builder.
IOpenTriviaClient Build()
Returns
- IOpenTriviaClient
A fully configured IOpenTriviaClient instance ready to interact with the Open Trivia Database API.
UseAutoDecoding(bool)
Configures the client to automatically decode API responses.
IOpenTriviaClientBuilder UseAutoDecoding(bool autoDecode = true)
Parameters
Returns
- IOpenTriviaClientBuilder
An instance of IOpenTriviaClientBuilder for further client configuration.
Remarks
Automatic decoding converts API responses from their encoded format (e.g., Base64) to a human-readable format. This takes place regardless of the encoding type specified for API communication, ensuring that the client can handle responses appropriately without requiring manual decoding by the caller. In cases where an explicit encoding is specified in a method call, that encoding will be used; otherwise, the configured encoding type for the client is used if set, or the default encoding behavior of the API is applied. This allows for flexible handling of API responses while ensuring that the configured encoding is used.
WithEncoding(ApiEncodingType)
Configures the client to use the specified encoding type for API requests.
IOpenTriviaClientBuilder WithEncoding(ApiEncodingType encodingType)
Parameters
encodingTypeApiEncodingTypeThe encoding type to use for API communication.
Returns
- IOpenTriviaClientBuilder
An instance of IOpenTriviaClientBuilder for further client configuration.
Remarks
Specifies the encoding type to use for API communication. This setting determines how the client encodes requests and decodes responses when an explicit encoding is not specified in a method call.
WithHttpClient(HttpClient)
Configures the builder to use the specified HTTP client for sending requests to the OpenTriviaDB API.
IOpenTriviaClientBuilder WithHttpClient(HttpClient httpClient)
Parameters
httpClientHttpClientThe HTTP client instance to use for all outgoing API requests. Cannot be null. The caller is responsible for managing the lifetime of the provided client.
Returns
- IOpenTriviaClientBuilder
The current builder instance configured to use the specified HTTP client.
Remarks
Use this method to provide a custom-configured HttpClient, for example to set custom headers, proxies, or timeouts. If not set, a default HttpClient may be used by the implementation.
WithRateLimitManagement(bool)
Configures the client to automatically manage API rate limits.
IOpenTriviaClientBuilder WithRateLimitManagement(bool manageRateLimit)
Parameters
manageRateLimitboolA value indicating whether rate limit management should be enabled. Specify true to allow the client to handle rate limiting automatically; otherwise, specify false.
Returns
- IOpenTriviaClientBuilder
An instance of IOpenTriviaClientBuilder for further client configuration.
Remarks
Enabling rate limit management helps prevent exceeding API request limits, reducing the likelihood of errors and improving application reliability.
WithSerializer(IApiDataSerializer)
Configures the builder to use the specified serializer for handling API response data.
IOpenTriviaClientBuilder WithSerializer(IApiDataSerializer serializer)
Parameters
serializerIApiDataSerializerThe serializer instance to use for serializing and deserializing API data. Cannot be null.
Returns
- IOpenTriviaClientBuilder
The current instance of the client builder for method chaining.