Skip to content

Commit

Permalink
[refactor] Change method name
Browse files Browse the repository at this point in the history
  • Loading branch information
mhmd-android committed Sep 2, 2024
1 parent 7d6bdfd commit 8980a80
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import io.ktor.client.request.HttpRequestBuilder
import io.ktor.client.request.request
import io.ktor.http.HttpMethod

suspend inline fun <reified T> HttpClient.getApiResponse(
suspend inline fun <reified T> HttpClient.get(
builder: HttpRequestBuilder,
): ApiResponse<T> {
builder.method = HttpMethod.Get
return apiResponseOf { request(builder) }
}

suspend inline fun <reified T> HttpClient.getApiResponse(
suspend inline fun <reified T> HttpClient.get(
block: HttpRequestBuilder.() -> Unit,
): ApiResponse<T> = getApiResponse(HttpRequestBuilder().apply(block))
): ApiResponse<T> = this.get(HttpRequestBuilder().apply(block))
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package ir.composenews.remotedatasource.api
import io.ktor.client.HttpClient
import io.ktor.http.appendPathSegments
import ir.composenews.network.ApiResponse
import ir.composenews.network.getApiResponse
import ir.composenews.network.get
import ir.composenews.remotedatasource.dto.MarketChartResponse
import ir.composenews.remotedatasource.dto.MarketDetailResponse
import ir.composenews.remotedatasource.dto.MarketResponse
Expand All @@ -30,7 +30,7 @@ class MarketsApiImpl @Inject constructor(
page: Int,
sparkline: Boolean,
): ApiResponse<List<MarketResponse>> = withContext(Dispatchers.IO) {
val response = httpClient.getApiResponse<List<MarketResponse>> {
val response = httpClient.get<List<MarketResponse>> {
url {
appendPathSegments(COINS, MARKETS)
parameters.append(VS_CURRENCY, currency)
Expand All @@ -48,7 +48,7 @@ class MarketsApiImpl @Inject constructor(
currency: String,
days: Int,
): ApiResponse<MarketChartResponse> = withContext(Dispatchers.IO) {
val response = httpClient.getApiResponse<MarketChartResponse> {
val response = httpClient.get<MarketChartResponse> {
url {
appendPathSegments(COINS, id, MARKET_CHART)
parameters.append(VS_CURRENCY, currency)
Expand All @@ -60,7 +60,7 @@ class MarketsApiImpl @Inject constructor(

override suspend fun getMarketDetail(id: String): ApiResponse<MarketDetailResponse> =
withContext(Dispatchers.IO) {
val response = httpClient.getApiResponse<MarketDetailResponse> {
val response = httpClient.get<MarketDetailResponse> {
url {
appendPathSegments(COINS, id)
}
Expand Down

0 comments on commit 8980a80

Please sign in to comment.