Guest User

Untitled

a guest
Mar 3rd, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. public interface RetrofitInterface
  2. {
  3. //for updating user
  4. @PUT("users/update/{email}")
  5. Call<Response> updateUser(@Path("email") String email,@Body User user);
  6. }
  7.  
  8. public void updateProfile(User user) {
  9.  
  10. private String name;
  11. private String email;
  12. private String city;
  13. private int age;
  14.  
  15. private String password;
  16. private String created_at;
  17. private String newPassword;
  18. private String token;
  19.  
  20. public void setName(String name) {
  21. this.name = name;
  22. }
  23.  
  24. public void setEmail(String email) {
  25. this.email = email;
  26. }
  27.  
  28. public void setCity(String city) {
  29. this.city = city;
  30. }
  31.  
  32. public void setAge(Integer age) {
  33. this.age = age;
  34. }
  35.  
  36. public void setPassword(String password) {
  37. this.password = password;
  38. }
  39.  
  40. public String getName() {
  41. return name;
  42. }
  43.  
  44. public String getEmail() {
  45. return email;
  46. }
  47.  
  48. public String getCity()
  49. {
  50. return city;
  51. }
  52.  
  53. public Integer getAge() {
  54. return age;
  55. }
  56.  
  57. public String getCreated_at() {
  58. return created_at;
  59. }
  60.  
  61. public void setNewPassword(String newPassword) {
  62. this.newPassword = newPassword;
  63. }
  64.  
  65. public void setToken(String token) {
  66. this.token = token;
  67. }
  68.  
  69. User muser = new User();
  70. muser.setName(nameText.getText().toString());
  71. muser.setAge(Integer.parseInt(ageText.getText().toString()));
  72. muser.setCity(cityText.getText().toString());
  73.  
  74. // user.setEmail(mEmail);
  75. updateProfile(muser);
  76.  
  77. public void updateProfile(User user) {
  78.  
  79. Retrofit retrofit = new Retrofit.Builder()
  80. .baseUrl("https://fitnessrace.herokuapp.com/")
  81. .addConverterFactory(GsonConverterFactory.create())
  82. .build();
  83.  
  84. RetrofitInterface retrofitInterface = retrofit.create(RetrofitInterface.class);
  85.  
  86. Call<Response> call = retrofitInterface.updateUser(mEmail,user);
  87. //
  88. call.enqueue(new Callback<Response>()
  89. {
  90. @Override
  91. public void onResponse(Call<Response> call, retrofit2.Response<Response> response)
  92. {
  93.  
  94. if (response.isSuccessful())
  95. {
  96.  
  97. Response responseBody = response.body();
  98. Log.d("success", response.toString());
  99. Log.d("success2", responseBody.toString());
  100. }
  101. else
  102. {
  103.  
  104. ResponseBody errorBody = response.errorBody();
  105.  
  106. // Gson gson = new Gson();
  107. Gson gson = new GsonBuilder().create();
  108.  
  109. try
  110. {
  111. Log.d("error1", errorBody.toString());
  112. //Response response1 = gson.fromJson(errorBody);
  113.  
  114. }
  115. catch (Exception e)
  116. {
  117. e.printStackTrace();
  118. Log.d("error2", e.toString());
  119. }
  120. }
  121. }
  122.  
  123. @Override
  124. public void onFailure(Call<Response> call, Throwable t)
  125. {
  126. Log.d(TAG, "onFailure: "+t.getLocalizedMessage());
  127. }
  128. });
Add Comment
Please, Sign In to add comment