private IEnumerator GetStuffSingle<T>(string url, Action<CallbackResponse<T>> callback)
 {
     using (UnityWebRequest www = Utilities.BuildScoresAPIWebRequest
         (GetLeaderboardsAPIURL() + url, HttpMethod.Get.ToString(), null, userID, username))
     {
         yield return www.Send();
         if (Globals.DebugFlag) Debug.Log(www.responseCode);
         CallbackResponse<T> response = new CallbackResponse<T>();
         if (Utilities.IsWWWError(www))
         {
             if (Globals.DebugFlag) Debug.Log(www.error);
             Utilities.BuildResponseObjectOnFailure(response, www);
         }
         else
         {
             try
             {
                 T data = JsonUtility.FromJson<T>(www.downloadHandler.text);
                 response.Result = data;
                 response.Status = CallBackResult.Success;
             }
             catch (Exception ex)
             {
                 response.Status = CallBackResult.DeserializationFailure;
                 response.Exception = ex;
             }
         }
         callback(response);
     }
 }
        private IEnumerator PostScoreInternal(Score instance, Action<CallbackResponse<User>> onInsertCompleted)
        {
            string json = JsonUtility.ToJson(instance);

            using (UnityWebRequest www = Utilities.BuildScoresAPIWebRequest(GetLeaderboardsAPIURL() + "scores",
                HttpMethod.Post.ToString(), json, userID, username))
            {
                yield return www.Send();
                if (Globals.DebugFlag) Debug.Log(www.responseCode);

                CallbackResponse<User> response = new CallbackResponse<User>();

                if (Utilities.IsWWWError(www))
                {
                    if (Globals.DebugFlag) Debug.Log(www.error);
                    Utilities.BuildResponseObjectOnFailure(response, www);
                }

                else if (www.downloadHandler != null)  //all OK
                {
                    //let's get the new object that was created
                    try
                    {
                        User newObject = JsonUtility.FromJson<User>(www.downloadHandler.text);
                        if (Globals.DebugFlag) Debug.Log("new object is " + newObject.ToString());
                        response.Status = CallBackResult.Success;
                        response.Result = newObject;
                    }
                    catch (Exception ex)
                    {
                        response.Status = CallBackResult.DeserializationFailure;
                        response.Exception = ex;
                    }
                }
                onInsertCompleted(response);
            }
        }
        private IEnumerator GetStuffArray<T>(string url, int skipCount, Action<CallbackResponse<T[]>> callback)
        {
            string fullurl = GetLeaderboardsAPIURL() + url;
            if (skipCount < 0)
                throw new ArgumentException("skipCount cannot be less than zero");
            else if (skipCount > 0)
                fullurl += "?skip=" + skipCount;

            using (UnityWebRequest www = Utilities.BuildScoresAPIWebRequest
                (fullurl, HttpMethod.Get.ToString(), null, userID, username))
            {
                yield return www.Send();
                if (Globals.DebugFlag) Debug.Log(www.responseCode);
                var response = new CallbackResponse<T[]>();
                if (Utilities.IsWWWError(www))
                {
                    if (Globals.DebugFlag) Debug.Log(www.error);
                    Utilities.BuildResponseObjectOnFailure(response, www);
                }
                else
                {
                    try
                    {
                        T[] data = JsonHelper.GetJsonArray<T>(www.downloadHandler.text);
                        response.Result = data;
                        response.Status = CallBackResult.Success;
                    }
                    catch (Exception ex)
                    {
                        response.Status = CallBackResult.DeserializationFailure;
                        response.Exception = ex;
                    }
                }
                callback(response);
            }
        }