Я начал изучать использование с Retrofit и Rxjava2.Я пытаюсь вывести все страны из https://restcountries.eu/rest/v2/all/, но я не могу обдумать это.Я хочу получить все из URL выше и подписаться вот так https://restcountries.eu/rest/v2/name/usa. Можете ли вы помочь мне достичь этого.
public interface ApiService {
@GET("country/{country_id}")
Single<Country> getCountryData(@Path("name") String name);
@GET("country/{country_id}")
Call<Country> getAllCountries(@Path("array") String name);
}
Страна:
public class Country {
@Expose
@SerializedName("name")
private Integer name;
@Expose
@SerializedName("capital")
private String capital;
@Expose
@SerializedName("population")
private int population;
}
MainClass:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Get all
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://restcountries.eu/rest/v2/all/")
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build();
ApiService apiService = retrofit.create(ApiService.class);
apiService.getAllCountries("array").subscribe(new SingleObserver<Country>() {
@Override
public void onSubscribe(Disposable d) {
// we'll come back to this in a moment
}
@Override
public void onSuccess(Country country) {
// data is ready and we can update the UI
Log.d("DTAG",country.getName());
}
@Override
public void onError(Throwable e) {
// oops, we best show some error message
}
});;
//Gat Single
Retrofit retrofitSingle = new Retrofit.Builder()
.baseUrl("https://restcountries.eu/rest/v2/all/USA")
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build();
ApiService apiServiceSingle = retrofitSingle.create(ApiService.class);
apiServiceSingle.getAllCountries("array").subscribe(new SingleObserver<Country>() {
@Override
public void onSubscribe(Disposable d) {
// we'll come back to this in a moment
}
@Override
public void onSuccess(Country country) {
// data is ready and we can update the UI
Log.d("DTAG","");
}
@Override
public void onError(Throwable e) {
// oops, we best show some error message
}
});;
}