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

public abstract class ContentRequest<T extends ContentRequest,C extends AssetObject> extends Object
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 Details

  • Constructor Details

  • Method Details

    • deserializeObject

      protected C deserializeObject(com.google.gson.JsonElement jsonElement)
    • 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

      public C fetchResult() throws ContentException
      This is a synchronous method to make the SDK request but differs from the method fetch() as it will return the expected object directly instead of the containing ContentResponse object. If an error occurs a ContentException 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

      public ContentResponse<C> fetch()
      This is a synchronous method to make the SDK request that will return with a ContentResponse 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 full ContentResponse object or prefer a method that does not throw exceptions. See also fetchResult() 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

      public void fetchAsync(ContentCallback<C> callback)
      This makes an asynchronous SDK request on a separate thread and will return the resulting ContentResponse in a ContentCallback 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

      public io.reactivex.rxjava3.core.Single<C> 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 full ContentResponse object is needed, use observable()}. 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

      public io.reactivex.rxjava3.core.Single<ContentResponse<C>> observable()
      Create an RxJava Single observable object which can then be subscribed to to get a ContentResponse. If only the result object is desired, the observableResult() 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

      protected T getThis()
      Override to return this. Solution for the unchecked cast warning.
      Returns:
      this
    • noCache

      public T 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

      protected String getCacheControl()
      Cache-control string to use (will be set to no-cache if noCache is set)
      Returns:
      cache-control header string
    • links

      public T links(String links)
      Specify which links should be returned in result. If you don't care about the "links", just use linksNone()
      Parameters:
      links - A comma delimited list of links to include.
      Returns:
      this
    • linksNone

      public T linksNone()
      Same as a call to links 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