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

Commit f2b155c2 authored by Md.Hasib Prince's avatar Md.Hasib Prince Committed by Hasib Prince
Browse files

App Lounge: Exodus tracker api integrated

parent 3093c3f2
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
package foundation.e.apps.api

import retrofit2.Response

suspend fun <T> getResult(apiCall: suspend () -> Response<T>): Result<T> {
    return try {
        fetchResult(apiCall())
    } catch (e: Exception) {
        Result.error(e.message ?: e.toString())
    }
}

private fun <T> fetchResult(response: Response<T>): Result<T> {
    if (response.isSuccessful) {
        response.body()?.let {
            return Result.success(it)
        }
    }

    return Result.error(response.message(), response.body())
}
+47 −0
Original line number Diff line number Diff line
package foundation.e.apps.api

data class Result<T>(val status: Status, val data: T?, val message: String?) {

    enum class Status {
        SUCCESS,
        ERROR,
        LOADING
    }

    companion object {
        fun <T> success(data: T): Result<T> {
            return Result(
                Status.SUCCESS,
                data,
                null
            )
        }

        fun <T> error(message: String, data: T? = null): Result<T> {
            return Result(
                Status.ERROR,
                data,
                message
            )
        }

        fun <T> loading(data: T? = null): Result<T> {
            return Result(
                Status.LOADING,
                data,
                null
            )
        }
    }

    fun isSuccess() = status == Status.SUCCESS

    fun handleResult(handler: () -> Unit, defaultErrorData: T?) : T? {
        if(isSuccess()) {
            handler()
            return data ?: defaultErrorData
        }
        return defaultErrorData
    }
}
+15 −0
Original line number Diff line number Diff line
package foundation.e.apps.api.exodus

import retrofit2.Response
import retrofit2.http.GET

interface ExodusTrackerApi {

    companion object {
        const val BASE_URL = "https://exodus.ecloud.global/api/"
        const val VERSION = "190239"
    }

    @GET("trackers?v=$VERSION")
    suspend fun getTrackerList(): Response<Trackers>
}
 No newline at end of file
+25 −0
Original line number Diff line number Diff line
package foundation.e.apps.api.exodus

data class Trackers (
    val trackers: Map<String, Tracker>
)

data class Tracker (
    val id: Long,
    val name: String,
    val description: String,
    val creationDate: String,
    val codeSignature: String,
    val networkSignature: String,
    val website: String,
    val categories: List<Category>
)

enum class Category {
    Advertisement,
    Analytics,
    CrashReporting,
    Identification,
    Location,
    Profiling
}
 No newline at end of file
+5 −0
Original line number Diff line number Diff line
package foundation.e.apps.api.exodus.repositories

interface ITrackerRepository {
    suspend fun getTrackerList(): Result<Boolean>
}
 No newline at end of file
Loading