public boolean DDAdd(int memberid, String te_username) { boolean result = false; String status = ""; JSONObject response, post; String api = API1 + te_username + API2; // String api = "http://192.168.2.132:5000"; String url = api + CREATEDDACCT; post = new JSONObject(); try { post.put("userid", memberid); post.put("session", this.session_token); } catch (JSONException e) { e.printStackTrace(); return result; } response = this.postJSON(url, post); if (response == null) { errormsg = "Server not responding."; errorcode = JSONError.NORESPONSE.getKey(); return result; } try { status = response.getString("result"); } catch (JSONException e) { status = "failure"; errormsg = "Server not responding"; errorcode = JSONError.NORESPONSE.getKey(); } if (status.compareTo("failure") == 0) { try { errormsg = response.getString("message"); if (errormsg.contains("There is already a customer")) result = true; } catch (JSONException e) { errormsg = "No Response"; } errorcode = JSONError.INVALIDINPUT.getKey(); } else { try { this.session_token = response.getString("session"); result = true; } catch (JSONException e) { errormsg = "Missing Session"; errorcode = JSONError.INTERNALCON.getKey(); } } if (result) { result = DDdetails(memberid, te_username); } return result; }
public boolean DDcheckStatus(int memberid, String te_username, String session) { boolean result = false; String status = ""; JSONObject response, post; String api = API1 + te_username + API2; // String api = "http://192.168.2.132:5000"; String url = api + CHECKDDSTATUS; post = new JSONObject(); try { post.put("userid", memberid); session = (session == null) ? this.session_token : session; post.put("session", session); } catch (JSONException e) { e.printStackTrace(); return result; } response = this.postJSON(url, post); if (response == null) { errormsg = "Server not responding."; errorcode = JSONError.NORESPONSE.getKey(); return result; } try { status = response.getString("ddstatus"); } catch (JSONException e) { status = "bad"; errormsg = "Server not responding"; errorcode = JSONError.NORESPONSE.getKey(); } if (status.compareTo("bad") == 0) { try { errormsg = response.getString("message"); } catch (JSONException e) { errormsg = "No Response"; } errorcode = JSONError.INVALIDINPUT.getKey(); } else { try { result = true; this.session_token = response.getString("session"); } catch (JSONException e) { /*probably doesn't matter.*/ } } return result; }