Skip to content

Commit 5f7ca13

Browse files
committed
Introduce new link api and bring back old link api
1 parent e35cbef commit 5f7ca13

9 files changed

Lines changed: 89 additions & 33 deletions

File tree

library/src/main/kotlin/me/proxer/library/api/anime/AnimeApi.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,11 @@ class AnimeApi internal constructor(retrofit: Retrofit) {
2525
fun link(streamId: String): LinkEndpoint {
2626
return LinkEndpoint(internalApi, streamId)
2727
}
28+
29+
/**
30+
* Returns the respective endpoint.
31+
*/
32+
fun vastLink(streamId: String): VastLinkEndpoint {
33+
return VastLinkEndpoint(internalApi, streamId)
34+
}
2835
}

library/src/main/kotlin/me/proxer/library/api/anime/InternalApi.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@ internal interface InternalApi {
2727
@Query("language") language: AnimeLanguage?
2828
): ProxerCall<List<Stream>>
2929

30-
@GET("anime/link2")
30+
@GET("anime/link")
3131
fun link(
32-
@Query("id") id: String?,
33-
@Query("adFlag") adFlag: Int?
32+
@Query("id") id: String?
33+
): ProxerCall<String>
34+
35+
@GET("anime/linkvast")
36+
fun vastLink(
37+
@Query("id") id: String?
3438
): ProxerCall<LinkContainer>
3539
}

library/src/main/kotlin/me/proxer/library/api/anime/LinkEndpoint.kt

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package me.proxer.library.api.anime
22

33
import me.proxer.library.ProxerCall
44
import me.proxer.library.api.Endpoint
5-
import me.proxer.library.entity.anime.LinkContainer
6-
import me.proxer.library.internal.util.toIntOrNull
75

86
/**
97
* Endpoint for retrieving the link to the uploaded anime. This may be null, if the link is broken or has been deleted.
@@ -15,19 +13,9 @@ import me.proxer.library.internal.util.toIntOrNull
1513
class LinkEndpoint internal constructor(
1614
private val internalApi: InternalApi,
1715
private val id: String
18-
) : Endpoint<LinkContainer> {
16+
) : Endpoint<String> {
1917

20-
private var enableAds: Boolean? = null
21-
22-
/**
23-
* Sets if the ad system of Proxer is supported and should be enabled.
24-
* Requires a special permission from the administration.
25-
*/
26-
fun enableAds(enableAds: Boolean? = false) = this.apply {
27-
this.enableAds = enableAds
28-
}
29-
30-
override fun build(): ProxerCall<LinkContainer> {
31-
return internalApi.link(id, enableAds.toIntOrNull())
18+
override fun build(): ProxerCall<String> {
19+
return internalApi.link(id)
3220
}
3321
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package me.proxer.library.api.anime
2+
3+
import me.proxer.library.ProxerCall
4+
import me.proxer.library.api.Endpoint
5+
import me.proxer.library.entity.anime.LinkContainer
6+
7+
/**
8+
* Endpoint similar to [LinkEndpoint], but additionally returns a VAST ad tag. This requires the highest authorization
9+
* level and should only be used by official applications.
10+
*
11+
* @author Ruben Gees
12+
*/
13+
class VastLinkEndpoint internal constructor(
14+
private val internalApi: InternalApi,
15+
private val id: String
16+
) : Endpoint<LinkContainer> {
17+
18+
override fun build(): ProxerCall<LinkContainer> {
19+
return internalApi.vastLink(id)
20+
}
21+
}

library/src/main/kotlin/me/proxer/library/entity/anime/LinkContainer.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ import com.squareup.moshi.JsonClass
77
* Entity representing a link to an anime.
88
*
99
* @property link The actual link. This does point to the HTML embed and not the video itself.
10-
* @property shouldShowAd If an ad should be shown for this stream. This is part of the Proxers ad system and needs
11-
* special permission to use.
10+
* @property adTag The VAST tag of the ad to show. Is empty if no ad is available or none should be shown.
1211
*/
1312
@JsonClass(generateAdapter = true)
1413
data class LinkContainer(
1514
@Json(name = "link") val link: String,
16-
@Json(name = "adFlag") val shouldShowAd: Boolean
15+
@Json(name = "adTag") val adTag: String
1716
)

library/src/test/kotlin/me/proxer/library/api/anime/LinkEndpointTest.kt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package me.proxer.library.api.anime
22

33
import me.proxer.library.ProxerTest
4-
import me.proxer.library.entity.anime.LinkContainer
54
import me.proxer.library.fromResource
65
import okhttp3.mockwebserver.MockResponse
76
import org.assertj.core.api.Assertions.assertThat
@@ -21,22 +20,17 @@ class LinkEndpointTest : ProxerTest() {
2120
.build()
2221
.execute()
2322

24-
assertThat(result).isEqualTo(buildTestLink())
23+
assertThat(result).isEqualTo("//www.dailymotion.com/embed/video/k4D1tfdhKG")
2524
}
2625

2726
@Test
2827
fun testPath() {
2928
server.enqueue(MockResponse().setBody(fromResource("link.json")))
3029

3130
api.anime.link("13")
32-
.enableAds(true)
3331
.build()
3432
.execute()
3533

36-
assertThat(server.takeRequest().path).isEqualTo("/api/v1/anime/link2?id=13&adFlag=1")
37-
}
38-
39-
private fun buildTestLink(): LinkContainer {
40-
return LinkContainer("//www.dailymotion.com/embed/video/k4D1tfdhKG", true)
34+
assertThat(server.takeRequest().path).isEqualTo("/api/v1/anime/link?id=13")
4135
}
4236
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package me.proxer.library.api.anime
2+
3+
import me.proxer.library.ProxerTest
4+
import me.proxer.library.entity.anime.LinkContainer
5+
import me.proxer.library.fromResource
6+
import okhttp3.mockwebserver.MockResponse
7+
import org.assertj.core.api.Assertions.assertThat
8+
import org.junit.jupiter.api.Test
9+
10+
class VastLinkEndpointTest : ProxerTest() {
11+
12+
@Test
13+
fun testDefault() {
14+
server.enqueue(MockResponse().setBody(fromResource("link_vast.json")))
15+
16+
val result = api.anime
17+
.vastLink("4")
18+
.build()
19+
.execute()
20+
21+
assertThat(result).isEqualTo(buildTestLinkContainer())
22+
}
23+
24+
@Test
25+
fun testPath() {
26+
server.enqueue(MockResponse().setBody(fromResource("link_vast.json")))
27+
28+
api.anime.vastLink("9")
29+
.build()
30+
.execute()
31+
32+
assertThat(server.takeRequest().path).isEqualTo("/api/v1/anime/linkvast?id=9")
33+
}
34+
35+
private fun buildTestLinkContainer(): LinkContainer {
36+
return LinkContainer("//www.dailymotion.com/embed/video/k4D1tLdhKG", "https://example.com")
37+
}
38+
}
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
{
22
"error": 0,
33
"message": "Abfrage erfolgreich",
4-
"data": {
5-
"link": "//www.dailymotion.com/embed/video/k4D1tfdhKG",
6-
"adFlag": true
7-
}
4+
"data": "//www.dailymotion.com/embed/video/k4D1tfdhKG"
85
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"error": 0,
3+
"message": "Abfrage erfolgreich",
4+
"data": {
5+
"link": "//www.dailymotion.com/embed/video/k4D1tLdhKG",
6+
"adTag": "https://example.com"
7+
}
8+
}

0 commit comments

Comments
 (0)