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}"
|
implementation "com.github.topjohnwu.libsu:core:${versions.libsu}"
|
||||||
|
|
||||||
//Love <3
|
//Love <3
|
||||||
implementation "com.gitlab.AuroraOSS:gplayapi:3.0.1"
|
implementation "com.gitlab.AuroraOSS:gplayapi:3.1.0"
|
||||||
|
|
||||||
//Test
|
//Test
|
||||||
testImplementation 'junit:junit:4.13.2'
|
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.Fuel
|
||||||
import com.github.kittinunf.fuel.core.*
|
import com.github.kittinunf.fuel.core.*
|
||||||
import java.nio.charset.Charset
|
import java.nio.charset.Charset
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
|
||||||
object FuelClient : IHttpClient {
|
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 {
|
override fun get(url: String, headers: Map<String, String>): PlayResponse {
|
||||||
return get(url, headers, hashMapOf())
|
return get(url, headers, hashMapOf())
|
||||||
}
|
}
|
||||||
@@ -104,6 +111,9 @@ object FuelClient : IHttpClient {
|
|||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
private fun buildPlayResponse(response: Response, request: Request): PlayResponse {
|
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 {
|
return PlayResponse().apply {
|
||||||
isSuccessful = response.isSuccessful
|
isSuccessful = response.isSuccessful
|
||||||
code = response.statusCode
|
code = response.statusCode
|
||||||
@@ -117,6 +127,7 @@ object FuelClient : IHttpClient {
|
|||||||
errorString = String(errorBytes)
|
errorString = String(errorBytes)
|
||||||
}
|
}
|
||||||
}.also {
|
}.also {
|
||||||
|
_responseCode.value = response.statusCode
|
||||||
Log.i("FUEL [${request.method}:${response.statusCode}] ${response.url}")
|
Log.i("FUEL [${request.method}:${response.statusCode}] ${response.url}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,12 +31,19 @@ import okhttp3.OkHttpClient
|
|||||||
import okhttp3.RequestBody.Companion.toRequestBody
|
import okhttp3.RequestBody.Companion.toRequestBody
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
|
||||||
object OkHttpClient : IHttpClient {
|
object OkHttpClient : IHttpClient {
|
||||||
|
|
||||||
private const val POST = "POST"
|
private const val POST = "POST"
|
||||||
private const val GET = "GET"
|
private const val GET = "GET"
|
||||||
|
|
||||||
|
private val _responseCode = MutableStateFlow(100)
|
||||||
|
override val responseCode: StateFlow<Int>
|
||||||
|
get() = _responseCode.asStateFlow()
|
||||||
|
|
||||||
private val okHttpClient = OkHttpClient().newBuilder()
|
private val okHttpClient = OkHttpClient().newBuilder()
|
||||||
.connectTimeout(25, TimeUnit.SECONDS)
|
.connectTimeout(25, TimeUnit.SECONDS)
|
||||||
.readTimeout(25, TimeUnit.SECONDS)
|
.readTimeout(25, TimeUnit.SECONDS)
|
||||||
@@ -140,6 +147,9 @@ object OkHttpClient : IHttpClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun processRequest(request: Request): PlayResponse {
|
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)
|
val call = okHttpClient.newCall(request)
|
||||||
return buildPlayResponse(call.execute())
|
return buildPlayResponse(call.execute())
|
||||||
}
|
}
|
||||||
@@ -165,6 +175,7 @@ object OkHttpClient : IHttpClient {
|
|||||||
errorString = response.message
|
errorString = response.message
|
||||||
}
|
}
|
||||||
}.also {
|
}.also {
|
||||||
|
_responseCode.value = response.code
|
||||||
Log.i("OKHTTP [${response.code}] ${response.request.url}")
|
Log.i("OKHTTP [${response.code}] ${response.request.url}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user