Exemple #1
0
        public HttpResponseMessage Get(string domain)
        {
            try
            {
                //Call Reddit
                RedditReader reddit = new RedditReader();
                var          result = reddit.Get();

                // Save to db
                RootReddit root = new RootReddit();
                root.data = result.data;
                root.kind = result.kind;
                db.RootReddits.Add(root);
                db.SaveChanges();

                //read & format DB
                var itemsbyauthors = from items in db.NewsItems
                                     where items.domain == domain
                                     group items by items.author into g
                                     select new AuthorModel {
                    author = g.Key, items = g.Select(p => new AuthorItem {
                        Id = p.redditid, CreatedDate = p.createdDate, Title = p.title, Permalink = p.permalink
                    }).ToList()
                };

                return(Request.CreateResponse(HttpStatusCode.OK, itemsbyauthors));
            }
            catch (Exception ex) {
                //TODO better error handling
                return(Request.CreateResponse(HttpStatusCode.ServiceUnavailable, "An error occured during the request: " + ex.Message));
            }
        }
Exemple #2
0
        public void RedditAPI()
        {
            RedditReader rp = new RedditReader();

            var result = rp.Get();

            //Assert 100 items
            Assert.IsNotNull(result);
            Assert.AreEqual(100, result.data.children.Count());
        }