I want to use Retrofit 2.1.0 for my next Android project. I would like to use Design Pattern and therefore create separate classes for every REST call i.e
IBalanceServ
public class BalanceRestClient {
private static BalanceRestClient instance;
private IBalanceService request;
private BalanceRestClient() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://hovermind.com")
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(rxAdapter)
.build();
request = retrofit.create(IBalanceService.class);
}
public static synchronized BalanceRestClient getInstance() {
if (instance == null)
instance = new BalanceRestClient();
return instance;
}
public void getRequest(String userName, YourCustomeCallback callback) {
Call call = apiService.getUser(username);
call.enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) {
User user = response.body();
callback.onResponse(user);
}
@Override
public void onFailure(Call call, Throwable t) {
// Log error here since request failed
}
});
}
}