protected IEnumerator _GetToken(AccessTypes accessTypes, Dictionary <string, string> headers, WebObjectEvent returnStringEvent) { var path = url + "/" + accessPath[accessTypes]; var connection = UnityEngine.Networking.UnityWebRequest.Post(path, headers); //WWW connection = new WWW(path, form); yield return(connection.Send()); if (connection.isError) { Debug.LogError("Error: " + connection.error); _idsController.CallAction(errorIdCall); yield break; } var webres = JsonConvert.DeserializeObject <WebObject>(connection.downloadHandler.text); /* * if (webres.err!= null && !string.IsNullOrEmpty(webres.err.error)) * { * Debug.LogError("Error: " + webres.err.error); * _idsController.CallAction(errorIdCall); * if (OnError != null) OnError(webres.err.error); * yield break; * } * /**/ token = webres.token; returnStringEvent(webres); if (OnTokenGet != null) { OnTokenGet(); } if (OnGet != null) { OnGet(webres); } }
protected IEnumerator _GetJson(AccessTypes accessTypes, WebObjectEvent returnStringEvent) { var path = url + "/" + accessPath[accessTypes]; var headers = new Dictionary <string, string>(); headers["Authorization"] = "Bearer " + token; WWW connection = new WWW(path, null, headers); yield return(connection); object webres = null; switch (accessTypes) { case AccessTypes.Users: try { webres = JsonConvert.DeserializeObject <List <WebUser> >(connection.text); } catch (Exception) { Debug.LogError("Error: "); } var users = webres as List <WebUser>; if (webres == null) { webres = JsonConvert.DeserializeObject <WebObject>(connection.text); var error = webres as WebObject; Debug.LogError("Error: " + error.err.error); _idsController.CallAction(errorIdCall); if (OnError != null) { OnError(error.err.error); } yield break; } var usersWebObj = users.Select(webUser => new WebObject(webUser)).ToList(); for (int webObject = 0, n = usersWebObj.Count; webObject < n; webObject++) { returnStringEvent(usersWebObj[webObject]); if (OnGet != null) { OnGet(usersWebObj[webObject]); } } break; case AccessTypes.User: webres = JsonConvert.DeserializeObject <WebUser>(connection.text); var user = webres as WebUser; if (string.IsNullOrEmpty(user.err.error)) { Debug.LogError("Error: " + user.err.error); _idsController.CallAction(errorIdCall); if (OnError != null) { OnError(user.err.error); } yield break; } var userWebObj = new WebObject(user); returnStringEvent(userWebObj); if (OnGet != null) { OnGet(userWebObj); } break; case AccessTypes.Score: Debug.LogError("Not Implemented"); break; case AccessTypes.Question: Debug.LogError("Not Implemented"); break; default: Debug.LogError("Out of Arguments - Not Implemented"); break; } }
public void GetToken(AccessTypes accessTypes, Dictionary <string, string> headers, WebObjectEvent returnStringEvent) { StartCoroutine(_GetToken(accessTypes, headers, returnStringEvent)); }
public void GetJson(AccessTypes accessTypes, WebObjectEvent returnStringEvent) { StartCoroutine(_GetJson(accessTypes, returnStringEvent)); }