Skip to content

Commit 06b45d9

Browse files
committed
Update
1 parent ec89d2d commit 06b45d9

6 files changed

Lines changed: 27 additions & 8 deletions

File tree

src/main/kotlin/com/thoo/api/ValorantApi.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ import com.google.gson.*
44
import com.thoo.api.models.*
55
import com.thoo.api.services.ValorantApiService
66
import com.thoo.api.utils.send
7+
import okhttp3.OkHttpClient
78
import retrofit2.Retrofit
89
import retrofit2.converter.gson.GsonConverterFactory
910
import java.lang.reflect.Modifier
1011
import java.lang.reflect.Type
1112
import java.math.BigDecimal
1213

13-
class ValorantApi {
14+
class ValorantApi(
15+
client: OkHttpClient = OkHttpClient()
16+
) {
1417

1518
private val gson = GsonBuilder()
1619
.setPrettyPrinting()
@@ -23,6 +26,7 @@ class ValorantApi {
2326
}).create()
2427

2528
private val retrofit: Retrofit = Retrofit.Builder()
29+
.client(client)
2630
.baseUrl("https://valorant-api.com/v1/")
2731
.addConverterFactory(GsonConverterFactory.create(gson))
2832
.build()
@@ -41,5 +45,6 @@ class ValorantApi {
4145
fun getThemes(): BaseModel<Array<Theme>> = service.themes().send()
4246
fun getTitles(): BaseModel<Array<Title>> = service.titles().send()
4347
fun getWeapons(): BaseModel<Array<Weapon>> = service.weapons().send()
48+
fun getVersion(): BaseModel<Version> = service.version().send()
4449

4550
}

src/main/kotlin/com/thoo/api/exceptions/ValorantApiError.kt renamed to src/main/kotlin/com/thoo/api/exceptions/ValorantApiException.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.thoo.api.exceptions
22

33
import java.lang.Exception
44

5-
class ValorantApiError(
5+
class ValorantApiException(
66
status: Int?,
77
error: String
88
): Exception("$error ${if(status != null) "(${status})" else ""}")
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.thoo.api.models
2+
3+
import java.util.*
4+
5+
data class Version(
6+
val branch: String,
7+
val version: String,
8+
val buildVersion: String,
9+
val buildDate: Date
10+
)

src/main/kotlin/com/thoo/api/services/ValorantApiService.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface ValorantApiService {
1616
@GET("/v1/buddies")
1717
fun buddies(): Call<BaseModel<Array<Budy>>>
1818

19-
@GET("/v1/cards")
19+
@GET("/v1/playercards")
2020
fun cards(): Call<BaseModel<Array<Card>>>
2121

2222
@GET("/v1/contenttiers")
@@ -40,10 +40,13 @@ interface ValorantApiService {
4040
@GET("/v1/themes")
4141
fun themes(): Call<BaseModel<Array<Theme>>>
4242

43-
@GET("/v1/titles")
43+
@GET("/v1/playertitles")
4444
fun titles(): Call<BaseModel<Array<Title>>>
4545

4646
@GET("/v1/weapons")
4747
fun weapons(): Call<BaseModel<Array<Weapon>>>
4848

49+
@GET("/v1/version")
50+
fun version(): Call<BaseModel<Version>>
51+
4952
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package com.thoo.api.utils
22

3-
import com.thoo.api.exceptions.ValorantApiError
3+
import com.thoo.api.exceptions.ValorantApiException
44
import com.thoo.api.models.BaseModel
55
import retrofit2.Call
66

77
inline fun <reified T> Call<BaseModel<T>>.send(): BaseModel<T> {
88
val response = this.execute();
99
if(!response.isSuccessful) {
10-
throw ValorantApiError(response.code(), "Something went wrong.")
10+
throw ValorantApiException(response.code(), "Something went wrong.")
1111
}
1212
if(response.body() == null) {
13-
throw ValorantApiError(null, "Response is null.")
13+
throw ValorantApiException(null, "Response is null.")
1414
}
1515
return response.body()!!
1616
}

src/test/kotlin/Test.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ fun main(args: Array<String>) {
1313
val seasons = api.getSeasons()
1414
val themes = api.getThemes()
1515
val titles = api.getTitles()*/
16-
val weapons = api.getWeapons()
16+
val f = api.getVersion()
17+
val status = api.getVersion()
1718
}

0 commit comments

Comments
 (0)