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 android.app.appsearch.StorageInfo
import com.google.gson.annotations.SerializedName import com.google.gson.annotations.SerializedName
class WeatherInfo { data class WeatherInfo (
@SerializedName("coord") @SerializedName("coord")
private var coord: Location? = null var coord: Location? = null,
@SerializedName("weather") @SerializedName("weather")
private var weather: Weather? = null var weather: Array<Weather>? = null,
@SerializedName("main") @SerializedName("main")
private var main: Main? = null var main: Main? = null
} )
class Location { class Location {
var lon: String? = null var lon: String? = null

View File

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