HttpCall.java 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package com.example.yiupang.freefoodfinder;
  2. import com.fasterxml.jackson.databind.JsonNode;
  3. import com.fasterxml.jackson.databind.ObjectMapper;
  4. import java.util.Map;
  5. /**
  6. * Created by yiupang on 5/27/2017.
  7. *
  8. */
  9. class HttpCall
  10. {
  11. static final int GET = 1;
  12. static final int POST = 2;
  13. static final int PUT = 3;
  14. static final int DELETE = 4;
  15. private static ObjectMapper mapper;
  16. static {
  17. mapper = new ObjectMapper();
  18. }
  19. public static String methodToStr(int method)
  20. {
  21. switch (method)
  22. {
  23. case GET:
  24. return "GET";
  25. case POST:
  26. return "POST";
  27. case PUT:
  28. return "PUT";
  29. case DELETE:
  30. return "DELETE";
  31. default:
  32. throw new IllegalArgumentException("Invalid method code");
  33. }
  34. }
  35. private String url;
  36. private int methodType;
  37. private JsonNode body;
  38. private Map<String, String> query;
  39. public String getUrl() {
  40. return url;
  41. }
  42. public void setUrl(String url) {
  43. this.url = url;
  44. }
  45. public int getMethodType() {
  46. return methodType;
  47. }
  48. public void setMethodType(int methodType) {
  49. this.methodType = methodType;
  50. }
  51. public JsonNode getBody() {
  52. return body;
  53. }
  54. public void setBody(JsonNode params) {
  55. this.body = params;
  56. }
  57. public void setBody(Object params) {
  58. this.body = mapper.valueToTree(params);
  59. }
  60. public Map<String, String> getQueryParams() {
  61. return query;
  62. }
  63. public void setQueryParams(Map<String, String> query) {
  64. this.query = query;
  65. }
  66. }