11package com.thoo.api.utils
22
33import com.google.gson.Gson
4+ import com.google.gson.reflect.TypeToken
45import com.thoo.api.exceptions.FortniteApiException
56import com.thoo.api.models.BaseModel
7+ import com.thoo.api.models.Cosmetic
68import okhttp3.OkHttpClient
79import okhttp3.Request
810import retrofit2.Call
@@ -13,6 +15,7 @@ import java.io.InputStream
1315import kotlin.jvm.Throws
1416
1517typealias FCall <T > = Call <BaseModel <T >>
18+ typealias CList = BaseModel <List <Cosmetic >>
1619
1720val gson = Gson ()
1821
@@ -24,12 +27,15 @@ internal inline fun <reified T> Call<BaseModel<T>>.send(): BaseModel<T> {
2427}
2528
2629@Throws(FortniteApiException ::class )
27- internal inline fun <reified T > Request.sendOkHttp (client : OkHttpClient ): BaseModel < T > {
30+ internal inline fun <reified T > Request.sendOkHttp (client : OkHttpClient ): T {
2831 val response = client.newCall(this ).execute()
2932 if (! response.isSuccessful) throw gson.fromJson(response.body()?.string() ? : " {}" , FortniteApiException ::class .java)
30- return gson.fromJson< BaseModel < T >> (response.body()?.string() ? : " {}" , BaseModel :: class .java )
33+ return gson.fromJson(response.body()?.string() ? : " {}" )
3134}
3235
36+ internal inline fun <reified T > Gson.fromJson (json : String ) =
37+ fromJson<T >(json, object : TypeToken <T >() {}.type)
38+
3339internal fun Response <* >.parseApiError (): FortniteApiException {
3440 val json = this .errorBody()?.string() ? : " {}"
3541 return gson.fromJson(json, FortniteApiException ::class .java)
0 commit comments