-
-
Notifications
You must be signed in to change notification settings - Fork 776
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
143 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 0 additions & 25 deletions
25
app/src/main/java/app/revanced/manager/domain/repository/ReVancedRepository.kt
This file was deleted.
Oops, something went wrong.
43 changes: 0 additions & 43 deletions
43
app/src/main/java/app/revanced/manager/network/api/ManagerAPI.kt
This file was deleted.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
app/src/main/java/app/revanced/manager/network/api/ReVancedAPI.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package app.revanced.manager.network.api | ||
|
||
import app.revanced.manager.domain.manager.PreferencesManager | ||
import app.revanced.manager.network.dto.Asset | ||
import app.revanced.manager.network.dto.ReVancedLatestRelease | ||
import app.revanced.manager.network.dto.ReVancedRelease | ||
import app.revanced.manager.network.service.ReVancedService | ||
import app.revanced.manager.network.utils.getOrThrow | ||
import app.revanced.manager.network.utils.transform | ||
|
||
class ReVancedAPI( | ||
private val service: ReVancedService, | ||
private val prefs: PreferencesManager | ||
) { | ||
private suspend fun apiUrl() = prefs.api.get() | ||
|
||
suspend fun getContributors() = service.getContributors(apiUrl()).transform { it.repositories } | ||
|
||
suspend fun getRelease(name: String) = service.getRelease(apiUrl(), name).transform { it.release } | ||
|
||
companion object Extensions { | ||
fun ReVancedRelease.findAssetByType(mime: String) = assets.singleOrNull { it.contentType == mime } ?: throw MissingAssetException(mime) | ||
} | ||
} | ||
|
||
class MissingAssetException(type: String) : Exception("No asset with type $type") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
app/src/main/java/app/revanced/manager/network/dto/ReVancedRelease.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package app.revanced.manager.network.dto | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ReVancedLatestRelease( | ||
val release: ReVancedRelease, | ||
) | ||
|
||
@Serializable | ||
data class ReVancedRelease( | ||
val metadata: ReVancedReleaseMeta, | ||
val assets: List<Asset> | ||
) | ||
|
||
@Serializable | ||
data class ReVancedReleaseMeta( | ||
@SerialName("tag_name") val tag: String, | ||
val name: String, | ||
val draft: Boolean, | ||
val prerelease: Boolean, | ||
@SerialName("created_at") val createdAt: String, | ||
@SerialName("published_at") val publishedAt: String | ||
) | ||
|
||
@Serializable | ||
data class Asset( | ||
val name: String, | ||
@SerialName("browser_download_url") val downloadUrl: String, | ||
@SerialName("content_type") val contentType: String | ||
) |
20 changes: 0 additions & 20 deletions
20
app/src/main/java/app/revanced/manager/network/dto/ReVancedReleases.kt
This file was deleted.
Oops, something went wrong.
20 changes: 7 additions & 13 deletions
20
app/src/main/java/app/revanced/manager/network/service/ReVancedService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,26 @@ | ||
package app.revanced.manager.network.service | ||
|
||
import app.revanced.manager.network.api.MissingAssetException | ||
import app.revanced.manager.network.dto.Asset | ||
import app.revanced.manager.network.dto.ReVancedReleases | ||
import app.revanced.manager.network.dto.ReVancedRepositories | ||
import app.revanced.manager.network.dto.ReVancedLatestRelease | ||
import app.revanced.manager.network.dto.ReVancedGitRepositories | ||
import app.revanced.manager.network.utils.APIResponse | ||
import app.revanced.manager.network.utils.getOrThrow | ||
import io.ktor.client.request.* | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
|
||
class ReVancedService( | ||
private val client: HttpService, | ||
) { | ||
suspend fun getAssets(api: String): APIResponse<ReVancedReleases> { | ||
return withContext(Dispatchers.IO) { | ||
suspend fun getRelease(api: String, repo: String): APIResponse<ReVancedLatestRelease> = | ||
withContext(Dispatchers.IO) { | ||
client.request { | ||
url("$api/tools") | ||
url("$api/v2/$repo/releases/latest") | ||
} | ||
} | ||
} | ||
|
||
suspend fun getContributors(api: String): APIResponse<ReVancedRepositories> { | ||
return withContext(Dispatchers.IO) { | ||
suspend fun getContributors(api: String): APIResponse<ReVancedGitRepositories> = | ||
withContext(Dispatchers.IO) { | ||
client.request { | ||
url("$api/contributors") | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.