Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. package com.music.underfy.request.get;
  2.  
  3. import android.content.Context;
  4. import android.os.AsyncTask;
  5.  
  6. import com.music.underfy.Application;
  7. import com.music.underfy.domain.track.Track;
  8. import com.music.underfy.dto.Reponse.DeleteResponseDTO;
  9.  
  10. import org.json.JSONException;
  11. import org.json.JSONObject;
  12. import org.springframework.http.HttpEntity;
  13. import org.springframework.http.HttpHeaders;
  14. import org.springframework.http.HttpMethod;
  15. import org.springframework.http.ResponseEntity;
  16. import org.springframework.web.client.RestTemplate;
  17.  
  18. import java.util.HashMap;
  19. import java.util.Map;
  20.  
  21. /**
  22. * Created by gabriel on 01/06/17.
  23. */
  24.  
  25. public class GetTrackAppServerRequest extends AsyncTask<String, Void, String> {
  26.  
  27.  
  28. private final String service = "/song";
  29. private final String separator="?id_song=";
  30.  
  31. private final String serviceUrl;
  32. private Context context;
  33.  
  34. public GetTrackAppServerRequest(Context context){
  35. this.context=context;
  36. this.serviceUrl= Application.appServer+service;
  37. }
  38.  
  39. @Override
  40. protected String doInBackground(String... params) {
  41. final String trackId=params[0];
  42.  
  43.  
  44. HttpHeaders headers = new HttpHeaders();
  45. headers.set("Authorization", "basic token");
  46.  
  47. Map<String,String> param=new HashMap<>();
  48.  
  49. RestTemplate restTemplate = new RestTemplate();
  50.  
  51. HttpEntity entity = new HttpEntity(headers);
  52. String url=serviceUrl+separator+trackId;
  53. ResponseEntity<String> response = restTemplate. exchange(
  54. url, HttpMethod.GET, entity, String.class, param);
  55. JSONObject userJson = null;
  56. try {
  57. userJson = new JSONObject(response.getBody());
  58.  
  59. return userJson.getString("message");
  60. } catch (JSONException e) {
  61. e.printStackTrace();
  62. }
  63.  
  64. return null;
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement