Issue #367
https://api.github.com/search/repositories?sort=stars&order=desc&q=language:javascript,java,swift,kotlin&q=created:>2019-08-21
interface Api {
@GET("https://api.github.com/search/repositories")
suspend fun getTrendingRepos(
@Query("sort") sort: String,
@Query("order") order: String,
@Query("q") qs: List<String>
): Response
}
class Repo {
fun api(): Api {
return Retrofit.Builder()
.baseUrl("https://api.github.com/")
.addConverterFactory(MoshiConverterFactory.create())
.build()
.create(Api::class.java)
}
}
class ViewModel(val repo: Repo, val dateProvider: DateProvider): ViewModel() {
val items = MutableLiveData<ArrayList<Item>>()
suspend fun load() {
try {
val order = "desc"
val sort = "star"
val formatter = SimpleDateFormat("YYYY-MM-dd")
val qs = listOf(
"language:javascript,java,swift,kotlin",
"q=created:>${formatter.format(dateProvider.yesterday)}"
)
val response = repo.api().getTrendingRepos(sort=sort, order=order, qs=qs)
this.items.value = response.items.toCollection(ArrayList())
} catch (e: Exception) {
this.items.value = arrayListOf()
}
}
}