How to return the searched content to another class via Retrofit

0

I have a problem that is as follows, I have a service class (DataService) that brings the api data using Retrofit2. So far so good, but when the data is returned I can access the body of the response through response.body () in the anonymous method onResponse (.. parameters here). Then the problem comes in, since my method is in service class, I need to return your data to the view (activity) but since the response is obtained inside the anonymous method onResponse this is not possible. How can I make the data returned by the API accessible to the service class, or do I need to adjust my way of handling this request?

public List<LoyaltyResponse> getLoyalties() {
        List<LoyaltyResponse> loyaltyResponseList;
        Call<List<LoyaltyResponse>> call = new RetrofitConfig().getLoyaltyHelper().getLoyalties(new LoyaltyRequest("param1", "param"));
        call.enqueue(new Callback<List<LoyaltyResponse>>() {
            @Override
            public void onResponse(Call<List<LoyaltyResponse>> call, Response<List<LoyaltyResponse>> response) {
                response.body();
            }
            @Override
            public void onFailure(Call<List<LoyaltyResponse>> call, Throwable throwable) {
                Log.i("WebAPI", "Erro ao buscar dados no servidor!");
            }
        });
        return null;
}
    
asked by anonymous 28.05.2018 / 21:27

0 answers