Skip to content
This repository was archived by the owner on Apr 9, 2024. It is now read-only.

Commit 9dc7fcb

Browse files
committed
Fixed missing type information issue
1 parent a994194 commit 9dc7fcb

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

src/main/kotlin/com/thoo/api/endpoints/CosmeticEndpoints.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.thoo.api.models.BaseModel
77
import com.thoo.api.models.Cosmetic
88
import com.thoo.api.models.CosmeticSearchProperties
99
import com.thoo.api.services.CosmeticService
10+
import com.thoo.api.utils.gson
1011
import com.thoo.api.utils.send
1112
import com.thoo.api.utils.sendOkHttp
1213
import okhttp3.HttpUrl
@@ -54,7 +55,7 @@ class CosmeticEndpoints(
5455
}
5556

5657
@JvmOverloads
57-
fun searchCosmetics(language: Language = this.language, propertiesReceiver: CosmeticSearchProperties.() -> Unit): BaseModel<List<Cosmetic>> {
58+
fun searchCosmetics(language: Language = this.language, propertiesReceiver: CosmeticSearchProperties.() -> Unit): BaseModel<MutableList<Cosmetic>> {
5859
val properties = CosmeticSearchProperties()
5960
propertiesReceiver.invoke(properties)
6061
val clazz = properties.javaClass

src/main/kotlin/com/thoo/api/utils/Utils.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package com.thoo.api.utils
22

33
import com.google.gson.Gson
4+
import com.google.gson.reflect.TypeToken
45
import com.thoo.api.exceptions.FortniteApiException
56
import com.thoo.api.models.BaseModel
7+
import com.thoo.api.models.Cosmetic
68
import okhttp3.OkHttpClient
79
import okhttp3.Request
810
import retrofit2.Call
@@ -13,6 +15,7 @@ import java.io.InputStream
1315
import kotlin.jvm.Throws
1416

1517
typealias FCall<T> = Call<BaseModel<T>>
18+
typealias CList = BaseModel<List<Cosmetic>>
1619

1720
val 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+
3339
internal fun Response<*>.parseApiError(): FortniteApiException {
3440
val json = this.errorBody()?.string() ?: "{}"
3541
return gson.fromJson(json, FortniteApiException::class.java)

src/test/java/TestJava.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ public final class TestJava {
55

66
public static void main(String[] args) {
77
FortniteAPI api = FortniteAPI.create();
8+
89
}
910

1011
}

src/test/kotlin/TestKotlin.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import com.google.gson.Gson
12
import com.thoo.api.FortniteAPI
23
import com.thoo.api.enums.Language
34

@@ -9,9 +10,9 @@ object TestKotlin {
910
language = Language.DE
1011
)
1112
val cosmetic = api.cosmetic.searchCosmetic {
12-
name = "aura"
13+
hasVariants = true
1314
}
14-
println(cosmetic.data.id)
15+
println(cosmetic.data.name)
1516
}
1617

1718
}

0 commit comments

Comments
 (0)