/** * Parse JSON for BorrowedBooks * * @param jar * @return */ private List<Book> parse(JSONArray jar) { List<Book> borrowedBooks = new ArrayList<>(); try { for (int i = 0; i < jar.length(); i++) { JSONObject job = (JSONObject) jar.get(i); Book b = JSONParser.parseBook(job); Friend f = JSONParser.parseFriend(job); User u = JSONParser.parseUser(job); BorrowedBook bb = new BorrowedBook(); bb.setRenter(f); bb.setBook(b); bb.setOwner(u); borrowedBooks.add(bb); } } catch (UnsupportedEncodingException | JSONException e) { e.printStackTrace(); } return borrowedBooks; }
/** * Make a reply request call to restful * * @param position * @throws JSONException */ public void requestReplyRequest(int position) throws JSONException { BorrowedBook borrowedBook = (BorrowedBook) borrowedBooks.get(position); RequestPackaging p = new RequestPackaging(); p.setMethod("POST"); // Set the HTTP REQUEST method p.setUri(BookshelfConstants.CONNECTION_URI); // Sets the URI JSONArray jar = new JSONArray(); JSONObject object = new JSONObject(); object.put("query", "update"); // What kind of query object.put("method", "replyborrowedbook"); // What kind of request object.put( "friendid", SaveSharedPreference.getID(getActivity())); // Pass the id for the user to the webservice object.put("id", borrowedBook.getRenter().getId()); object.put("isbn", borrowedBooks.get(position).getIsbn()); object.put("accepted", "FALSE"); object.put("replied", "TRUE"); jar.put(object); p.setJarParams(jar); // Add the param objects to the JSONArray MyTask task = new MyTask(); task.execute(p); }