SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class ApiService {
  2.  
  3.     private Context context;
  4.     private RequestQueue requestQueue;
  5.  
  6.     public ApiService(Context context) {
  7.  
  8.         this.context = context;
  9.         requestQueue = Volley.newRequestQueue(context);
  10.     }
  11.  
  12.     public void registerStudent(String firstName, String lastName, String course, int score, Response.Listener<Student> listener, Response.ErrorListener errorListener){
  13.  
  14.         GsonRequest<Student> request = new GsonRequest<>(Request.Method.POST
  15.                 , "experts/student",
  16.                 new TypeToken<Student>() {
  17.                 }.getType(),
  18.                 listener,
  19.                 errorListener);
  20.         JsonObject jsonObject=new JsonObject();
  21.         jsonObject.addProperty("first_name",firstName);
  22.         jsonObject.addProperty("last_name",lastName);
  23.         jsonObject.addProperty("course",course);
  24.         jsonObject.addProperty("score",score);
  25.         request.setJsonObject(jsonObject);
  26.         requestQueue.add(request);
  27.  
  28.     }
  29.  
  30.     public void listStudents(Response.Listener<List<Student>> listener, Response.ErrorListener errorListener) {
  31.         GsonRequest<List<Student>> request = new GsonRequest<>(Request.Method.GET
  32.                 , "experts/student",
  33.                 new TypeToken<List<Student>>() {
  34.                 }.getType(),
  35.                 listener,
  36.                 errorListener);
  37.         requestQueue.add(request);
  38.     }
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top