public object RxBuildRequest <T>(UniRx.IObserver <T> o, Converter.Converter convert, RestMethodInfo methodInfo, string url) { Action <HttpResponseMessage <string> > responseMessage = message => { string errorMessage = ""; if (IsRequestError(message, out errorMessage)) { o.OnError(new Exception(errorMessage)); return; } string result = GetSuccessResponse(message); // result = "[]"; // result = "[asd..s]"; if (EnableDebug) { Debug.LogFormat("Raw Response:{0}", result); } //Parse Json By Type if (typeof(T) == typeof(string)) { var resultData = (T)(object)result; o.OnNext(resultData); o.OnCompleted(); return; } T data = default(T); bool formatError = false; try { data = convert.FromBody <T>(result); } catch (ConversionException e) { formatError = true; o.OnError(new Exception(e.Message)); } if (!formatError) { o.OnNext(data); o.OnCompleted(); } }; HttpClientRequest httpClientRequest = new HttpClientRequest(new Uri(url), responseMessage); ConfigureRESTfulApi(methodInfo, httpClientRequest); return(httpClientRequest); }
protected IEnumerator Request <T>(RestMethodInfo methodInfo, string url, object[] arguments, Callback <T> cb) { object request = httpImpl.BuildRequest(methodInfo, url); InterceptRequest(request); CoroutineWithData cd = new CoroutineWithData(this, httpImpl.SendRequest(this, request)); yield return(cd.coroutine); string errorMessage; if (httpImpl.IsRequestError(cd.result, out errorMessage)) { cb.errorCB(errorMessage); yield break; } string result = httpImpl.GetSuccessResponse(cd.result); // result = "[]"; // result = "[asd..s]"; Log("Response:" + result); //Parse Json By Type if (typeof(T) == typeof(string)) { var response = (T)(object)result; cb.successCB(response); yield break; } T data = default(T); bool formatError = false; try { data = convert.FromBody <T>(result); } catch (ConversionException e) { formatError = true; cb.errorCB(e.Message); } if (!formatError) { cb.successCB(data); } }