Skip to content

Commit

Permalink
PostRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
slartus committed Apr 19, 2024
1 parent 2c687f3 commit 0497495
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ru.slartus.boostbuddy.data.repositories

import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.request.get
import io.ktor.client.request.parameter
import ru.slartus.boostbuddy.data.repositories.models.Posts
import ru.slartus.boostbuddy.utils.fetchOrError

internal class PostRepository(
private val httpClient: HttpClient,
) {
suspend fun getPost(url: String, id: String): Result<Posts> =
fetchOrError {
val response: String =
httpClient.get("https://api.boosty.to/v1/blog/$url/post/$id") {
parameter("comments_limit", "20")
parameter("reply_limit", "20")
}.body()

error(response)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ru.slartus.boostbuddy.data.Inject
import ru.slartus.boostbuddy.data.ktor.buildHttpClient
import ru.slartus.boostbuddy.data.repositories.BlogRepository
import ru.slartus.boostbuddy.data.repositories.GithubRepository
import ru.slartus.boostbuddy.data.repositories.PostRepository
import ru.slartus.boostbuddy.data.repositories.SettingsRepository
import ru.slartus.boostbuddy.data.repositories.SubscribesRepository
import ru.slartus.boostbuddy.data.repositories.comments.CommentsRepository
Expand Down Expand Up @@ -37,6 +38,7 @@ object PlatformDataConfiguration {
bindSingleton { BlogRepository(httpClient = instance(TAG_HTTP_CLIENT_BOOSTY)) }
bindSingleton { GithubRepository(httpClient = instance(TAG_HTTP_CLIENT_GITHUB)) }
bindSingleton { CommentsRepository(httpClient = instance(TAG_HTTP_CLIENT_BOOSTY)) }
bindSingleton { PostRepository(httpClient = instance(TAG_HTTP_CLIENT_BOOSTY)) }
}
}
}

0 comments on commit 0497495

Please sign in to comment.