Class OneDriveConnection

java.lang.Object
com.amilesend.client.connection.Connection<GsonFactory>
com.amilesend.onedrive.connection.OneDriveConnection

public class OneDriveConnection extends com.amilesend.client.connection.Connection<GsonFactory>
Wraps a OkHttpClient that manages authentication refresh and parsing responses to corresponding POJO types. Construct a new instance via the OneDriveConnection.OneDriveConnectionBuilder that simplifies configuration of the OneDriveAuthManager and automatically sets a pre-configured Gson instance for proper request/response serialization.
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
     

    Nested classes/interfaces inherited from class com.amilesend.client.connection.Connection

    com.amilesend.client.connection.Connection.ConnectionBuilder<G extends com.amilesend.client.parse.GsonFactoryBase,C extends com.amilesend.client.connection.Connection<G>,B extends com.amilesend.client.connection.Connection.ConnectionBuilder<G,C,B>>
  • Field Summary

    Fields inherited from class com.amilesend.client.connection.Connection

    JSON_CONTENT_TYPE, JSON_MEDIA_TYPE
  • Method Summary

    Modifier and Type
    Method
    Description
     
    long
    download(@NonNull okhttp3.Request request, @NonNull Path folderPath, String name, long sizeBytes, @NonNull com.amilesend.client.connection.file.TransferProgressCallback callback)
    Downloads the contents for the given request to the specified folderPath and name.
    downloadAsync(@NonNull okhttp3.Request request, @NonNull Path folderPath, String name, long sizeBytes, @NonNull com.amilesend.client.connection.file.TransferProgressCallback callback)
    Downloads the contents for the given request asynchronously to the specified folderPath and name.
    executeAsync(@NonNull okhttp3.Request request, @NonNull com.amilesend.client.parse.parser.GsonParser<T> parser)
    Executes the given Request and parses the JSON-formatted response with given GsonParser.
    executeRemoteAsync(@NonNull okhttp3.Request request)
    Executes the given Request for a remote asynchronous operation and returns the monitoring URL.
    okhttp3.Request.Builder
    Creates a new Request.Builder with pre-configured headers for a request that contains both a JSON-formatted request and response body.

    Methods inherited from class com.amilesend.client.connection.Connection

    execute, execute, getAuthManager, getBaseUrl, getGsonFactory, getHttpClient, getUserAgent, isGzipContentEncodingEnabled, newRequestBuilder

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • newWithBodyRequestBuilder

      public okhttp3.Request.Builder newWithBodyRequestBuilder()
      Creates a new Request.Builder with pre-configured headers for a request that contains both a JSON-formatted request and response body.
      Returns:
      the request builder
    • executeRemoteAsync

      public String executeRemoteAsync(@NonNull okhttp3.Request request) throws com.amilesend.client.connection.ConnectionException
      Executes the given Request for a remote asynchronous operation and returns the monitoring URL.
      Parameters:
      request - the request
      Returns:
      the monitoring URL to track the remote asynchronous operation
      Throws:
      com.amilesend.client.connection.ConnectionException - if an error occurred during the transaction
    • executeAsync

      public <T> CompletableFuture<T> executeAsync(@NonNull okhttp3.Request request, @NonNull com.amilesend.client.parse.parser.GsonParser<T> parser)
      Executes the given Request and parses the JSON-formatted response with given GsonParser.
      Type Parameters:
      T - the POJO resource type
      Parameters:
      request - the request
      parser - the parser to decode the response body
      Returns:
      the CompletableFuture used to fetch the parsed response or failure exception reason
    • download

      public long download(@NonNull okhttp3.Request request, @NonNull Path folderPath, String name, long sizeBytes, @NonNull com.amilesend.client.connection.file.TransferProgressCallback callback) throws com.amilesend.client.connection.ConnectionException
      Downloads the contents for the given request to the specified folderPath and name.
      Parameters:
      request - the request
      folderPath - the path of the folder to download the contents to
      name - the name of the file to download the contents to
      sizeBytes - the total size of the expected file in bytes
      callback - the TransferProgressCallback call to invoke to report download transfer progress
      Returns:
      the size of the downloaded file in bytes
      Throws:
      com.amilesend.client.connection.ConnectionException - if an error occurred while downloading the content for the request
    • downloadAsync

      public CompletableFuture<Long> downloadAsync(@NonNull okhttp3.Request request, @NonNull Path folderPath, String name, long sizeBytes, @NonNull com.amilesend.client.connection.file.TransferProgressCallback callback)
      Downloads the contents for the given request asynchronously to the specified folderPath and name.
      Parameters:
      request - the request
      folderPath - the path of the folder to download the contents to
      name - the name of the file to download the contents to
      sizeBytes - the total size of the expected file in bytes
      callback - the TransferProgressCallback call to invoke to report download transfer progress
      Returns:
      the CompletableFuture used to fetch the number of bytes downloaded
    • builder

      public static OneDriveConnection.OneDriveConnectionBuilder<?,?> builder()