Skip to content

Commit

Permalink
CXAN-187 Add chapters models and endpoint (#626)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexander Baltser <[email protected]>
  • Loading branch information
abalcer-ls and Alexander Baltser authored Aug 3, 2023
1 parent 07a5971 commit f2a5c8d
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ object ApiConstants {
const val ENDPOINT_TERMS_OF_SERVICE = "documents/termsofservice"
const val ENDPOINT_PRIVACY_POLICY = "documents/privacy"
const val ENDPOINT_PAYMENT_ADDENDUM = "documents/paymentaddendum"
const val ENDPOINT_CHAPTERS = "/chapters"
}

/**
Expand Down
24 changes: 24 additions & 0 deletions models/src/main/java/com/vimeo/networking2/Chapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.vimeo.networking2

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

/**
* Chapter data.
*
* @param uri The relative URI of the chapter.
* @param title The title of the chapter.
* @param timeCode The timecode of the chapter in seconds from the start of the video.
*/
@JsonClass(generateAdapter = true)
data class Chapter(

@Json(name = "uri")
val uri: String? = null,

@Json(name = "title")
val title: String? = null,

@Json(name = "timecode")
val timeCode: Long? = null
)
21 changes: 21 additions & 0 deletions models/src/main/java/com/vimeo/networking2/ChapterList.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.vimeo.networking2

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import com.vimeo.networking2.common.Page

/**
* List of chapters that are pageable.
*/
@JsonClass(generateAdapter = true)
data class ChapterList(

@Json(name = "total")
override val total: Int? = null,

@Json(name = "filtered_total")
override val filteredTotal: Int? = null,

@Json(name = "data")
override val data: List<Chapter>? = null
) : Page<Chapter>
6 changes: 5 additions & 1 deletion models/src/main/java/com/vimeo/networking2/Video.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import java.util.Date
* @param user The video owner.
* @param width The video's width in pixels.
* @param app the video app info.
* @param hasChapters Whether the video has chapters.
*/
@JsonClass(generateAdapter = true)
data class Video(
Expand Down Expand Up @@ -181,7 +182,10 @@ data class Video(
val width: Int? = null,

@Json(name = "app")
val app: App? = null
val app: App? = null,

@Json(name = "has_chapters")
val hasChapters: Boolean? = null

) : Entity, VideoContainer<Video> {

Expand Down
10 changes: 10 additions & 0 deletions request/src/main/java/com/vimeo/networking2/VimeoApiClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2527,6 +2527,16 @@ interface VimeoApiClient {
*/
fun getCustomDomains(email: String, callback: VimeoCallback<CustomDomains>): VimeoRequest

/**
* Get chapters for a video.
*
* @param uri The uri of the endpoint.
* @param callback The callback which will be notified of the request completion.
* @param cacheControl The optional cache behavior for the request, null indicates that the default cache behavior
* should be used.
*/
fun getVideoChapters(uri: String, callback: VimeoCallback<ChapterList>, cacheControl: CacheControl?): VimeoRequest

companion object {

private val delegate: MutableVimeoApiClientDelegate = MutableVimeoApiClientDelegate()
Expand Down
8 changes: 8 additions & 0 deletions request/src/main/java/com/vimeo/networking2/VimeoService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,14 @@ internal interface VimeoService {
@Field(EMAIL) email: String
): VimeoCall<CustomDomains>

@GET
fun getVideoChapters(
@Header(AUTHORIZATION) authorization: String,
@Url uri: String,
@QueryMap queryParams: Map<String, @JvmSuppressWildcards String>,
@Header(CACHE_CONTROL) cacheControl: CacheControl?
): VimeoCall<ChapterList>

companion object {
private const val CACHE_CONTROL = "Cache-Control"
private const val AUTHORIZATION = "Authorization"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.vimeo.networking2.Category
import com.vimeo.networking2.CategoryList
import com.vimeo.networking2.Channel
import com.vimeo.networking2.ChannelList
import com.vimeo.networking2.ChapterList
import com.vimeo.networking2.Comment
import com.vimeo.networking2.CommentList
import com.vimeo.networking2.ConnectedApp
Expand Down Expand Up @@ -1135,4 +1136,10 @@ internal class MutableVimeoApiClientDelegate(var actual: VimeoApiClient? = null)

override fun getCustomDomains(email: String, callback: VimeoCallback<CustomDomains>): VimeoRequest =
client.getCustomDomains(email, callback)

override fun getVideoChapters(
uri: String,
callback: VimeoCallback<ChapterList>,
cacheControl: CacheControl?
): VimeoRequest = client.getVideoChapters(uri, callback, cacheControl)
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import com.vimeo.networking2.Category
import com.vimeo.networking2.CategoryList
import com.vimeo.networking2.Channel
import com.vimeo.networking2.ChannelList
import com.vimeo.networking2.ChapterList
import com.vimeo.networking2.Comment
import com.vimeo.networking2.CommentList
import com.vimeo.networking2.ConnectedApp
Expand Down Expand Up @@ -1836,6 +1837,15 @@ internal class VimeoApiClientImpl(
return vimeoService.getCustomDomains(authHeader, email).enqueue(callback)
}

override fun getVideoChapters(
uri: String,
callback: VimeoCallback<ChapterList>,
cacheControl: CacheControl?
): VimeoRequest {
val safeUrl = uri.validate() ?: return localVimeoCallAdapter.enqueueInvalidUri(callback)
return vimeoService.getVideoChapters(authHeader, safeUrl, emptyMap(), cacheControl).enqueue(callback)
}

private fun <T> LocalVimeoCallAdapter.enqueueInvalidUri(callback: VimeoCallback<T>): VimeoRequest {
return enqueueError(
ApiError(
Expand Down

0 comments on commit f2a5c8d

Please sign in to comment.