-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a074d77
commit 6c322df
Showing
6 changed files
with
100 additions
and
2 deletions.
There are no files selected for viewing
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
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
10 changes: 10 additions & 0 deletions
10
app/src/main/kotlin/org/michaelbel/template/ktor/AppResponse.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.michaelbel.template.ktor | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class AppResponse( | ||
@SerialName("id") val id: Int, | ||
@SerialName("name") val name: String | ||
) |
26 changes: 26 additions & 0 deletions
26
app/src/main/kotlin/org/michaelbel/template/ktor/AppService.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.michaelbel.template.ktor | ||
|
||
import io.ktor.client.HttpClient | ||
import io.ktor.client.call.body | ||
import io.ktor.client.request.get | ||
import io.ktor.client.request.parameter | ||
|
||
class AppService( | ||
private val httpClient: HttpClient | ||
) { | ||
|
||
suspend fun getAppResponse( | ||
id: Int | ||
): AppResponse { | ||
return httpClient.get("route/$id") { | ||
parameter("key", "1234") | ||
}.body() | ||
} | ||
|
||
companion object { | ||
const val REQUEST_TIMEOUT_MILLIS = 10_000L | ||
const val SOCKET_TIMEOUT_SECONDS = 10_000L | ||
const val HTTP_CACHE_SIZE_BYTES = 1024 * 1024 * 50 | ||
const val CONNECT_TIMEOUT_MILLIS = 10_000L | ||
} | ||
} |
4 changes: 3 additions & 1 deletion
4
app/src/main/kotlin/org/michaelbel/template/repository/AppRepository.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
package org.michaelbel.template.repository | ||
|
||
import org.michaelbel.template.datastore.AppPreferences | ||
import org.michaelbel.template.ktor.AppService | ||
import org.michaelbel.template.room.AppDao | ||
|
||
class AppRepository( | ||
private val appPreferences: AppPreferences, | ||
private val appDao: AppDao | ||
private val appDao: AppDao, | ||
private val appService: AppService | ||
) |
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