Advertisement
Guest User

Untitled

a guest
Sep 13th, 2016
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. public static final String BASE_URL= "http://ashwinku.fwd.wf/ssng-project/api";
  2. public static final String REGISTER_OPERATION = "/registerUser";
  3. public static final String LOGIN_OPERATION = "/loginUser";
  4.  
  5. public User(String firstName, String password) {
  6. this.firstName=firstName;
  7. this.password = password;
  8.  
  9. }
  10.  
  11. RestAdapter restAdapter = new RestAdapter.Builder()
  12. .setEndpoint(Constants.BASE_URL)
  13. .setLogLevel(RestAdapter.LogLevel.FULL)
  14. .build();
  15.  
  16. //Creating object for our interface
  17. RequestInterface api = restAdapter.create(RequestInterface.class);
  18. user = new User(firstName,password);
  19. user.setFirstName(firstName);
  20. user.setPassword(password);
  21. //Defining the method insertuser of our interface
  22. api.loginuser(user, new Callback<User>() {
  23. @Override
  24. public void success(User result, Response response) {
  25. BufferedReader reader = null;
  26. //An string to store output from the server
  27. String output = "";
  28. try {
  29. //Initializing buffered reader
  30. reader = new BufferedReader(new InputStreamReader(response.getBody().in()));
  31. //Reading the output in the string
  32. output = reader.readLine();
  33.  
  34.  
  35.  
  36. } catch (IOException e) {
  37. e.printStackTrace();
  38. }
  39. //Displaying the output as a toast
  40. Toast.makeText(getActivity(), output, Toast.LENGTH_LONG).show();
  41. }
  42.  
  43. @Override
  44. public void failure(RetrofitError error) {
  45. Toast.makeText(getActivity(), error.toString(), Toast.LENGTH_LONG).show();
  46.  
  47. }
  48. });
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement