/// <summary> /// Saves the authentication token channels permissions in the ORTC server. /// </summary> public UnityTask <bool> PostAuthentication() { #region Sanity Checks if (String.IsNullOrEmpty(Url)) { return(UnityTask.FailedTask <bool>(new OrtcException(OrtcExceptionReason.InvalidArguments, "URL is null or empty."))); } if (String.IsNullOrEmpty(ApplicationKey)) { return(UnityTask.FailedTask <bool>(new OrtcException(OrtcExceptionReason.InvalidArguments, "Application Key is null or empty."))); } if (String.IsNullOrEmpty(AuthenticationToken)) { return(UnityTask.FailedTask <bool>(new OrtcException(OrtcExceptionReason.InvalidArguments, "Authentication Token is null or empty."))); } if (String.IsNullOrEmpty(PrivateKey)) { return(UnityTask.FailedTask <bool>(new OrtcException(OrtcExceptionReason.InvalidArguments, "Private Key is null or empty."))); } if (Permissions != null && Permissions.Count == 0) { return(UnityTask.FailedTask <bool>(new OrtcException(OrtcExceptionReason.InvalidArguments, "No permissions set."))); } #endregion return(UnityTask.RunCoroutine <bool>(PostAuthenticationAsync)); }
/// <summary> /// Sends a message to a channel. /// </summary> public UnityTask <bool> SendMessage() { if (String.IsNullOrEmpty(Url)) { UnityTask.FailedTask <bool>(new OrtcException(OrtcExceptionReason.InvalidArguments, "Server URL can not be null or empty.")); } return(UnityTask.RunCoroutine <bool>(SendMessageAsync)); }
/// <summary> /// Returns your current score /// </summary> /// <returns></returns> public UnityTask <GameScore> Self() { if (!IsAuthenticated) { return(UnityTask.FailedTask <GameScore>("Not authenticated")); } return(HttpPostAsync <GameScore>("Self")); }
/// <summary> /// Posts the score to the server /// </summary> /// <typeparam name="T"></typeparam> /// <param name="entity"></param> /// <returns></returns> public UnityTask Update(GameScore entity) { if (!IsAuthenticated) { return(UnityTask.FailedTask <GameScore>("Not authenticated")); } return(HttpPostAsync("Update", entity)); }
/// <summary> /// Posts the HTTP request to the server /// </summary> /// <param name="method">controller method to call</param> /// <returns>Metadata</returns> public UnityTask HttpPostAsync(string method) { if (!Config.IsValid) { return(UnityTask.FailedTask("Invalid configuration.")); } if (Application.internetReachability == NetworkReachability.NotReachable) { return(UnityTask.FailedTask("Internet not reachable.")); } var action = string.Format("api/{0}/{1}", ControllerName, method); var url = Config.Path.EndsWith("/") ? Config.Path + action : Config.Path + "/" + action; return(Client.PostAsync(url)); }
/// <summary> /// Posts the HTTP request to the server /// </summary> /// <typeparam name="T">return type</typeparam> /// <param name="method">controller method to call</param> /// <param name="entity">dto</param> /// <returns>response of type T</returns> public UnityTask <T> HttpPostAsync <T>(string method, object entity) where T : class { if (!Config.IsValid) { return(UnityTask.FailedTask <T>("Invalid configuration.")); } if (Application.internetReachability == NetworkReachability.NotReachable) { return(UnityTask.FailedTask <T>("Internet not reachable.")); } var action = string.Format("api/{0}/{1}", ControllerName, method); var url = Config.Path.EndsWith("/") ? Config.Path + action : Config.Path + "/" + action; return(Client.PostAsync <T>(url, JsonSerializer.Serialize(entity))); }
/// <summary> /// Posts a get request against a IQueryable OData data source /// </summary> /// <typeparam name="T">return type</typeparam> /// <param name="prefix">prefix to odata query</param> /// <param name="query">odata query</param> /// <returns>found entity array of type T</returns> public UnityTask <T[]> HttpPostAsync <T>(string prefix, ODataQuery <T> query) where T : class { if (!Config.IsValid) { return(UnityTask.FailedTask <T[]>("Invalid configuration.")); } if (Application.internetReachability == NetworkReachability.NotReachable) { return(UnityTask.FailedTask <T[]>("Internet not reachable.")); } var action = string.Format("api/{0}/Query/{1}{2}", ControllerName, prefix, query); var url = Config.Path.EndsWith("/") ? Config.Path + action : Config.Path + "/" + action; return(Client.PostAsync <T[]>(url)); }