Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 184e4af9 authored by Vincent Bourgmayer's avatar Vincent Bourgmayer
Browse files

feature: Add new gitlab API client method

also refactor SystemAppDefinitionApi to use const based placeholder in URL
parent a79141bb
Loading
Loading
Loading
Loading
+33 −4
Original line number Diff line number Diff line
@@ -22,17 +22,46 @@ import retrofit2.Response
import retrofit2.http.GET
import retrofit2.http.Path

/*
Those API method client must fit with gitlab releases API
https://docs.gitlab.com/ee/api/releases/#download-a-release-asset
TODO Option to consider at the end of the implementation:
Can we rename this interface into: GitlabReleaseApi ?
 */
interface SystemAppDefinitionApi {

    companion object {
        const val BASE_URL =
            "https://gitlab.e.foundation/api/v4/projects/"

        private const val PROJECT_ID_PLACEHOLDER = "projectId"
        private const val RELEASE_TYPE_PLACEHOLDER = "releaseType"
        private const val TAG_NAME_PLACEHOLDER = "gitlabTagName"

        private const val LIST_RELEASES_URL_SEGMENT =
            "{$PROJECT_ID_PLACEHOLDER}/releases"
        private const val UPDATE_INFO_BY_TAG_URL_SEGMENT =
            "{$PROJECT_ID_PLACEHOLDER}/releases/{$TAG_NAME_PLACEHOLDER}/downloads/json/{$RELEASE_TYPE_PLACEHOLDER}.json"
        private const val LATEST_UPDATE_INFO_URL_SEGMENT =
            "{$PROJECT_ID_PLACEHOLDER}/releases/permalink/latest/downloads/json/{$RELEASE_TYPE_PLACEHOLDER}.json"
    }

    @GET("{projectId}/releases/permalink/latest/downloads/json/{releaseType}.json")
    suspend fun getSystemAppUpdateInfo(
        @Path("projectId") projectId: Int,
        @Path("releaseType") releaseType: String,

    @GET(LIST_RELEASES_URL_SEGMENT)
    suspend fun getSystemAppReleases(
        @Path(PROJECT_ID_PLACEHOLDER) projectId: Int
    )//: Response<@TODO>

    @GET(UPDATE_INFO_BY_TAG_URL_SEGMENT)
    suspend fun getSystemAppUpdateInfoByTag(
        @Path(PROJECT_ID_PLACEHOLDER) projectId: Int,
        @Path(TAG_NAME_PLACEHOLDER) gitlabTagName: String,
        @Path(RELEASE_TYPE_PLACEHOLDER) releaseType: String,
    ): Response<SystemAppInfo>

    @GET(LATEST_UPDATE_INFO_URL_SEGMENT)
    suspend fun getLatestSystemAppUpdateInfo(
        @Path(PROJECT_ID_PLACEHOLDER) projectId: Int,
        @Path(RELEASE_TYPE_PLACEHOLDER) releaseType: String,
    ): Response<SystemAppInfo>
}
+1 −1
Original line number Diff line number Diff line
@@ -103,7 +103,7 @@ class SystemAppsUpdatesRepository @Inject constructor(
        val projectId =
            systemAppProjectList.find { it.packageName == packageName }?.projectId ?: return null

        val response = systemAppDefinitionApi.getSystemAppUpdateInfo(projectId, releaseType)
        val response = systemAppDefinitionApi.getLatestSystemAppUpdateInfo(projectId, releaseType)
        val systemAppInfo = response.body()

        return if (systemAppInfo == null) {