From 665a4855482ffe4ebd0550dacc5be163cf6b5ea5 Mon Sep 17 00:00:00 2001 From: CheK539 Date: Wed, 13 Dec 2023 16:29:43 +0500 Subject: [PATCH] Add check from URL status. Add check document and video conversion statuses. --- CHANGELOG.md | 3 + documentation/LIBRARY.md | 156 ++++++++++++++++++ .../android/library/api/UploadcareClient.kt | 125 ++++++++++++++ .../android/library/callbacks/Callbacks.kt | 6 + .../android/library/data/ConvertData.kt | 4 +- 5 files changed, 292 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa6aca7..9a636e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ **Library changes:** - Added file metadata [features](https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/File-metadata). - Added delete group [method](https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/Group/operation/deleteGroup). +- Added check from URL status [method](https://uploadcare.com/api-refs/upload-api/#tag/Upload/operation/fromURLUploadStatus). +- Added check document conversion status [method](https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/Conversion/operation/documentConvert). +- Added check video conversion status [method](https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/Conversion/operation/videoConvertStatus). ## 4.0.0 diff --git a/documentation/LIBRARY.md b/documentation/LIBRARY.md index 2b67341..dbb13d7 100644 --- a/documentation/LIBRARY.md +++ b/documentation/LIBRARY.md @@ -11,6 +11,7 @@ * [Copy file to remote storage](#copy-file-to-remote-storage-api-reference) * [List of groups](#list-of-groups-api-reference) * [Group info](#group-info-api-reference) +* [Delete group](#delete-group-api-reference) * [Store group](#store-group-api-reference) * [Project info](#project-info-api-reference) * [List of webhooks](#list-of-webhooks-api-reference) @@ -18,7 +19,9 @@ * [Update webhook](#update-webhook-api-reference) * [Delete webhook](#delete-webhook-api-reference) * [Convert documents](#convert-documents-api-reference) +* [Check document conversion status](#check-document-conversion-status-api-reference) * [Convert videos](#convert-videos-api-reference) +* [Check video conversion status](#check-video-conversion-status-api-reference) * [Content delivery](#content-delivery-reference) * [Secure Content delivery](#secure-content-delivery-reference) * [Execute AWS Rekognition](#execute-aws-rekognition-api-reference) @@ -35,6 +38,7 @@ * [Initialization Upload](#initialization-upload) * [Upload File](#upload-file-api-reference) * [Upload File from URL](#upload-file-url-api-reference) +* [Check upload File from URL Status](#check-upload-file-from-url-status-api-reference) * [Create file group](#create-files-group-api-reference) ## Initialization @@ -866,6 +870,57 @@ DocumentConverter converter = new DocumentConverter(uploadcare, conversionJobs); List result = converter.convert(); ``` +## Check document conversion status ([API Reference](https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/Conversion/operation/documentConvertStatus)) ## + +##### Asynchronous check document conversion status. + +Kotlin +```kotlin +uploadcare.getDocumentConversionStatusAsync( + context = context, + token = 12345678, + callback = object : ConversionStatusCallback { + override fun onFailure(e: UploadcareApiException) { + // Handle errors. + } + + override fun onSuccess(result: ConvertStatusData) { + // Successfully fetched status. + } + } +) +``` + +Java +```java +uploadcare.getDocumentConversionStatusAsync( + context, + 12345678, + new ConversionStatusCallback() { + @Override + public void onFailure(@NonNull UploadcareApiException e) { + // Handle errors. + } + + @Override + public void onSuccess(@NonNull ConvertStatusData result) { + // Successfully fetched status. + } + }); +``` + +##### Synchronous check document conversion status. + +Kotlin +```kotlin +val status = client.getDocumentConversionStatus(12345678) +``` + +Java +```java +ConvertStatusData status = uploadcare.getDocumentConversionStatus(12345678); +``` + ## Convert videos ([API Reference](https://uploadcare.com/api-refs/rest-api/v0.7.0/#operation/videoConvert)) ## ##### Asynchronous videos convert. @@ -959,6 +1014,57 @@ VideoConverter converter = new VideoConverter(uploadcare, conversionJobs); List result = converter.convert(); ``` +## Check video conversion status ([API Reference](https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/Conversion/operation/videoConvertStatus)) ## + +##### Asynchronous check video conversion status. + +Kotlin +```kotlin +uploadcare.getVideoConversionStatusAsync( + context = context, + token = 12345678, + callback = object : ConversionStatusCallback { + override fun onFailure(e: UploadcareApiException) { + // Handle errors. + } + + override fun onSuccess(result: ConvertStatusData) { + // Successfully fetched status. + } + } +) +``` + +Java +```java +uploadcare.getVideoConversionStatusAsync( + context, + 12345678, + new ConversionStatusCallback() { + @Override + public void onFailure(@NonNull UploadcareApiException e) { + // Handle errors. + } + + @Override + public void onSuccess(@NonNull ConvertStatusData result) { + // Successfully fetched status. + } + }); +``` + +##### Synchronous check video conversion status. + +Kotlin +```kotlin +val status = client.getVideoConversionStatus(12345678) +``` + +Java +```java +ConvertStatusData status = uploadcare.getVideoConversionStatus(12345678); +``` + ## Content delivery ([Reference](https://uploadcare.com/docs/delivery/cdn/)) ## ##### CDN URLs build. @@ -1746,6 +1852,56 @@ try { } ``` +## Check upload File from URL Status ([API Reference](https://uploadcare.com/api-refs/upload-api/#tag/Upload/operation/fromURLUploadStatus)) ## + +##### Asynchronous check upload file from URL status. + +Kotlin +```kotlin +uploadcare.getFromUrlStatusAsync( + context = context, + token = "YOUR_TOKEN", + callback = object : UploadFromUrlStatusCallback { + override fun onFailure(e: UploadcareApiException) { + // Handle errors. + } + + override fun onSuccess(result: UploadFromUrlStatusData) { + // Successfully fetched status. + } + }) +``` + +Java +```java +uploadcare.getFromUrlStatusAsync( + context, + "YOUR_TOKEN", + new UploadFromUrlStatusCallback() { + @Override + public void onFailure(@NonNull UploadcareApiException e) { + // Handle errors. + } + + @Override + public void onSuccess(@NonNull UploadFromUrlStatusData result) { + // Successfully fetched status. + } + }); +``` + +##### Synchronous check upload file from URL status. + +Kotlin +```kotlin +val fromUrlStatus = client.getFromUrlStatus(urlToken) +``` + +Java +```java +UploadFromUrlStatusData urlStatus = uploadcare.getFromUrlStatus("YOUR_TOKEN"); +``` + ## Create file group ([API Reference](https://uploadcare.com/api-refs/upload-api/#operation/createFilesGroup)) ## ##### Asynchronous file group create. diff --git a/library/src/main/java/com/uploadcare/android/library/api/UploadcareClient.kt b/library/src/main/java/com/uploadcare/android/library/api/UploadcareClient.kt index 841143b..fc7ba1a 100644 --- a/library/src/main/java/com/uploadcare/android/library/api/UploadcareClient.kt +++ b/library/src/main/java/com/uploadcare/android/library/api/UploadcareClient.kt @@ -6,8 +6,10 @@ import com.squareup.moshi.Types import com.uploadcare.android.library.BuildConfig import com.uploadcare.android.library.api.RequestHelper.Companion.md5 import com.uploadcare.android.library.callbacks.* +import com.uploadcare.android.library.data.ConvertStatusData import com.uploadcare.android.library.data.CopyOptionsData import com.uploadcare.android.library.data.ObjectMapper +import com.uploadcare.android.library.data.UploadFromUrlStatusData import com.uploadcare.android.library.data.WebhookOptionsData import com.uploadcare.android.library.exceptions.UploadFailureException import com.uploadcare.android.library.exceptions.UploadcareApiException @@ -1123,6 +1125,129 @@ class UploadcareClient constructor(val publicKey: String, ) } + /** + * Check the status of a task to fetch/upload a file from a URL. + * + * @param token Token that identifies a request to fetch/upload a file from a URL. + */ + fun getFromUrlStatus(token: String): UploadFromUrlStatusData { + val url = Urls.uploadFromUrlStatus(token) + + return requestHelper.executeQuery( + requestType = RequestHelper.REQUEST_GET, + url = url.toString(), + apiHeaders = false, + dataClass = UploadFromUrlStatusData::class.java + ) + } + + /** + * Check the status of a task to fetch/upload a file from a URL Asynchronously. + * + * @param context Application context. [android.content.Context] + * @param token Token that identifies a request to fetch/upload a file from a URL. + * @param callback callback [UploadFromUrlStatusCallback] with either + * a UploadFromUrlStatusData response or a failure exception. + */ + fun getFromUrlStatusAsync( + context: Context, + token: String, + callback: UploadFromUrlStatusCallback + ) { + val url = Urls.uploadFromUrlStatus(token) + + return requestHelper.executeQueryAsync( + context = context, + requestType = RequestHelper.REQUEST_GET, + url = url.toString(), + apiHeaders = false, + dataClass = UploadFromUrlStatusData::class.java, + callback = callback + ) + } + + /** + * Check document conversion job status. + * + * @param token Job token. + */ + fun getDocumentConversionStatus(token: Int): ConvertStatusData { + val url = Urls.apiConvertDocumentStatus(token) + + return requestHelper.executeQuery( + requestType = RequestHelper.REQUEST_GET, + url = url.toString(), + apiHeaders = true, + dataClass = ConvertStatusData::class.java + ) + } + + /** + * Check document conversion job status Asynchronously. + * + * @param context Application context. [android.content.Context] + * @param token Job token. + * @param callback callback [ConversionStatusCallback] with either + * a ConvertStatusData response or a failure exception. + */ + fun getDocumentConversionStatusAsync( + context: Context, + token: Int, + callback: ConversionStatusCallback + ) { + val url = Urls.apiConvertDocumentStatus(token) + + return requestHelper.executeQueryAsync( + context = context, + requestType = RequestHelper.REQUEST_GET, + url = url.toString(), + apiHeaders = true, + dataClass = ConvertStatusData::class.java, + callback = callback + ) + } + + /** + * Check video conversion job status. + * + * @param token Job token. + */ + fun getVideoConversionStatus(token: Int): ConvertStatusData { + val url = Urls.apiConvertVideoStatus(token) + + return requestHelper.executeQuery( + requestType = RequestHelper.REQUEST_GET, + url = url.toString(), + apiHeaders = true, + dataClass = ConvertStatusData::class.java + ) + } + + /** + * Check video conversion job status Asynchronously. + * + * @param context Application context. [android.content.Context] + * @param token Job token. + * @param callback callback [ConversionStatusCallback] with either + * a ConvertStatusData response or a failure exception. + */ + fun getVideoConversionStatusAsync( + context: Context, + token: Int, + callback: ConversionStatusCallback + ) { + val url = Urls.apiConvertVideoStatus(token) + + return requestHelper.executeQueryAsync( + context = context, + requestType = RequestHelper.REQUEST_GET, + url = url.toString(), + apiHeaders = true, + dataClass = ConvertStatusData::class.java, + callback = callback + ) + } + internal fun createGroupInternal(fileIds: List, jsonpCallback: String? = null, signature: String? = null, diff --git a/library/src/main/java/com/uploadcare/android/library/callbacks/Callbacks.kt b/library/src/main/java/com/uploadcare/android/library/callbacks/Callbacks.kt index ec74562..269b3dc 100644 --- a/library/src/main/java/com/uploadcare/android/library/callbacks/Callbacks.kt +++ b/library/src/main/java/com/uploadcare/android/library/callbacks/Callbacks.kt @@ -2,6 +2,8 @@ package com.uploadcare.android.library.callbacks import androidx.annotation.NonNull import com.uploadcare.android.library.api.* +import com.uploadcare.android.library.data.ConvertStatusData +import com.uploadcare.android.library.data.UploadFromUrlStatusData import com.uploadcare.android.library.exceptions.UploadcareApiException import okhttp3.Response import java.net.URI @@ -57,3 +59,7 @@ interface UploadcareWebhooksCallback : BaseListCallback interface UploadcareMetadataCallback : BaseCallback> interface UploadcareMetadataKeyValueCallback : BaseCallback + +interface UploadFromUrlStatusCallback : BaseCallback + +interface ConversionStatusCallback : BaseCallback diff --git a/library/src/main/java/com/uploadcare/android/library/data/ConvertData.kt b/library/src/main/java/com/uploadcare/android/library/data/ConvertData.kt index 3a83b6b..734c9dd 100644 --- a/library/src/main/java/com/uploadcare/android/library/data/ConvertData.kt +++ b/library/src/main/java/com/uploadcare/android/library/data/ConvertData.kt @@ -17,9 +17,9 @@ internal data class ConvertResult( val uuid: String, val token: Int) -internal data class ConvertStatusData( +data class ConvertStatusData( val status: String, val result: ConvertStatusResultData, val error: String? = null) -internal data class ConvertStatusResultData(val uuid: String) +data class ConvertStatusResultData(val uuid: String)