Class BraveSpellcheckQuery
- All Implemented Interfaces:
BraveQueryBuilder<BraveSpellcheckQuery,SpellcheckSearchApiResponse>
This class is not intended to be instantiated directly, instead use the builder()
method to create a new instance of the builder.
The builder is not thread-safe and not intended to be instantiated directly, instead use the
builder() method to create a new instance of the builder. Also note that this builder is
a stateful, reusable builder intended for single-threaded use.
Method reset() will clear the internal state of the builder and must be called before
reusing.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class net.ygbstudio.jbrave.core.builders.AbstractQueryUrlBuilder
delayedOperators, optionTracker, QUERY_PROMPT, urlEnd, urlStart -
Method Summary
Modifier and TypeMethodDescriptionstatic BraveSpellcheckQuerybuilder()<T extends CountryIdentifier>
BraveSpellcheckQuerycountry(T country) Adds the country option to the URL query.execute()Executes the request and returns response of string.@NotNull Optional<HttpResponse<String>> Returns the current HTTP response as anOptional.Returns the type of the API response.booleanChecks if the request has been executed.<T extends LanguageIdentifier>
BraveSpellcheckQuerylanguage(T language) Adds the language option to the URL query.Adds a search term to the URL query.reset()Clears the current instance ofBraveSpellcheckQueryby resetting its state to its initial values.Converts the current query to anHttpRequestinstance.withHeaders(@NotNull Consumer<BraveSpellcheckQuery.BraveRequestBuilder> headers) Sets the request headers using the provided consumer.withRetries(int maxRetries) Sets the maximum number of retry attempts for rate-limited (HTTP 429) responses.withToken(@NotNull ClientInfo clientInfo) Sets the subscription token header using the providedClientInfoinstance.Methods inherited from class net.ygbstudio.jbrave.core.builders.AbstractQueryUrlBuilder
addInstanceVertical, addOption, addOptionCarrier, addQueryTerm, build, clear, isValidQuery, optionMissing, queryMissing, self, toURIMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.ygbstudio.jbrave.api.builders.BraveQueryBuilder
getEitherPOJO, getErrorPOJO, getPOJO, getRateLimitPolicy, getRateLimitRemaining, getRateLimits, toURI
-
Method Details
-
builder
-
query
Adds a search term to the URL query. Maximum of 400 characters and 50 words.If a query is already present, subsequent calls are ignored. Only one query term is supported per search request.
- Parameters:
queryTerm- the search term to add- Returns:
- the current instance of the builder
-
language
Adds the language option to the URL query.- Parameters:
language- The language identifier to set.- Returns:
- The current instance of the builder.
- See Also:
-
country
Adds the country option to the URL query.- Parameters:
country- The country identifier to set.- Returns:
- The current instance of the builder.
- See Also:
-
withToken
@Contract("_ -> this") public BraveSpellcheckQuery withToken(@NotNull @NotNull ClientInfo clientInfo) Sets the subscription token header using the providedClientInfoinstance.- Parameters:
clientInfo- theClientInfoinstance containing the subscription token- Returns:
- the current instance of
BraveSpellcheckQuery
-
withHeaders
@Contract("_ -> this") public BraveSpellcheckQuery withHeaders(@NotNull @NotNull Consumer<BraveSpellcheckQuery.BraveRequestBuilder> headers) Sets the request headers using the provided consumer.- Parameters:
headers- a consumer that accepts an inner request builder instance and applies preconfigured headers to it via helper methods.- Returns:
- the current instance of
BraveSpellcheckQuery
-
withRetries
Sets the maximum number of retry attempts for rate-limited (HTTP 429) responses.Values less than or equal to zero fall back to the default retry policy (one retry). Retries sleep for the server-provided rate limit reset window before each attempt.
- Parameters:
maxRetries- the maximum number of retry attempts for rate-limited responses- Returns:
- the current instance of
BraveSpellcheckQuery
-
execute
Executes the request and returns response of string.- Specified by:
executein interfaceBraveQueryBuilder<BraveSpellcheckQuery,SpellcheckSearchApiResponse> - Returns:
- an optional response to the request
-
hasExecuted
public boolean hasExecuted()Description copied from interface:BraveQueryBuilderChecks if the request has been executed. Precisely, it will tell the caller whether the builder has an existing (complete) request in it or not.- Specified by:
hasExecutedin interfaceBraveQueryBuilder<BraveSpellcheckQuery,SpellcheckSearchApiResponse> - Returns:
trueif the request has been executed,falseotherwise
-
toHttpRequest
Description copied from interface:BraveQueryBuilderConverts the current query to anHttpRequestinstance.- Specified by:
toHttpRequestin interfaceBraveQueryBuilder<BraveSpellcheckQuery,SpellcheckSearchApiResponse> - Returns:
- the
HttpRequestinstance representing the current query
-
getHttpResponse
Returns the current HTTP response as anOptional.If the request has not been executed, this method will execute the request and return the
HttpResponse.- Specified by:
getHttpResponsein interfaceBraveQueryBuilder<BraveSpellcheckQuery,SpellcheckSearchApiResponse> - Returns:
- an
Optionalcontaining the current HTTP response.
-
getResponseType
Description copied from interface:BraveQueryBuilderReturns the type of the API response. The class returned by this method is the class of the concrete implementation ofApiResponsethat this builder is expected to produce as a result of its query.- Specified by:
getResponseTypein interfaceBraveQueryBuilder<BraveSpellcheckQuery,SpellcheckSearchApiResponse> - Returns:
- the class of the API response
-
reset
Clears the current instance ofBraveSpellcheckQueryby resetting its state to its initial values.- Specified by:
resetin interfaceBraveQueryBuilder<BraveSpellcheckQuery,SpellcheckSearchApiResponse> - Returns:
- the current instance of
BraveSpellcheckQuery
-