File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,13 +4,16 @@ import com.google.gson.*
44import com.thoo.api.models.*
55import com.thoo.api.services.ValorantApiService
66import com.thoo.api.utils.send
7+ import okhttp3.OkHttpClient
78import retrofit2.Retrofit
89import retrofit2.converter.gson.GsonConverterFactory
910import java.lang.reflect.Modifier
1011import java.lang.reflect.Type
1112import 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}
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ package com.thoo.api.exceptions
22
33import java.lang.Exception
44
5- class ValorantApiError (
5+ class ValorantApiException (
66 status : Int? ,
77 error : String
88): Exception(" $error ${if (status != null ) " (${status} )" else " " } " )
Original file line number Diff line number Diff line change 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+ )
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 11package com.thoo.api.utils
22
3- import com.thoo.api.exceptions.ValorantApiError
3+ import com.thoo.api.exceptions.ValorantApiException
44import com.thoo.api.models.BaseModel
55import retrofit2.Call
66
77inline 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}
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments