Retrofit2 API call is not performed

0

Good evening!   I am trying to do some testing to learn how to tinker with retrofit and RecyclerView and am using the example of the coinmarketcap site API in v2. But the service call is not entering the enqueue method, here is the configuration:

public class Coin {
private int id;
private String name;
private String symbol;
private String website_slug;

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getSymbol() {
    return symbol;
}

public void setSymbol(String symbol) {
    this.symbol = symbol;
}

public String getWebsite_slug() {
    return website_slug;
}

public void setWebsite_slug(String website_slug) {
    this.website_slug = website_slug;
}
}

interface

public interface CoinmarketService {

//chamada de uma listagem simples
@GET("{type}")
Call<Coin> getMoedas(@Path("type") String type);

}

The call is performed inside the Main class, in which case the main class may be empty, I initially only need the callback to execute because when I call this method in my main activity it does not return any calls.     // call Retrofit for API     private void retrofitConfig () {         Retrofit retrofit = new Retrofit.Builder ()                 .baseUrl (" link ")                 .addConverterFactory (GsonConverterFactory.create ())                 .build ();

    //Implementando a interface
    CoinmarketService service = retrofit.create(CoinmarketService.class);

    Call<Coin> moedas = service.getMoedas("listings");

    //Realizando a chamada assícrona
    moedas.enqueue(new Callback<Coin>() {
        @Override
        public void onResponse(Call<Coin> call, Response<Coin> response) {
            if (response.isSuccessful()){
                //Tratando retorno
                Coin coin = response.body();

                adapter.notifyDataSetChanged();
            }
        }

        @Override
        public void onFailure(Call<Coin> call, Throwable t) {
            Toast.makeText(MainActivity.this, "Problemas detectados", Toast.LENGTH_SHORT).show();
        }
    });
}

The adapter mentioned is because I'm trying to use RecyclerView, but it can be removed from the test, in that case I only need the Retrofit API call to happen so I'm not even getting into the 'enqueue' method. >

implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    
asked by anonymous 19.09.2018 / 02:22

0 answers