Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface RetrofitInterface
- {
- //for updating user
- @PUT("users/update/{email}")
- Call<Response> updateUser(@Path("email") String email,@Body User user);
- }
- public void updateProfile(User user) {
- private String name;
- private String email;
- private String city;
- private int age;
- private String password;
- private String created_at;
- private String newPassword;
- private String token;
- public void setName(String name) {
- this.name = name;
- }
- public void setEmail(String email) {
- this.email = email;
- }
- public void setCity(String city) {
- this.city = city;
- }
- public void setAge(Integer age) {
- this.age = age;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- public String getName() {
- return name;
- }
- public String getEmail() {
- return email;
- }
- public String getCity()
- {
- return city;
- }
- public Integer getAge() {
- return age;
- }
- public String getCreated_at() {
- return created_at;
- }
- public void setNewPassword(String newPassword) {
- this.newPassword = newPassword;
- }
- public void setToken(String token) {
- this.token = token;
- }
- User muser = new User();
- muser.setName(nameText.getText().toString());
- muser.setAge(Integer.parseInt(ageText.getText().toString()));
- muser.setCity(cityText.getText().toString());
- // user.setEmail(mEmail);
- updateProfile(muser);
- public void updateProfile(User user) {
- Retrofit retrofit = new Retrofit.Builder()
- .baseUrl("https://fitnessrace.herokuapp.com/")
- .addConverterFactory(GsonConverterFactory.create())
- .build();
- RetrofitInterface retrofitInterface = retrofit.create(RetrofitInterface.class);
- Call<Response> call = retrofitInterface.updateUser(mEmail,user);
- //
- call.enqueue(new Callback<Response>()
- {
- @Override
- public void onResponse(Call<Response> call, retrofit2.Response<Response> response)
- {
- if (response.isSuccessful())
- {
- Response responseBody = response.body();
- Log.d("success", response.toString());
- Log.d("success2", responseBody.toString());
- }
- else
- {
- ResponseBody errorBody = response.errorBody();
- // Gson gson = new Gson();
- Gson gson = new GsonBuilder().create();
- try
- {
- Log.d("error1", errorBody.toString());
- //Response response1 = gson.fromJson(errorBody);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- Log.d("error2", e.toString());
- }
- }
- }
- @Override
- public void onFailure(Call<Response> call, Throwable t)
- {
- Log.d(TAG, "onFailure: "+t.getLocalizedMessage());
- }
- });
Add Comment
Please, Sign In to add comment