Ejemplo n.º 1
0
        public TemperatureStatistics Get([FromUri] string cityname)
        {
            TemperatureStatistics info = null;

            string key = (Request.Headers.Contains("Authorization") ? Request.Headers.GetValues("Authorization").FirstOrDefault() : string.Empty);

            if (!key.Equals(Constants.ConstValues.SECURITY_KEY))
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Chave inválida."));
            }


            Utils.SqlServer sql = new Utils.SqlServer();
            info = sql.GetStatisticsByCity(cityname);

            if (sql.Error.Length > 0)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, sql.Error));
            }

            if (info == null)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Sem estatísticas para esta cidade."));
            }

            return(info);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Metodo para que a api do spotyfy devolva o token e na sequencia ele eh salvo em banco
        /// </summary>
        /// <param name="id"></param>
        /// <param name="key"></param>
        /// <param name="code"></param>
        public void Get(int id, [QueryString] string key, [QueryString] string code)
        {
            if (!key.Equals(Constants.ConstValues.SECURITY_KEY))
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Chave inválida."));
            }

            if (id == 99) //valor configurado na plataforma o SPOTIFY
            {
                Utils.SqlServer sql = new Utils.SqlServer();
                if (!sql.SaveSpotifyCode(code))
                {
                    throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, sql.Error));
                }
            }
            else
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.Forbidden, "Id Inválido."));
            }
        }