This file contains hidden or 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
private static String preprocessNestedAsterisks(String markdownText) { | |
// Here we treat double/single asterisks (emphasis) | |
// because nested emphasis (**for example *like* this**) | |
// is not interpreted correctly by the Bypass lib | |
String[] doubleAsteriskSplitMarkdown = markdownText.split("\\*\\*", -1); | |
int numberOfDoubleAsteriskedTokens = doubleAsteriskSplitMarkdown.length; | |
// strings surrounded by double asterisks are always on the odd array positions | |
for (int i = 1; i < numberOfDoubleAsteriskedTokens; i += 2) { |
This file contains hidden or 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 net.grandcentrix.gatewayapi.data.remote | |
internal interface GatewayApi { | |
@GET("lights/{roomId}") | |
suspend fun getLights(@Path("roomId") roomId: String): Response<Entity> | |
@GET("system") | |
suspend fun getSystemDetail(): Response<Entity> | |
This file contains hidden or 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 net.grandcentrix.gatewayapi.domain.usecase | |
internal typealias GetLightsUseCase = suspend (String) -> Either<Throwable, List<Light>> | |
internal typealias EntityConverter<T> = (Entity) -> T | |
internal fun getLightsUseCaseFactory( | |
api: GatewayApi, | |
converter: EntityConverter<List<Light>> | |
): GetLightsUseCase = { roomId: String -> | |
api.getLights(roomId) |
This file contains hidden or 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
sealed class Either<out F, out S> | |
data class Failure<out F>(val failure: F) : Either<F, Nothing>() | |
data class Success<out S>(val success: S) : Either<Nothing, S>() |
This file contains hidden or 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
class GetLightsUseCaseTest { | |
private val testEntity = TestClassesProvider.entity() | |
private val mockApi = mockk<GatewayApi>() | |
private val lights = listOf(Light(id = "1234")) | |
private val mockConverter = mockk<EntityConverter<List<Light>>> converter@{ | |
every { [email protected](testEntity) } returns lights | |
} |
This file contains hidden or 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 net.grandcentrix.gatewayapi.api | |
interface GatewayApiService { | |
suspend fun getLights(roomId: String): Either<Throwable, List<Light>> | |
suspend fun getSystemDetail(): Either<Throwable, SystemDetail> | |
companion object { | |
This file contains hidden or 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
internal class DefaultGatewayApiService( | |
val getLightsUseCase: GetLightsUseCase, | |
val getSystemDetailUseCase: GetSystemUseCase | |
) : GatewayApiService { | |
override suspend fun getLights(roomId: String): Either<Throwable, List<Light>> = | |
getLightsUseCase(roomId) | |
override suspend fun getSystemDetail(): Either<Throwable, SystemDetail> = //... | |
} |
This file contains hidden or 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
sealed class ApiError | |
data class HttpError(val code: Int, val body: String) : ApiError() | |
data class NetworkError(val throwable: Throwable) : ApiError() | |
data class UnknownApiError(val throwable: Throwable) : ApiError() |
This file contains hidden or 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
interface TmdbApi { | |
@GET("configuration") | |
suspend fun getConfiguration(): Either<ApiError, TmdbConfiguration> | |
@GET("movie/popular") | |
suspend fun getPopularMovies( | |
@Query("language") language: String, | |
@Query("page") page: Int, | |
@Query("region") region: String |
This file contains hidden or 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
private class EitherCall<R>( | |
private val delegate: Call<R>, | |
private val successType: Type | |
) : Call<Either<ApiError, R>> { | |
override fun enqueue(callback: Callback<Either<ApiError, R>>) = delegate.enqueue( | |
object : Callback<R> { | |
override fun onResponse(call: Call<R>, response: Response<R>) { | |
callback.onResponse(this@EitherCall, Response.success(response.toEither())) |
OlderNewer