within the interface
@POST("/data")
Call<IDVerification> postCustomerConfirmation (@Body IDVerification idVerification);
Inside the Activityui onCreate
Retrofit client = new Retrofit.Builder()
.baseUrl(APIForid.base_url)
.addConverterFactory(GsonConverterFactory.create())
.build();
Calling a control class or asynchronous use
public void sendIDVerification(IDVerification idVerification) {
sendIDVerificationUI.showSending();
if(idVerification != null) {
Call<IDVerification> call = apiForid.postCustomerConfirmation(idVerification);
call.enqueue(new Callback<IDVerification>() {
@Override
public void onResponse(Response<IDVerification> response, Retrofit retrofit) {
if (response.isSuccess()) {
sendIDVerificationUI.finishSendingVerification();
}
}
@Override
public void onFailure(Throwable t) {
if(t.toString() != null) {
String message = t.getMessage();
if (message.contains("timeout") || message.contains("ETIMEDOUT")) {
sendIDVerificationUI.onSendIdVerificationError(0);
} else if (message.contains("Unable to resolve host")) {
sendIDVerificationUI.onSendIdVerificationError(0);
} else if (message.contains("Failed to connect")) {
sendIDVerificationUI.onSendIdVerificationError(0);
} else if (message.contains("SocketTimeout") ){
sendIDVerificationUI.onSendIdVerificationError(0);
}
}
}
});
}
}
Within the Idverification class create a constructor
public IDVerification(FacebookProfile facebookProfile, Customer customer, Location location, Picture picture, Audio audio) {
if(facebookProfile != null) {
this.facebookProfile = new FacebookProfile(facebookProfile.getName(),
facebookProfile.getEducation_history(),
facebookProfile.getBirthday(),
facebookProfile.getHometown(),
facebookProfile.getEmail(),
facebookProfile.getLocation());
}
...
Within each previously used class, have your own constructor
public FacebookProfile (String name, String education_history, String birthday, String hometown, String email, String location){
this.name = name;
this.education_history = education_history;
this.birthday = birthday;
this.hometown = hometown;
this.email = email;
this.location = location;
}
You need to be more specific. What part is your difficulty in? It is in the interface statement to be passed to Restadapter.Builder?
– ramaral
yes, how to create the right interface and how to create the call afterwards in order to pass each right part
– Aleff Matos
I need to send to a server the information contained in each class, and those classes are all within this Idverification, I want to know how I declare this, and how I go dividing by class to get something close to the example I gave
– Aleff Matos
It is not enough to have a method in the interface with
@POST
and a parameter with the annotation of@Body
? He even tested it?– Wakim