示例#1
0
    /// <summary>
    /// Coroutine that sends a web request to the API and receives a list of matches with given gameToken.
    /// A filter is sent to specify what types of matches to GET.
    /// A callback is also sent which is used to send the retrieved matches back.
    /// </summary>
    /// <param name="filter">The enum specifying how to filter the matches that are to be acquired.</param>
    /// <param name="callback">The callback we want to send the retrieved matches to</param>
    /// <param name="matchSearchName">The name of the match we want to search for in the case that filter is GETRequestFilters.byName</param>
    private IEnumerator GETMatches(GETRequestFilters filter, System.Action <KJAPP.JSONObjects.Match.BaseResponse[]> callback, string matchSearchName = "")
    {
        var apiEndpoint = "";

        switch (filter)
        {
        case GETRequestFilters.noFilter:
            apiEndpoint = "/matches/no_body/" + gameToken;
            break;

        case GETRequestFilters.inSession:
            apiEndpoint = "/matches/in_session/no_body/" + gameToken;
            break;

        case GETRequestFilters.notInSession:
            apiEndpoint = "/matches/not_in_session/no_body/" + gameToken;
            break;

        case GETRequestFilters.notFull:
            apiEndpoint = "/matches/not_full/no_body/" + gameToken;
            break;

        case GETRequestFilters.withName:
            apiEndpoint = "/matches/with_name/no_body/" + gameToken + "/" + matchSearchName;
            break;

        default:
            apiEndpoint = "/matches/no_body/" + gameToken;
            break;
        }

        var webRequest = UnityWebRequest.Get(apiUrl + apiEndpoint);

        yield return(webRequest.Send());

        if (webRequest.isNetworkError)
        {
            Debug.Log(webRequest.error);
        }
        else
        {
            var jsonString = webRequest.downloadHandler.text;
            var matches    = JsonHelper.getJsonArray <KJAPP.JSONObjects.Match.BaseResponse>(jsonString);
            callback(matches);
        }
    }
示例#2
0
 /// <summary>
 /// Public method for starting the process of displaying matches.
 /// </summary>
 /// <param name="filter">What type of filter we want to apply to the request.</param>
 /// <param name="callback">The callback that receives the array of matches.</param>
 /// <param name="withName">Default parameter that is set to "". Used whenever filter is set to GETRequestFilters.withName</param>
 public void RequestMatches(GETRequestFilters filter, System.Action <KJAPP.JSONObjects.Match.BaseResponse[]> callback, string withName = "")
 {
     StartCoroutine(GETMatches(filter, callback, withName));
 }