Package com.draftable.api.client
Class Comparisons
java.lang.Object
com.draftable.api.client.Comparisons
- All Implemented Interfaces:
Closeable,AutoCloseable
Client for the `comparisons` endpoint in the Draftable Comparison API.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThrown when acreateComparison(com.draftable.api.client.Comparisons.Side, com.draftable.api.client.Comparisons.Side)request is made with bad parameters.static classThrown when the agetComparison(String)ordeleteComparison(String)request is made for a non-existent comparison.static classThrown when a request is made, but the provided auth token is invalid.static final classRepresents a file passed in as one side of a comparison.static classThrown when an unknown error occurs while making a request. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionComparisons(String accountId, String authToken) Constructs aComparisonsinstance for the given credentials, which can then be used to make API requests.Comparisons(String accountId, String authToken, String apiBaseUrl) Constructs aComparisonsinstance for the given credentials and apiBaseUrl, which can then be used to make API requests. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes any open inner HTTP clients, and ends any async event loops.createComparison(Comparisons.Side left, Comparisons.Side right) Synchronously creates a *private* comparison that never expires with the given sides and an automatically generated identifier.createComparison(Comparisons.Side left, Comparisons.Side right, String identifier, boolean isPublic, Instant expires) Synchronously creates a comparison with the given sides and properties.createComparisonAsync(Comparisons.Side left, Comparisons.Side right) Asynchronously creates a *private* comparison that never expires with the given sides and an automatically generated identifier.createComparisonAsync(Comparisons.Side left, Comparisons.Side right, String identifier, boolean isPublic, Instant expires) Asynchronously creates a comparison with the given sides and properties.createExport(String comparisonId, ExportKind exportKind) createExport(String comparisonId, ExportKind exportKind, boolean includeCoverPage) Creates a new export of given kind for given comparisonvoiddeleteComparison(String identifier) Synchronously deletes a given comparison.deleteComparisonAsync(String identifier) Asynchronously deletes a given comparison.static StringSynchronously gets a list of all of the account's comparisons.Asynchronously gets a list of all of the account's comparisons.getComparison(String identifier) Synchronously gets metadata for a given comparison.getComparisonAsync(String identifier) Asynchronously gets metadata for a given comparison.Gets an existing exportpublicViewerURL(String identifier) publicViewerURL(String identifier, boolean wait) signedViewerURL(String identifier) signedViewerURL(String identifier, Duration validUntil, boolean wait) signedViewerURL(String identifier, Instant validUntil, boolean wait)
-
Field Details
-
defaultApiBase
- See Also:
-
-
Constructor Details
-
Comparisons
Constructs aComparisonsinstance for the given credentials, which can then be used to make API requests.- Parameters:
accountId- The account ID to make requests for. This is located in your account console.authToken- The auth token for the account. This is located in your account console.
-
Comparisons
public Comparisons(@Nonnull String accountId, @Nonnull String authToken, @Nullable String apiBaseUrl) Constructs aComparisonsinstance for the given credentials and apiBaseUrl, which can then be used to make API requests.- Parameters:
accountId- The account ID to make requests for. This is located in your account console.authToken- The auth token for the account. This is located in your account console.apiBaseUrl- The base API URL. If null, use the default Draftable cloud API URL. The URL must have the protocol (e.g. "https") and end in "v1" with no trailing slash, e.g. "https://api.draftable.com/v1"
-
-
Method Details
-
close
Closes any open inner HTTP clients, and ends any async event loops.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- An error occurred closing an HTTP client.
-
getExport
@Nonnull public Export getExport(@Nonnull String identifier) throws Comparisons.ComparisonNotFoundException, IOException, Comparisons.InvalidAuthenticationException, Comparisons.UnknownErrorException Gets an existing export- Parameters:
identifier- Export identifier (note that this is different from comparison identifier).- Returns:
- The object giving metadata about the existing export.
- Throws:
Comparisons.ComparisonNotFoundExceptionIOExceptionComparisons.InvalidAuthenticationExceptionComparisons.UnknownErrorException
-
createExport
@Nonnull public Export createExport(@Nonnull String comparisonId, @Nonnull ExportKind exportKind, boolean includeCoverPage) throws Comparisons.BadRequestException, IOException, Comparisons.InvalidAuthenticationException, Comparisons.UnknownErrorException Creates a new export of given kind for given comparison- Parameters:
comparisonId- The unique identifier of the comparison to exportexportKind- Export kind. Supported values: single_page, combined, left, right.includeCoverPage- Relevant only for combined comparison, indicates whether it should include a cover page- Returns:
- The object giving metadata about the newly created export.
- Throws:
Comparisons.BadRequestExceptionIOExceptionComparisons.InvalidAuthenticationExceptionComparisons.UnknownErrorException
-
createExport
@Nonnull public Export createExport(@Nonnull String comparisonId, @Nonnull ExportKind exportKind) throws Comparisons.BadRequestException, IOException, Comparisons.InvalidAuthenticationException, Comparisons.UnknownErrorException -
getAllComparisons
@Nonnull public List<Comparison> getAllComparisons() throws IOException, Comparisons.InvalidAuthenticationException, Comparisons.UnknownErrorExceptionSynchronously gets a list of all of the account's comparisons.- Returns:
- A
List<Comparison>giving all of the account's comparisons. - Throws:
IOException- If an error occurs communicating with the server.Comparisons.InvalidAuthenticationException- If the given auth token is invalid.Comparisons.UnknownErrorException- If an unknown error occurs internally. This should never be thrown, but guarantees that no other kinds of exceptions are thrown.
-
getAllComparisonsAsync
Asynchronously gets a list of all of the account's comparisons.- Returns:
- A
CompletableFuture<List<Comparison>>that will complete with a list all of the account's comparisons, or with one of the exceptions documented ingetAllComparisons().
-
getComparison
@Nonnull public Comparison getComparison(@Nonnull String identifier) throws Comparisons.ComparisonNotFoundException, IOException, Comparisons.InvalidAuthenticationException, Comparisons.UnknownErrorException Synchronously gets metadata for a given comparison.- Parameters:
identifier- The comparison's identifier.- Returns:
- A
Comparisongiving the comparison's metadata. - Throws:
Comparisons.ComparisonNotFoundException- If no comparison with the given identifier exists.IOException- If an error occurs communicating with the server.Comparisons.InvalidAuthenticationException- If the given auth token is invalid.Comparisons.UnknownErrorException- If an unknown error occurs internally. This should never be thrown, but guarantees that no other kinds of exceptions are thrown.
-
getComparisonAsync
Asynchronously gets metadata for a given comparison.- Parameters:
identifier- The comparison's identifier.- Returns:
- A
CompletableFuture<Comparison>that will complete with aComparisongiving the metadata, or with one of the exceptions documented ingetComparison(java.lang.String).
-
deleteComparison
public void deleteComparison(@Nonnull String identifier) throws Comparisons.ComparisonNotFoundException, IOException, Comparisons.InvalidAuthenticationException, Comparisons.UnknownErrorException Synchronously deletes a given comparison.- Parameters:
identifier- The comparison's identifier.- Throws:
Comparisons.ComparisonNotFoundException- If no comparison with the given identifier exists.IOException- If an error occurs communicating with the server.Comparisons.InvalidAuthenticationException- If the given auth token is invalid.Comparisons.UnknownErrorException- If an unknown error occurs internally. This should never be thrown, but guarantees that no other kinds of exceptions are thrown.
-
deleteComparisonAsync
Asynchronously deletes a given comparison.- Parameters:
identifier- The comparison's identifier.- Returns:
- A
CompletableFuturethat will complete withVoidif the comparison is successfully deleted, or with one of the exceptions documented indeleteComparison(java.lang.String).
-
createComparison
@Nonnull public Comparison createComparison(@Nonnull Comparisons.Side left, @Nonnull Comparisons.Side right) throws IOException, Comparisons.InvalidAuthenticationException, Comparisons.UnknownErrorException Synchronously creates a *private* comparison that never expires with the given sides and an automatically generated identifier.- Parameters:
left- AComparisons.Siderepresenting the left file.right- AComparisons.Siderepresenting the right file.- Returns:
- A
Comparisoninstance representing the newly created comparison. - Throws:
IOException- If an error occurs communicating with the server.Comparisons.InvalidAuthenticationException- If the given auth token is invalid.Comparisons.UnknownErrorException- If an unknown error occurs internally. This should never be thrown, but guarantees that no other kinds of exceptions are thrown.
-
createComparison
@Nonnull public Comparison createComparison(@Nonnull Comparisons.Side left, @Nonnull Comparisons.Side right, @Nullable String identifier, boolean isPublic, @Nullable Instant expires) throws Comparisons.BadRequestException, IOException, Comparisons.InvalidAuthenticationException, Comparisons.UnknownErrorException Synchronously creates a comparison with the given sides and properties.- Parameters:
left- AComparisons.Siderepresenting the left file.right- AComparisons.Siderepresenting the right file.identifier- The identifier to use, or null to use an automatically generated one. If you provide an identifier that clashes with an existing comparison, aComparisons.BadRequestExceptionis thrown.isPublic- Whether the comparison is publicly accessible, or requires authentication to view.expires- AnInstantat which the comparison will expire and be automatically deleted, or null for no expiry. If provided, the expiry time must be in the future.- Returns:
- A
Comparisoninstance representing the newly created comparison. - Throws:
Comparisons.BadRequestException- If you provide an identifier that is already in use, or other invalid information.IOException- If an error occurs communicating with the server.Comparisons.InvalidAuthenticationException- If the given auth token is invalid.Comparisons.UnknownErrorException- If an unknown error occurs internally. This should never be thrown, but guarantees that no other kinds of exceptions are thrown.
-
createComparisonAsync
@Nonnull public CompletableFuture<Comparison> createComparisonAsync(@Nonnull Comparisons.Side left, @Nonnull Comparisons.Side right) Asynchronously creates a *private* comparison that never expires with the given sides and an automatically generated identifier.- Parameters:
left- AComparisons.Siderepresenting the left file.right- AComparisons.Siderepresenting the right file.- Returns:
- A
CompletableFuture<Comparison>that will complete with the newly created comparison, or an exception as documented increateComparison(Side, Side).
-
createComparisonAsync
@Nonnull public CompletableFuture<Comparison> createComparisonAsync(@Nonnull Comparisons.Side left, @Nonnull Comparisons.Side right, @Nullable String identifier, boolean isPublic, @Nullable Instant expires) Asynchronously creates a comparison with the given sides and properties.- Parameters:
left- AComparisons.Siderepresenting the left file.right- AComparisons.Siderepresenting the right file.identifier- The identifier to use, or null to use an automatically generated one. If you provide an identifier that clashes with an existing comparison, aComparisons.BadRequestExceptionis thrown.isPublic- Whether the comparison is publicly accessible, or requires authentication to view.expires- AnInstantat which the comparison will expire and be automatically deleted, or null for no expiry. If provided, the expiry time must be in the future.- Returns:
- A
CompletableFuture<Comparison>that will complete with the newly created comparison, or an exception as documented increateComparison(Side, Side, String, boolean, Instant).
-
publicViewerURL
-
publicViewerURL
-
signedViewerURL
-
signedViewerURL
-
signedViewerURL
-
generateIdentifier
-