Created
July 4, 2019 21:52
-
-
Save leocruzdev/6a72d85be381470f24b8763cf8ca8677 to your computer and use it in GitHub Desktop.
remotedatasource
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
package com.dacruzl2.gitmvpkoin.data.source.remote | |
import com.dacruzl2.gitmvpkoin.data.Root | |
import com.dacruzl2.gitmvpkoin.data.source.GithubDataSource | |
import com.dacruzl2.gitmvpkoin.data.source.remote.services.GithubService | |
import kotlinx.coroutines.Dispatchers | |
import kotlinx.coroutines.withContext | |
import java.lang.Exception | |
class IssuesRemoteDataSource(private val remoteSource: GithubService) : GithubDataSource { | |
override suspend fun getIssues(onSuccess: (repos: List<Root>) -> Unit) = withContext(Dispatchers.IO) { | |
try { | |
val request = remoteSource.getIssues().await() | |
if (request.isSuccessful) { | |
withContext(Dispatchers.Main) { | |
val issuesList = request.body()!! | |
onSuccess(issuesList) | |
} | |
} else {} | |
} catch (t: Exception) {} | |
} | |
override suspend fun saveIssues(issues: List<Root>) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment