static IEnumerator WaitForRequest(UnityWebRequest data, System.Action <string> handler) { yield return(data.SendWebRequest()); if (data.error != null) { Enjin.IsRequestValid(data.responseCode, data.downloadHandler.text); queryStatus = Status.Error; } else { if (Enjin.IsRequestValid(data.responseCode, data.downloadHandler.text)) { queryReturn = data.downloadHandler.text; queryStatus = Status.Complete; if (Enjin.IsDebugLogActive) { Debug.Log("<color=orange>[GRAPHQL RESULTS]</color> " + queryReturn); } handler(queryReturn); } else { queryReturn = "ERROR"; } } //OnQueryComplete(); }
public static void POST(string details, string token, bool async, System.Action <string> handler) { details = details.Trim('\r'); details = QuerySorter(details); string jsonData = ""; Query query = new Query { query = details }; jsonData = JsonUtility.ToJson(query); if (Enjin.IsDebugLogActive) { if (!jsonData.Contains("password:"******"access_tokens:")) { Debug.Log("<color=orange>[GRAPHQL QUERY]</color> " + jsonData); } } UnityWebRequest request = UnityWebRequest.Post(Enjin.GraphQLURL, UnityWebRequest.kHttpVerbPOST); request.uploadHandler = new UploadHandlerRaw(Encoding.UTF8.GetBytes(jsonData)) as UploadHandler; request.SetRequestHeader("Content-Type", "application/json; charset=utf-8"); if (token == "") { request.SetRequestHeader("X-App-Id", Enjin.AppID.ToString()); } if (token != "login") { request.SetRequestHeader("Authorization", "Bearer " + Enjin.AccessToken); } request.downloadHandler = new DownloadHandlerBuffer(); if (request.error != null) { Enjin.IsRequestValid(request.responseCode, request.downloadHandler.text); } else { if (async) { instance.StartCoroutine(WaitForRequest(request, handler)); queryStatus = Status.Loading; } else if (!async) { request.SendWebRequest(); while (!request.isDone) { } if (Enjin.IsRequestValid(request.responseCode, request.downloadHandler.text)) { queryStatus = Status.Complete; queryReturn = request.downloadHandler.text; } } } // NOTE: Turn this conversion on once methods are updated to support this structure //queryReturn = Regex.Replace(queryReturn, @"(""[^""\\]*(?:\\.[^""\\]*)*"")|\s+", "$1"); if (Enjin.IsDebugLogActive && queryReturn != null) { Debug.Log("<color=orange>[GRAPHQL RESULTS]</color> " + queryReturn.ToString()); } }