public DebugRequestEvents(CompositeDisposable compositeDisposable, Request <T> request, int id) : base() { #if UNITY_EDITOR OnSuccess.Subscribe(x => DebugFormat.Log <Request <T> >($"[{request.RESTMethod}] {id} - OnSuccess\n\n{JsonConvert.SerializeObject(x, Formatting.Indented)}\n", deep: DEEP)).AddTo(compositeDisposable); OnSuccessRaw.Subscribe(x => DebugFormat.Log <Request <T> >($"[{request.RESTMethod}] {id} - OnSuccessRaw\n\n{Request<T>.JsonPrettify(x)}\n", deep: DEEP)).AddTo(compositeDisposable); #endif OnSerializationError.Subscribe(x => DebugFormat.LogError <Request <T> >($"[{request.RESTMethod}] {id} - OnSerializationError: {x}", deep: DEEP)).AddTo(compositeDisposable); OnHttpError.Subscribe(x => DebugFormat.LogError <Request <T> >($"[{request.RESTMethod}] {id} - OnHttpError\n\n {JsonConvert.SerializeObject(x, Formatting.Indented)}\n", deep: DEEP)).AddTo(compositeDisposable); OnHttpErrorRaw.Subscribe(x => DebugFormat.LogError <Request <T> >($"[{request.RESTMethod}] {id} - OnHttpErrorRaw\n\n{x}\n", deep: DEEP)).AddTo(compositeDisposable); OnNetworkError.Subscribe(x => DebugFormat.LogError <Request <T> >($"[{request.RESTMethod}] {id} - OnNetworkError\n\n {JsonConvert.SerializeObject(x, Formatting.Indented)}\n", deep: DEEP)).AddTo(compositeDisposable); }
public IEnumerator PagedRequest(int per_page, string api_path) { int page = 1; JSONNode data = JSONNode.Parse("[]"); string response = null; JSONNode responseJSON = null; do { UnityWebRequest request = UnityWebRequest.Get(API_URL + api_path + "&page=" + page + "&per_page=" + per_page); PrepareHeaders(request); yield return(VimeoApi.SendRequest(request)); if (request.error != null) { if (request.responseCode == 401) { SendError("401 Unauthorized request. Are you using a valid token?", request.downloadHandler.text); } else if (IsNetworkError(request)) { Debug.LogError("[VimeoApi] It seems like you are not connected to the internet or are having connection problems."); OnNetworkError?.Invoke(request.error); } else { if (page > 1) { // It's OK, make it the end of pages Debug.LogWarning("[VimeoApi] Paged request error for url " + request.url + ", at page #" + page + ", error: " + request.error + ", " + request.downloadHandler.text); break; } else { SendError(request.url + " - " + request.downloadHandler.text, request.downloadHandler.text); } } yield break; } response = request.downloadHandler.text; responseJSON = JSONNode.Parse(response); JSONNode pageData = responseJSON["data"]; for (int i = 0; i < pageData.Count; i++) { JSONNode element = pageData[i]; data.Add(element); } if (pageData.Count < per_page) { break; } page++; }while (true); if (responseJSON != null) { responseJSON.Remove("data"); responseJSON.Add("data", data); } OnRequestComplete?.Invoke(responseJSON.ToString()); }