Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
RETROFIT TESTING
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.retrofit2:retrofit:2.0.2'
compile 'com.squareup.retrofit2:converter-gson:2.0.2'
public class ApiClient {
public static final String BASE_URL = "http://indianvedicschool.com/";
private static Retrofit retrofit = null;
public static Retrofit getClient() {
if (retrofit==null) {
Gson gson = new GsonBuilder()
.setLenient()
.create();
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
}
return retrofit;
}
}
public interface ApiInterface {
@FormUrlEncoded
@POST("login_api.php")
Call<String> logInWithDetails(@Field("email") String email, @Field("password") String password, @Field("submit") String submit);
}
private void submitDetails(String email, String password) {
ApiInterface apiService =
ApiClient.getClient().create(ApiInterface.class);
Call<String> call = apiService.logInWithDetails(email,password,"");
call.enqueue(new Callback<String>() {
@Override
public void onResponse(Call<String> call, Response<String> response) {
Log.d(TAG," ONRESPONSE : "+response.raw());
Log.d(TAG," ONRESPONSE : "+response.body());
}
@Override
public void onFailure(Call<String> call, Throwable t) {
Log.d(TAG," ONRESPONSE : "+t.getLocalizedMessage());
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment