Retrofit outra maneira de implementar
private void updatePhoneNumber() {
final MaterialDialog dialog = new MaterialDialog.Builder(this).progress(true, 0).content(R.string.action_send_data).show();
final Customer customer = Customer.builder()
.email(myPrefs.email().get())
.ddd(PhoneUtil.getDdd(inputPhone.getText().toString()))
.phone(PhoneUtil.getPhone(inputPhone.getText().toString())).build();
CustomerService service = ServiceGenerator.createService(CustomerService.class);
Call<ResponseBody> call = service.changePhoneNumber(myPrefs.authToken().get(), customer);
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
dialog.dismiss();
phoneTextInputLayout.setError(null);
if(response.isSuccessful()) {
try {
Toast.makeText(PhoneUpdateActivity.this, response.body().string(), Toast.LENGTH_LONG).show();
myPrefs.edit().ddd().put(customer.getDdd()).phone().put(customer.getPhone()).phoneActivated().put(false).apply();
setResult(RESULT_OK);
finish();
} catch (IOException e) {
e.printStackTrace();
}
} else {
phoneTextInputLayout.setError(ExceptionParse.getMessage(response));
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
dialog.dismiss();
DialogUtil.networkIssue(PhoneUpdateActivity.this);
}
});
}
/**
* Solicita o envio do SMS
*/
private void sendSms() {
// Não envia sms em devtime
if(!BuildConfig.FLAVOR.equals("dev")) {
Call<Boolean> call = service.verifyPhoneNumber(myPrefs.authToken().get(), Customer.builder()
.ddd(myPrefs.ddd().get())
.phone(myPrefs.phone().get())
.email(myPrefs.email().get()).build()
);
call.enqueue(new SuppressErrorCallback<Boolean>() {
@Override
public void onResponse(Call<Boolean> call, Response<Boolean> response) {
if(response.isSuccessful()) {
startCountdown();
} else {
FirebaseCrash.log("O endpoin retornou um erro ao enviar um SMS");
}
}
});
} else {
startCountdown();
}
}
package br.com.choferrj.cliente.service;
import java.util.List;
import br.com.choferrj.cliente.model.Customer;
import br.com.choferrj.cliente.model.GiftCard;
import br.com.choferrj.cliente.model.History;
import br.com.choferrj.cliente.model.Page;
import br.com.choferrj.cliente.model.ResponseDefault;
import br.com.choferrj.cliente.model.Review;
import okhttp3.MultipartBody;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.PUT;
import retrofit2.http.Part;
import retrofit2.http.Path;
import retrofit2.http.Query;
/**
* Created by Dell15r on 09/05/2016.
*/
public interface CustomerService {
@POST("customer")
Call<Customer> create(@Body Customer customer);
@PUT("customer")
Call<Customer> update(@Header("X-Auth-Token") String token, @Body Customer customer);
// alcatrazbr
// @POST("customer/login")
@POST("webservice/loginteste")
Call<Customer> login(@Body Customer customer);
@GET("customer")
Call<Customer> getProfile(@Header("X-Auth-Token") String token);
@Multipart
@POST("customer/profile-image")
Call<Customer> updateThumb(@Header("X-Auth-Token") String token, @Part MultipartBody.Part file);
@POST("customer/change-password")
Call<ResponseBody> changePassword(@Header("X-Auth-Token") String token, @Body Customer customer);
@PUT("customer/change-device-token")
Call<ResponseBody> changeDeviceToken(@Header("X-Auth-Token") String token, @Body Customer customer);
@POST("customer/reset-password")
Call<Customer> resetPassword(@Body Customer customer);
@POST("customer/verify")
Call<Boolean> verifyEmail(@Body Customer customer);
@POST("customer/verify-phone")
Call<Boolean> verifyPhone(@Header("X-Auth-Token") String token, @Body Customer customer);
@PUT("customer/change-phone")
Call<ResponseBody> changePhone(@Header("X-Auth-Token") String token, @Body Customer customer);
// alcatrazbr
@PUT("webservice/change-phone")
Call<ResponseBody> changePhoneNumber(@Header("X-Auth-Token") String token, @Body Customer customer);
@PUT("customer/activate-phone/{code}")
Call<Boolean> activatePhoneNumber(@Header("X-Auth-Token") String token, @Path("code") String code);
// alcatrazbr
@PUT("webservice/validate-phone-code/")
Call<ResponseDefault> activatePhoneNumber(@Body Customer customer);
@POST("customer/giftcard/apply/{code}")
Call<GiftCard> applyGiftCard(@Header("X-Auth-Token") String token, @Path("code") String code);
@GET("customer/giftcard/all")
Call<List<GiftCard>> listGiftCards(@Header("X-Auth-Token") String token);
@GET("customer/history/all")
Call<Page<History>> listHistory(@Header("X-Auth-Token") String token, @Query("page") int page, @Query("size") int size);
}
package br.com.choferrj.cliente.model;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Builder;
import br.com.choferrj.cliente.BuildConfig;
/**
* Created by Dell15r on 09/05/2016.
*/
@Getter @Setter @Builder
public class Customer {
private long id;
private String name;
private String firstName;
private String lastName;
private String ddd;
private String phone;
private String email;
private String password;
private String deviceToken;
private String token;
private String picture;
private String thumb;
private String since;
private String codeToConfirm;
private String deviceType = "android";
private Request currentRequest;
private boolean disabledPerson;
private boolean emailActivation;
private boolean phoneActivation;
private String androidApiVersion;
private String manufacturer;
private String model;
private int codeVersion = BuildConfig.VERSION_CODE;
}