Skip to content

Commit

Permalink
Add check from URL status.
Browse files Browse the repository at this point in the history
Add check document and video conversion statuses.
  • Loading branch information
CheK539 committed Dec 13, 2023
1 parent 612aa9b commit 665a485
Show file tree
Hide file tree
Showing 5 changed files with 292 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
156 changes: 156 additions & 0 deletions documentation/LIBRARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@
* [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)
* [Create webhook](#create-webhook-api-reference)
* [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)
Expand All @@ -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
Expand Down Expand Up @@ -866,6 +870,57 @@ DocumentConverter converter = new DocumentConverter(uploadcare, conversionJobs);
List<UploadcareFile> 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.
Expand Down Expand Up @@ -959,6 +1014,57 @@ VideoConverter converter = new VideoConverter(uploadcare, conversionJobs);
List<UploadcareFile> 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.
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<String>,
jsonpCallback: String? = null,
signature: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -57,3 +59,7 @@ interface UploadcareWebhooksCallback : BaseListCallback<UploadcareWebhook>
interface UploadcareMetadataCallback : BaseCallback<Map<String, String>>

interface UploadcareMetadataKeyValueCallback : BaseCallback<String>

interface UploadFromUrlStatusCallback : BaseCallback<UploadFromUrlStatusData>

interface ConversionStatusCallback : BaseCallback<ConvertStatusData>
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 665a485

Please sign in to comment.