class ExChange(
val basePrice: String
)
Interface
interface ExChangeAPI{
@GET("v1/forex/recent")
fun getExChangeInfo(
@Query("codes")arg:String
): retrofit2.Call<List<ExChange>>
}
Builder
val ExChangeRetrofit = Retrofit.Builder()
.baseUrl("https://quotation-api-cdn.dunamu.com/")
.addConverterFactory(GsonConverterFactory.create())
.build()
val ExChangeService = ExChangeRetrofit.create(ExChangeAPI::class.java)
Callback
ExChangeService.getExChangeInfo(value).enqueue(object :Callback<List<ExChange>>{
override fun onResponse(
call: retrofit2.Call<List<ExChange>>,
response: Response<List<ExChange>>
) {
CurrentWON = (response.body()!!.get(0).basePrice).toDouble()
}
override fun onFailure(call: retrofit2.Call<List<ExChange>>, t: Throwable) {
Log.d("Hey","ExChangeService onFailure")
}
})
사용
SetExChange("FRX.KRWUSD")
'Android with Kotlin' 카테고리의 다른 글
다중 선택 RecyclerView (0) | 2023.03.19 |
---|---|
Retorfit Body 사용 Post 방식 - Havah (0) | 2023.03.19 |
Dialog 실행 (0) | 2023.03.19 |
RecyclerView in RecyclerView (0) | 2023.03.19 |
Recycle View에서 Callback에 의한 notifyDataSetChanged() -OnUiThread 사용 (0) | 2023.03.19 |