Exemplo n.º 1
0
        public async Task <ActionResult <Response> > GetAsync(string subreddit)
        {
            HttpContext.Request.Headers.TryGetValue("AccessToken", out var accessToken);

            if (string.IsNullOrEmpty(accessToken.ToString()))
            {
                return(new UnauthorizedResult());
            }

            WebAgent agent    = new WebAgent(accessToken, _userAgent);
            var      request  = agent.CreateRequest(subreddit);
            var      response = await agent.GetResponseAsync(request);

            if (!response.IsSuccessStatusCode)
            {
                return(new StatusCodeResult((int)response.StatusCode));
            }

            var jsonString = await response.Content.ReadAsStringAsync();

            var content = JsonConvert.DeserializeObject <List <Root> >(jsonString);


            return(new JsonResult(
                       ResponseFactory.CreateResponseFromPost(content?[0].Data.Children[0].Post),
                       _jsonSettings
                       ));
        }