Skip to content

Instantly share code, notes, and snippets.

@muratcanbur
Created September 3, 2015 06:23
Show Gist options
  • Save muratcanbur/4a332f043886880f0ac3 to your computer and use it in GitHub Desktop.
Save muratcanbur/4a332f043886880f0ac3 to your computer and use it in GitHub Desktop.
Creating RestInterface Class
public final class BaseService {
private BaseService() {
}
private static Builder getBuilder() {
OkHttpClient client = new OkHttpClient();
client.setConnectTimeout(BuildConfig.CONNECTION_TIMEOUT,
TimeUnit.MILLISECONDS);
client.setReadTimeout(BuildConfig.CONNECTION_TIMEOUT,
TimeUnit.MILLISECONDS);
client.setWriteTimeout(BuildConfig.CONNECTION_TIMEOUT,
TimeUnit.MILLISECONDS);
StethoUtil.addNetworkInterceptor(client);
return new Builder()
.setEndpoint(BuildConfig.REST_ENDPOINT)
.setClient(new OkClient(client));
}
public static RestInterface getApi() {
Gson gson = new GsonBuilder().create();
return getBuilder().setConverter(new GsonConverter(gson))
.build().create(RestInterface.class);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment