Skip to content

Instantly share code, notes, and snippets.

@antonicg
Created February 4, 2018 18:26
Show Gist options
  • Save antonicg/0af9700a61cc564a83b6fcb048258ce0 to your computer and use it in GitHub Desktop.
Save antonicg/0af9700a61cc564a83b6fcb048258ce0 to your computer and use it in GitHub Desktop.
package com.antonicastejon.cryptodata.domain
import com.antonicastejon.cryptodata.model.CoinMarketCapRepository
import com.antonicastejon.cryptodata.model.Crypto
import io.reactivex.Single
/**
* Created by Antoni Castejón on 31/12/2017.
*/
const val LIMIT_CRYPTO_LIST = 20
class CryptoListInteractor(private val coinMarketCapRepository: CoinMarketCapRepository) : CryptoListUseCases {
override fun getCryptoListBy(page: Int): Single<List<CryptoViewModel>> {
return coinMarketCapRepository.getCryptoList(page, LIMIT_CRYPTO_LIST)
.map { cryptos -> cryptos.map(cryptoViewModelMapper) }
}
val cryptoViewModelMapper: (Crypto) -> CryptoViewModel = {
crypto -> CryptoViewModel(crypto.id, crypto.name, crypto.symbol, crypto.rank, crypto.priceUsd.toFloat(), crypto.priceBtc.toFloat(), crypto.percentChange24h.toFloat())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment