Пример #1
0
  public void processSignUp(String username, String password, String email, String charity) {
    email = "fakeEmail";
    String URL = "http://45.33.62.187/api/v1/player/?format=json";
    String Body =
        ""
            + "{"
            + "   \"charity\": \"/api/v1/charity/"
            + charity
            + "/\","
            + "   \"email\": \""
            + email
            + "\","
            + "   \"username\": \""
            + username
            + "\","
            + "   \"username_hash\": \""
            + sha256(username)
            + "\","
            + "   \"password_hash\": \""
            + sha256(password)
            + "\","
            + "   \"wins\": 0,"
            + "   \"losses\": 0"
            + "}";

    String results =
        apiCall.httpPostPutOrPatch(
            URL,
            Body,
            httpReturns.size(),
            false,
            false); // makes the first call to insert player to table

    // below gets the userID from another query, then posts that to the matchmaking table
    String url =
        "http://45.33.62.187/api/v1/player/?username_hash="
            + sha256(username)
            + "&password_hash="
            + sha256(password)
            + "&format=json";
    String getPlayer = apiCall.httpGet(url, httpReturns.size());

    if (getPlayer.equalsIgnoreCase("FAILED")
        || getPlayer.equalsIgnoreCase("CANCELLED")
        || getPlayer.equalsIgnoreCase("EMPTY")) {
      // menuComponents.add(3, new MenuComponent(300, 400, 100, 50, Assets.menuFailedRegion));
    } else {
      JSONObject json = new JSONObject(getPlayer);
      JSONArray playerArray = json.getJSONArray("objects");
      JSONObject player0 = playerArray.getJSONObject(0);
      int id = player0.getInt("id");

      // post to matchmaking
      URL = "http://45.33.62.187/api/v1/matchmaking/?format=json";
      Body =
          ""
              + "{"
              + "   \"player\": \"/api/v1/player/"
              + id
              + "/\","
              + "   \"match\": null,"
              + "   \"waiting\": false"
              + "}";

      results = apiCall.httpPostPutOrPatch(URL, Body, httpReturns.size(), false, false);
      // end post to matchmaking

    }
    // end get playerID
  }