mirror of
https://github.com/whyorean/AuroraStore.git
synced 2026-06-13 02:11:07 -04:00
Bump gplayapi to 3.1.0
Also, override required responseCode StateFlow for HttpClient Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -168,7 +168,7 @@ dependencies {
|
||||
implementation "com.github.topjohnwu.libsu:core:${versions.libsu}"
|
||||
|
||||
//Love <3
|
||||
implementation "com.gitlab.AuroraOSS:gplayapi:3.0.1"
|
||||
implementation "com.gitlab.AuroraOSS:gplayapi:3.1.0"
|
||||
|
||||
//Test
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
|
||||
@@ -26,9 +26,16 @@ import com.aurora.store.util.Log
|
||||
import com.github.kittinunf.fuel.Fuel
|
||||
import com.github.kittinunf.fuel.core.*
|
||||
import java.nio.charset.Charset
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
|
||||
object FuelClient : IHttpClient {
|
||||
|
||||
private val _responseCode = MutableStateFlow(0)
|
||||
override val responseCode: StateFlow<Int>
|
||||
get() = _responseCode.asStateFlow()
|
||||
|
||||
override fun get(url: String, headers: Map<String, String>): PlayResponse {
|
||||
return get(url, headers, hashMapOf())
|
||||
}
|
||||
@@ -104,6 +111,9 @@ object FuelClient : IHttpClient {
|
||||
|
||||
@JvmStatic
|
||||
private fun buildPlayResponse(response: Response, request: Request): PlayResponse {
|
||||
// Reset response code as flow doesn't sends the same value twice
|
||||
_responseCode.value = 0
|
||||
|
||||
return PlayResponse().apply {
|
||||
isSuccessful = response.isSuccessful
|
||||
code = response.statusCode
|
||||
@@ -117,7 +127,8 @@ object FuelClient : IHttpClient {
|
||||
errorString = String(errorBytes)
|
||||
}
|
||||
}.also {
|
||||
_responseCode.value = response.statusCode
|
||||
Log.i("FUEL [${request.method}:${response.statusCode}] ${response.url}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,12 +31,19 @@ import okhttp3.OkHttpClient
|
||||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
import java.io.IOException
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
|
||||
object OkHttpClient : IHttpClient {
|
||||
|
||||
private const val POST = "POST"
|
||||
private const val GET = "GET"
|
||||
|
||||
private val _responseCode = MutableStateFlow(100)
|
||||
override val responseCode: StateFlow<Int>
|
||||
get() = _responseCode.asStateFlow()
|
||||
|
||||
private val okHttpClient = OkHttpClient().newBuilder()
|
||||
.connectTimeout(25, TimeUnit.SECONDS)
|
||||
.readTimeout(25, TimeUnit.SECONDS)
|
||||
@@ -140,6 +147,9 @@ object OkHttpClient : IHttpClient {
|
||||
}
|
||||
|
||||
private fun processRequest(request: Request): PlayResponse {
|
||||
// Reset response code as flow doesn't sends the same value twice
|
||||
_responseCode.value = 0
|
||||
|
||||
val call = okHttpClient.newCall(request)
|
||||
return buildPlayResponse(call.execute())
|
||||
}
|
||||
@@ -165,7 +175,8 @@ object OkHttpClient : IHttpClient {
|
||||
errorString = response.message
|
||||
}
|
||||
}.also {
|
||||
_responseCode.value = response.code
|
||||
Log.i("OKHTTP [${response.code}] ${response.request.url}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user