openWeather(api), retrofilt2

This commit is contained in:
JUNGGWAN KIM 2024-09-20 15:58:24 +09:00
parent 809b2b4279
commit b298c6d86f
2 changed files with 15 additions and 16 deletions

View File

@ -3,16 +3,16 @@ package rasel.lunar.launcher.model
import android.app.appsearch.StorageInfo
import com.google.gson.annotations.SerializedName
class WeatherInfo {
data class WeatherInfo (
@SerializedName("coord")
private var coord: Location? = null
var coord: Location? = null,
@SerializedName("weather")
private var weather: Weather? = null
var weather: Array<Weather>? = null,
@SerializedName("main")
private var main: Main? = null
}
var main: Main? = null
)
class Location {
var lon: String? = null

View File

@ -65,26 +65,25 @@ class OpenWeatherGetter : BaseGetter {
val service = retro.create<RestrofitService>()
val call = service.getPosts("lat=44.34&lon=10.99&appid=87cd0810b7e4b4debd31a6ef98b98154")
val call = service.getPosts()
call!!.enqueue(object: Callback<WeatherInfo>() {
override fun onResponse(
call: Call<WeatherInfo>,
response: Response<WeatherInfo>
) {
BLog.LOGE("Location >>> ")
call?.enqueue(object: Callback<WeatherInfo?> {
override fun onResponse(call: Call<WeatherInfo?>, response: Response<WeatherInfo?>) {
BLog.LOGE("Location error >>> $response")
BLog.LOGE("Location error >>> ${WeatherInfo().toString()}")
}
override fun onFailure(call: Call<WeatherInfo>, t: Throwable) {
BLog.LOGE("Location >>> ")
override fun onFailure(call: Call<WeatherInfo?>, t: Throwable) {
BLog.LOGE("Location error >>> $t")
}
})
}
}
interface RestrofitService {
@GET("/data/2.5/weather?{post}}")
fun getPosts(@Path("post") post: String?): Call<WeatherInfo?>?
@GET("/data/2.5/weather?lat=44.34&lon=10.99&appid=87cd0810b7e4b4debd31a6ef98b98154")
fun getPosts(): Call<WeatherInfo?>?
}