I am using yahoo weather api and getting result using this link:
Now I want to using this url with retrofit. So please tell me how to change the city by passing query.
Thank you
I am using yahoo weather api and getting result using this link:
Now I want to using this url with retrofit. So please tell me how to change the city by passing query.
Thank you
It would end up being something like this:
public interface WeatherService {
@GET("v1/public/yql")
Call<String> getWeather(@Query("q") String query);
}
Then create the object like this:
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://query.yahooapis.com")
.addConverterFactory(ScalarsConverterFactory.create())
.build();
WeatherService wService = retrofit.create(WeatherService.class);
And run it like this:
String query = "select * from weather.forecast where woeid in (select woeid from geo.places(1) where text=\"Leeds\")&format=json";
Call<String> weather = wService.getWeather(query);
try {
Response<String> resp = weather.execute();
You should change the ConverterFactory to json and properly parse the weather output.
I have not tested this, just giving you an idea of how to use the Retrofit query.
If I understand well, you are looking for a way to include a given city to the url. Here is a sample code on how to do so. In the example the variable city could take any given city name.
var city = "london";
var query = "select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22"+ city +"%22)&format=json"
Update:
then you could concatenate the query to the base url like this :
var baseurl = "https://query.yahooapis.com/v1/public/yql?q=" + query;