public IEnumerator Update <T>(T item, Action <IRestResponse <T> > callback = null) where T : new() { string id = null; // Check if item uses the 'IDataModel' Interface to get 'id' property, otherwise try Refelection (using Reflection helper). IDataModel model = item as IDataModel; if (model != null) { id = model.GetId(); } else if (ReflectionHelper.HasField(item, "id")) { var x = ReflectionHelper.GetField(item, "id"); id = x.GetValue(item) as string; } else { Debug.LogError("Unable to get 'id' data model property"); } if (string.IsNullOrEmpty(id)) { Debug.LogError("Error 'id' value is missing"); yield return(null); } string url = TableUrl(_name, id); ZumoRequest request = new ZumoRequest(url, Method.PATCH, true, _client.User); request.AddBody(item); Debug.Log("Update Request Url: " + url + " patch:" + item); yield return(request.Request.Send()); request.ParseJson <T>(callback); }
public IEnumerator Lookup <T>(string id, Action <IRestResponse <T> > callback = null) where T : new() { string url = TableUrl(_name, id); ZumoRequest request = new ZumoRequest(url, Method.GET, true, _client.User); Debug.Log("Lookup Request Url: " + url); yield return(request.Request.Send()); request.ParseJson <T>(callback); }
public IEnumerator Insert <T>(T item, Action <IRestResponse <T> > callback = null) where T : new() { string url = TableUrl(_name); ZumoRequest request = new ZumoRequest(url, Method.POST, true, _client.User); Debug.Log("Insert Request: " + url); request.AddBody(item); yield return(request.Request.Send()); request.ParseJson <T>(callback); }
/// <summary> /// Invokes custom API for HTTP Methods: GET, POST, PUT, PATCH, DELETE /// </summary> public IEnumerator InvokeApi <T>(string apiName, Method httpMethod, Action <IRestResponse <T> > callback = null) where T : new() { string url = ApiUrl(apiName); Debug.Log(httpMethod.ToString() + " custom API Request Url: " + url); ZumoRequest request = new ZumoRequest(url, httpMethod, true, User); yield return(request.Request.SendWebRequest()); request.ParseJson <T>(callback); }
private void LoggedIn(ZumoRequest request, Action <IRestResponse <AuthenticatedUser> > callback = null) { string message = request.Request.downloadHandler.text; IRestResponse <AuthenticatedUser> response = request.ParseJson <AuthenticatedUser>(); if (!response.IsError) { User = response.Data; if (callback != null) { callback(response); } } else { Debug.LogWarning("Login error message:" + message); } request.Dispose(); }