private IEnumerator PostSurveyResponseInternal(SurveyResponse surveyResponse, Action <CallbackResponse> completed) { string json = JsonUtility.ToJson(surveyResponse); //Debug.Log(json); using (UnityWebRequest www = Utilities.BuildInGameSurveyAPIWebRequest(PostSurveyResponseUrl, HttpMethod.Post.ToString(), json)) { yield return(www.Send()); if (Globals.DebugFlag) { Debug.Log(www.responseCode); } var response = new CallbackResponse(); if (Utilities.IsWWWError(www)) { if (Globals.DebugFlag) { Debug.Log(www.error); } Utilities.BuildResponseObjectOnFailure(response, www); } completed(response); } }
public static void BuildResponseObjectOnFailure(CallbackResponse response, UnityWebRequest www) { if (www.responseCode == 404L) { response.Status = CallBackResult.NotFound; } else if (www.responseCode == 409L) { response.Status = CallBackResult.ResourceExists; } else { response.Status = CallBackResult.Failure; } string errorMessage = www.error; if (errorMessage == null && www.downloadHandler != null && !string.IsNullOrEmpty(www.downloadHandler.text)) { errorMessage = www.downloadHandler.text; } else { errorMessage = Globals.ErrorOccurred; } Exception ex = new Exception(errorMessage); response.Exception = ex; }
private IEnumerator GetSurveys(string url, Action <CallbackResponse <Survey[]> > callback) { using (UnityWebRequest www = Utilities.BuildInGameSurveyAPIWebRequest (GetSurveysUrl, HttpMethod.Get.ToString(), null)) { yield return(www.Send()); if (Globals.DebugFlag) { Debug.Log(www.responseCode); } var response = new CallbackResponse <Survey[]>(); if (Utilities.IsWWWError(www)) { if (Globals.DebugFlag) { Debug.Log(www.error); } Utilities.BuildResponseObjectOnFailure(response, www); } else { try { Survey[] surveys = JsonHelper.GetJsonArray <Survey>(www.downloadHandler.text); foreach (var survey in surveys) { survey.questions = JsonHelper.GetJsonArray <Question>(survey.data); } response.Result = surveys; response.Status = CallBackResult.Success; } catch (Exception ex) { response.Status = CallBackResult.DeserializationFailure; response.Exception = ex; } } callback(response); } }
public static void BuildResponseObjectOnException(CallbackResponse response, Exception ex) { response.Status = CallBackResult.LocalException; response.Exception = ex; }