Skip to content

Instantly share code, notes, and snippets.

@BALUSANGEM
Created November 12, 2017 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BALUSANGEM/2706aafd05a30e38e5aa457042541ce7 to your computer and use it in GitHub Desktop.
Save BALUSANGEM/2706aafd05a30e38e5aa457042541ce7 to your computer and use it in GitHub Desktop.
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