コード例 #1
0
    /**
     * Parse JSON for Borrowed Books
     *
     * @param jar
     * @return
     * @throws UnsupportedEncodingException
     * @throws JSONException
     */
    private List<Book> parse(JSONArray jar) throws UnsupportedEncodingException, JSONException {
      List<Book> books = new ArrayList<>();

      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);

        books.add(bb);
      }
      return books;
    }
コード例 #2
0
 /**
  * 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;
 }
コード例 #3
0
  private void requestUpdateData(String uri) throws JSONException {
    for (Book b : adapter.getSelectedBooks()) {
      BorrowedBook bb = (BorrowedBook) b;
      RequestPackaging p = new RequestPackaging();
      p.setMethod("POST"); // Set the HTTP REQUEST method
      p.setUri(uri); // Sets the URI
      JSONArray jar = new JSONArray();
      JSONObject object = new JSONObject();
      object.put("query", "update"); // What kind of query
      object.put("method", "retrieveborrowbook"); // What kind of request
      object.put(
          "id",
          SaveSharedPreference.getID(getActivity())); // Pass the id for the user to the webservice
      object.put("isbn", bb.getIsbn());
      object.put("friendid", bb.getOwner().getId());
      jar.put(object);
      p.setJarParams(jar); // Add the param objects to the JSONArray

      MyTask task = new MyTask();
      task.execute(p);
    }
  }
コード例 #4
0
  /**
   * 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);
  }