Ejemplo n.º 1
0
        internal async Task <bool> SendMessageAsync(string content, int userid)
        {
            try
            {
                JSONRepresentations.Post.Message m = new JSONRepresentations.Post.Message()
                {
                    message = content,
                    to      = userid
                };

                SparklrResponse <string> result = await webClient.PostJsonAsyncRawResponse("chat", m);

                if (result.IsOkAndTrue())
                {
                    return(true);
                }
                else if (result.Code == System.Net.HttpStatusCode.BadRequest)
                {
                    throw new ArgumentException("The message you wanted to send was not accepted by the server, maybe it was too long?", content);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exceptions.NotAuthorizedException)
            {
                throw new Exceptions.NotAuthorizedException("You are either not authorized or blocked by the specified user.");
            }
        }
        public async Task <bool> SigninAsync(string username, string password)
        {
            try
            {
                SparklrResponse <string> response = await webClient.GetRawResponseAsync("signin", username, password);

                if (response.IsOkAndTrue())
                {
                    Authenticated = true;
                    return(true);
                }
                else
                {
                    Authenticated = false;
                    return(false);
                }
            }
            catch (NotAuthorizedException)
            {
                Authenticated = false;
                return(false);
            }
        }
        /// <summary>
        /// Checks if sparklr is running
        /// </summary>
        /// <returns>true if it is, otherwise false</returns>
        public async Task <bool> GetAwakeAsync()
        {
            SparklrResponse <string> response = await webClient.GetRawResponseAsync("areyouawake");

            return(response.IsOkAndTrue());
        }