Class ContentRequest<T extends ContentRequest,C extends AssetObject>
java.lang.Object
com.oracle.content.sdk.request.core.ContentRequest<T,C>
- Type Parameters:
T
- The Request class (e.g. SearchContentItemsRequest)C
- The result object to deserialize (e.g. ContentSearchResult)
- Direct Known Subclasses:
ContentRequestById
,GetApiInfoRequest
,PaginatedListRequest
Base class for SDK requests, including methods commons to all request such as the ability
to disable the cache for a single call
noCache()
or specify common options
such as linksNone()
.
There are various methods used to make the SDK call as well as the code to deserialize the response
into a result object. See the various methods for initiating the request such as
fetch()
, fetchAsync(ContentCallback)
, and observable()
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ContentDeliveryClient
protected String
protected final Class
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
ContentRequest
(@NotNull ContentDeliveryClient client, @NotNull Class objectClass) -
Method Summary
Modifier and TypeMethodDescriptionprotected C
deserializeObject
(com.google.gson.JsonElement jsonElement) fetch()
This is a synchronous method to make the SDK request that will return with aContentResponse
object.void
fetchAsync
(ContentCallback<C> callback) This makes an asynchronous SDK request on a separate thread and will return the resultingContentResponse
in aContentCallback
method.This is a synchronous method to make the SDK request but differs from the methodfetch()
as it will return the expected object directly instead of the containingContentResponse
object.protected String
Cache-control string to use (will be set to no-cache if noCache is set)abstract retrofit2.Call<com.google.gson.JsonElement>
getCall()
Get the retrofit call to make for this request..protected T
getThis()
Override to return this.protected static com.google.gson.Gson
gson()
The gson object to use for deserializationSpecify which links should be returned in result.Same as a call tolinks
specifying "none", so no links will be returnednoCache()
Optional override of cache policy which will force the call to get the data from the network and not use the cache.io.reactivex.rxjava3.core.Single<ContentResponse<C>>
Create an RxJava Single observable object which can then be subscribed to to get aContentResponse
.io.reactivex.rxjava3.core.Single<C>
Create an RxJava Single observable object which can then be subscribed on to get the result object as part of the response.
-
Field Details
-
objectClass
-
client
-
links
-
-
Constructor Details
-
ContentRequest
protected ContentRequest(@NotNull @NotNull ContentDeliveryClient client, @NotNull @NotNull Class objectClass)
-
-
Method Details
-
deserializeObject
-
getCall
public abstract retrofit2.Call<com.google.gson.JsonElement> getCall()Get the retrofit call to make for this request..- Returns:
- return the retrofit call object to use for this request
-
fetchResult
This is a synchronous method to make the SDK request but differs from the methodfetch()
as it will return the expected object directly instead of the containingContentResponse
object. If an error occurs aContentException
will be thrown. You can use this method if you just want the object result directly and prefer to have a try/catch block to handle any errors. Example to get a content item:GetContentItemRequest request = new GetContentItemRequest(deliveryClient, itemID); try { ContentItem result = request.fetchResult(); } catch (ContentException e) { // handle error }
- Returns:
- The result object from the response.
- Throws:
ContentException
- if there is an error
-
fetch
This is a synchronous method to make the SDK request that will return with aContentResponse
object. This method will not throw an exception but if there is an exception it will be contained in the response. Use this method if you want the fullContentResponse
object or prefer a method that does not throw exceptions. See alsofetchResult()
Example to get a content item:GetContentItemRequest request = new GetContentItemRequest(deliveryClient, itemID); ContentResponse response = request.fetch(); if (response.isSuccess()) { ContentItem result = response.getResult() } else { // handle error }
- Returns:
- returns the
ContentResponse
after completion of the call
-
fetchAsync
This makes an asynchronous SDK request on a separate thread and will return the resultingContentResponse
in aContentCallback
method. Example to get a content item:GetContentItemRequest request = new GetContentItemRequest(clientAPI, itemID); request.fetchAsync(response -> { if (response.isSuccess()) { ContentItem item = response.getResult(); } else { // handle error } });
- Parameters:
callback
- The callback method to call after completion of the call.
-
observableResult
Create an RxJava Single observable object which can then be subscribed on to get the result object as part of the response. If the fullContentResponse
object is needed, useobservable()
}. Example code to make a blocking (synchronous) call to get a content item:GetContentItemRequest request = new GetContentItemRequest(clientAPI, itemID); ContentItem item = request.observableResult().blockingGet();
- Returns:
- RxJava observable object to subscribe to for the result object
-
observable
Create an RxJava Single observable object which can then be subscribed to to get aContentResponse
. If only the result object is desired, theobservableResult()
method can be used instead to directly observe the result of the object. Example code to make an asynchronous call to get a content item:GetContentItemRequest request = new GetContentItemRequest(clientAPI, itemID); request.observable(). .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe( response -> { // valid response, get content item in result ContentItem item = response.getResult(); }, error -> { // handle error } );
- Returns:
- RxJava observable object to subscribe to for the
ContentResponse
-
getThis
Override to return this. Solution for the unchecked cast warning.- Returns:
- this
-
noCache
Optional override of cache policy which will force the call to get the data from the network and not use the cache.- Returns:
- this
-
getCacheControl
Cache-control string to use (will be set to no-cache if noCache is set)- Returns:
- cache-control header string
-
links
Specify which links should be returned in result. If you don't care about the "links", just uselinksNone()
- Parameters:
links
- A comma delimited list of links to include.- Returns:
- this
-
linksNone
Same as a call tolinks
specifying "none", so no links will be returned- Returns:
- this
-
gson
protected static com.google.gson.Gson gson()The gson object to use for deserialization- Returns:
- gson instance
-