Retorfit Body를 사용한 Post-Method – Havah

데이터 클래스

data class Planet(
    val message: Message
)

data class Message(
    val msg: Msg
)

data class Msg(
    val totalData: Int,
    val listData: List<ListData>,
    val fullTime: Int
)

data class ListData(
    val tokenId: Int,
    var claimable: Double = 0.0,
    var planetStatus: Int = 0,
    var operationTime: Int = 0,
    var totalPrice:Double =0.0
)

상호 작용

interface HavahAPI{
    @POST("api/icon/myPlanetList")
    fun getHavahInfo(
        @Body req :PlanetReq
    ):retrofit2.Call<Planet>
}

건축업자

val HavahRetrofit = Retrofit.Builder()
    .baseUrl("https://havah.io")
    .addConverterFactory(GsonConverterFactory.create())
    .build()

val HavahService = HavahRetrofit.create(HavahAPI::class.java)

구현 또는 사용

HavahService.getHavahInfo(
    PlanetReq(
        0,
        100,
        HavahList.get(i).address
    )
).enqueue(object : Callback<Planet> {
    override fun onResponse(
        call: retrofit2.Call<Planet>,
        response: Response<Planet>
    ) {

        var temp = response.body()!
!
.message.msg.listData Log.d("Hey4","HavahList.get(i).sub.size = ${HavahList.get(i).sub.size}") for(j in 0 until HavahList.get(i).sub.size){ for( k in 0 until temp.size) { if (HavahList.get(i).sub.get(j).tokenId.equals(temp.get(k).tokenId)) { HavahList.get(i).sub.get(j).claimable = temp.get(k).claimable HavahList.get(i).sub.get(j).planetStatus = temp.get(k).planetStatus HavahList.get(i).sub.get(j).operationTime = temp.get(k).operationTime HavahList.get(i).sub.get(j).totalPrice =ByBitPrice * temp.get(k).claimable } } } Log.d("Hey", "Havah List : ${HavahList}") } override fun onFailure(call: retrofit2.Call<Planet>, t: Throwable) { Log.d("Hey", "Havah onFailure") } })