Class BraveImageQuery
- All Implemented Interfaces:
BraveQueryBuilder<BraveImageQuery,ImageSearchApiResponse>
This class is specifically designed for constructing Brave Image Search API queries, and 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
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 BraveImageQuerybuilder()Returns a new instance ofBraveImageQuerycount(int count) Adds the count option to the URL query.<T extends CountryIdentifier>
BraveImageQuerycountry(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>
BraveImageQuerylanguage(T searchLanguage) Adds the search language option to the URL query.Adds a search term to the URL query.reset()Clears the current instance ofBraveImageQueryby resetting its state to its initial values.safeSearch(@NotNull SafeSearch safeSearch) Adds a safe search option to the URL query.spellcheck(boolean spellCheck) Adds the spell check option to the URL query.Converts the current query to anHttpRequestinstance.withHeaders(@NotNull Consumer<BraveImageQuery.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
Returns a new instance ofBraveImageQuery- Returns:
- a new instance of
BraveImageQuery
-
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 search language option to the URL query.- Parameters:
searchLanguage- the search language to set- Returns:
- the current instance of the builder
- See Also:
-
safeSearch
Adds a safe search option to the URL query.- Parameters:
safeSearch- aSafeSearchenum value specifying the safe search level- Returns:
- the current instance of the builder
-
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:
-
count
Adds the count option to the URL query.- Parameters:
count- the number of results to return- Returns:
- the current instance of the builder
-
spellcheck
Adds the spell check option to the URL query.- Parameters:
spellCheck- whether to enable spellcheck- Returns:
- the current instance of the builder
-
withToken
Sets the subscription token header using the providedClientInfoinstance.- Parameters:
clientInfo- theClientInfoinstance containing the subscription token- Returns:
- the current instance of
BraveImageQuery
-
withHeaders
@Contract("_ -> this") public BraveImageQuery withHeaders(@NotNull @NotNull Consumer<BraveImageQuery.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
BraveImageQuery
-
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
BraveImageQuery
-
execute
Executes the request and returns response of string.- Specified by:
executein interfaceBraveQueryBuilder<BraveImageQuery,ImageSearchApiResponse> - 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<BraveImageQuery,ImageSearchApiResponse> - Returns:
trueif the request has been executed,falseotherwise
-
toHttpRequest
Converts the current query to anHttpRequestinstance.- Specified by:
toHttpRequestin interfaceBraveQueryBuilder<BraveImageQuery,ImageSearchApiResponse> - Returns:
- the
HttpRequestinstance representing the current query
-
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<BraveImageQuery,ImageSearchApiResponse> - Returns:
- the class of the API response
-
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<BraveImageQuery,ImageSearchApiResponse> - Returns:
- an
Optionalcontaining the current HTTP response.
-
reset
Clears the current instance ofBraveImageQueryby resetting its state to its initial values.- Specified by:
resetin interfaceBraveQueryBuilder<BraveImageQuery,ImageSearchApiResponse> - Returns:
- the current instance of
BraveImageQuery
-