Last active
November 1, 2016 00:07
-
-
Save briansalvattore/b0854dc8b6418c9165eb9c7205978a57 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HelloWorld { | |
private static final int TIMEOUT = 120; | |
private static final String BASE = "https://randomuser.me/"; | |
public static void main(String[] args) { | |
System.out.println("Hello"); | |
HttpLoggingInterceptor logging = new HttpLoggingInterceptor(); | |
logging.setLevel(HttpLoggingInterceptor.Level.BODY); | |
OkHttpClient client = new OkHttpClient.Builder() | |
.connectTimeout(TIMEOUT, TimeUnit.SECONDS) | |
.writeTimeout(TIMEOUT, TimeUnit.SECONDS) | |
.readTimeout(TIMEOUT, TimeUnit.SECONDS) | |
.addInterceptor(logging) | |
.build(); | |
Retrofit retrofit = new Retrofit.Builder() | |
.baseUrl(BASE) | |
.addConverterFactory(GsonConverterFactory.create()) | |
.client(client) | |
.build(); | |
System.out.println("Init call"); | |
retrofit.create(Service.class).getUser().enqueue(new Callback<JsonObject>() { | |
@Override | |
public void onResponse(Call<JsonObject> arg0, Response<JsonObject> arg1) { | |
System.out.println("Response"); | |
System.out.println(arg1.body()); | |
} | |
@Override | |
public void onFailure(Call<JsonObject> arg0, Throwable arg1) { | |
System.out.println("When call failure"); | |
System.err.println(arg1.toString()); | |
} | |
}); | |
} | |
public interface Service { | |
@GET("/api") | |
Call<JsonObject> getUser(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment