From daf96024de3f2c3981350562bcd6a5628f308c6c Mon Sep 17 00:00:00 2001 From: Alexander Baltser Date: Mon, 22 Jun 2020 18:47:13 +0300 Subject: [PATCH 1/2] Add the video status endpoint --- .../java/com/vimeo/networking2/VideoStatus.kt | 43 +++++++++++++++++++ .../vimeo/networking2/enums/VideoStateType.kt | 39 +++++++++++++++++ .../java/com/vimeo/networking2/ModelsTest.kt | 3 +- .../com/vimeo/networking2/enums/EnumsTest.kt | 3 +- .../com/vimeo/networking/VimeoService.java | 7 +++ .../networking/callers/GetRequestCaller.java | 21 +++++++++ 6 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 models/src/main/java/com/vimeo/networking2/VideoStatus.kt create mode 100644 models/src/main/java/com/vimeo/networking2/enums/VideoStateType.kt diff --git a/models/src/main/java/com/vimeo/networking2/VideoStatus.kt b/models/src/main/java/com/vimeo/networking2/VideoStatus.kt new file mode 100644 index 000000000..86b365fe6 --- /dev/null +++ b/models/src/main/java/com/vimeo/networking2/VideoStatus.kt @@ -0,0 +1,43 @@ +package com.vimeo.networking2 + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass +import com.vimeo.networking2.enums.VideoStateType +import com.vimeo.networking2.enums.asEnum +import java.io.Serializable + +/** + * The current status of the video transcoding process. + */ +@JsonClass(generateAdapter = true) +data class VideoStatus( + /** + * The current state of the transcoding process. + */ + @Json(name = "state") + val state: String? = null, + + /** + * The percentage of the transcoding process that is complete. + */ + @Json(name = "progress") + val progress: Int? = 0, + + /** + * The remaining time in seconds before transcoding is complete. + */ + @Json(name = "time_left") + val timeLeft: Long? = 0 +) : Serializable { + + companion object { + private const val serialVersionUID = -72138L + } +} + +/** + * @see VideoStatus.state + * @see VideoStateType + */ +val VideoStatus.videoStateType: VideoStateType + get() = state.asEnum(VideoStateType.UNKNOWN) diff --git a/models/src/main/java/com/vimeo/networking2/enums/VideoStateType.kt b/models/src/main/java/com/vimeo/networking2/enums/VideoStateType.kt new file mode 100644 index 000000000..2d2d61d97 --- /dev/null +++ b/models/src/main/java/com/vimeo/networking2/enums/VideoStateType.kt @@ -0,0 +1,39 @@ +package com.vimeo.networking2.enums + +/** + * Video transcoding states. + */ +enum class VideoStateType(override val value: String?): StringValue { + + ACTIVE("active"), + + BLOCKED("blocked"), + + EXCEEDS_QUOTA("exceeds_quota"), + + EXCEEDS_TOTAL_CAP("exceeds_total_cap"), + + FAILED("failed"), + + FINISHING("finishing"), + + INTERNAL_ERROR("internal_error"), + + INVALID_FILE("invalid_file"), + + PENDING("pending"), + + READY("ready"), + + RETRIEVED("retrieved"), + + STANDBY("standby"), + + STARTING("starting"), + + UPLOAD_COMPLETE("upload_complete"), + + UPLOAD_INCOMPLETE("upload_incomplete"), + + UNKNOWN("unknown") +} diff --git a/models/src/test/java/com/vimeo/networking2/ModelsTest.kt b/models/src/test/java/com/vimeo/networking2/ModelsTest.kt index 813dd10b3..4f15b521a 100644 --- a/models/src/test/java/com/vimeo/networking2/ModelsTest.kt +++ b/models/src/test/java/com/vimeo/networking2/ModelsTest.kt @@ -153,7 +153,8 @@ class ModelsTest { VimeoAccount::class, WatchedInteraction::class, WatchLaterInteraction::class, - Website::class + Website::class, + VideoStatus::class ) @Test diff --git a/models/src/test/java/com/vimeo/networking2/enums/EnumsTest.kt b/models/src/test/java/com/vimeo/networking2/enums/EnumsTest.kt index 2959637f9..1b09e5386 100644 --- a/models/src/test/java/com/vimeo/networking2/enums/EnumsTest.kt +++ b/models/src/test/java/com/vimeo/networking2/enums/EnumsTest.kt @@ -51,7 +51,8 @@ class EnumsTest { VideoQualityType::class.java, VideoSourceType::class.java, VideoStatusType::class.java, - ViewPrivacyType::class.java + ViewPrivacyType::class.java, + VideoStateType::class.java ) @Test diff --git a/vimeo-networking/src/main/java/com/vimeo/networking/VimeoService.java b/vimeo-networking/src/main/java/com/vimeo/networking/VimeoService.java index c50ef16cb..039aad71b 100644 --- a/vimeo-networking/src/main/java/com/vimeo/networking/VimeoService.java +++ b/vimeo-networking/src/main/java/com/vimeo/networking/VimeoService.java @@ -51,6 +51,7 @@ import com.vimeo.networking2.UserList; import com.vimeo.networking2.Video; import com.vimeo.networking2.VideoList; +import com.vimeo.networking2.VideoStatus; import com.vimeo.networking2.VimeoAccount; import com.vimeo.networking2.params.BatchPublishToSocialMedia; import com.vimeo.networking2.PublishJob; @@ -465,6 +466,12 @@ Call getAlbumList(@Header("Authorization") String authHeader, @GET("products") Call getProducts(@Header("Authorization") String authHeader); + + @GET + Call getVideoStatus(@Header("Authorization") String authHeader, + @Url String uri, + @QueryMap Map options, + @Header("Cache-Control") String cacheHeaderValue); // @PUT diff --git a/vimeo-networking/src/main/java/com/vimeo/networking/callers/GetRequestCaller.java b/vimeo-networking/src/main/java/com/vimeo/networking/callers/GetRequestCaller.java index 62d6e2b4c..2ab765962 100644 --- a/vimeo-networking/src/main/java/com/vimeo/networking/callers/GetRequestCaller.java +++ b/vimeo-networking/src/main/java/com/vimeo/networking/callers/GetRequestCaller.java @@ -51,6 +51,7 @@ import com.vimeo.networking2.UserList; import com.vimeo.networking2.Video; import com.vimeo.networking2.VideoList; +import com.vimeo.networking2.VideoStatus; import org.jetbrains.annotations.NotNull; @@ -552,6 +553,26 @@ public Call call(@NotNull String authHeader, } }; + /** + * Used in association with + * {@link VimeoClient#getContent(String, CacheControl, Caller, String, Map, String, VimeoCallback)} or + * {@link VimeoClient#getContentSync(String, CacheControl, String, Map, String, Caller)} + * to get a {@link VideoStatus} response from an API endpoint. + */ + public static final Caller VIDEO_STATUS = + new Caller() { + + @NotNull + @Override + public Call call(@NotNull String authHeader, + @NotNull String uri, + @NotNull Map queryMap, + @NotNull String cacheHeader, + @NotNull VimeoService vimeoService) { + return vimeoService.getVideoStatus(authHeader, uri, queryMap, cacheHeader); + } + }; + private GetRequestCaller() {} } From d3f77da7329dddba4a57f05c6b5a3fc6a8edd45d Mon Sep 17 00:00:00 2001 From: Alexander Baltser Date: Tue, 23 Jun 2020 18:41:21 +0300 Subject: [PATCH 2/2] Fix the review comments --- models/src/main/java/com/vimeo/networking2/VideoStatus.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/src/main/java/com/vimeo/networking2/VideoStatus.kt b/models/src/main/java/com/vimeo/networking2/VideoStatus.kt index 86b365fe6..4549d9bb6 100644 --- a/models/src/main/java/com/vimeo/networking2/VideoStatus.kt +++ b/models/src/main/java/com/vimeo/networking2/VideoStatus.kt @@ -21,13 +21,13 @@ data class VideoStatus( * The percentage of the transcoding process that is complete. */ @Json(name = "progress") - val progress: Int? = 0, + val progress: Int? = null, /** * The remaining time in seconds before transcoding is complete. */ @Json(name = "time_left") - val timeLeft: Long? = 0 + val timeLeft: Long? = null ) : Serializable { companion object {