예제 #1
0
        public IActionResult Index()
        {
            var api = new HackerNewsApi();
            List <HackerNews> hn = api.Get20News();

            return(View(hn));
        }
예제 #2
0
        public void CanNotPassNegativeToTopStories()
        {
            HackerNewsApi client             = new HackerNewsApi();
            IEnumerable <HackerNewsItem> ids = client.TopStories(-1);

            Assert.IsTrue(ids.Count() == 0);
        }
예제 #3
0
        public void CanAskForInvalidItem()
        {
            HackerNewsApi  client = new HackerNewsApi();
            HackerNewsItem item   = client.NewsItem(int.MaxValue).Result;

            Assert.IsTrue(item == null);
        }
예제 #4
0
        public void CanGetMaxTopStories()
        {
            HackerNewsApi client             = new HackerNewsApi();
            IEnumerable <HackerNewsItem> ids = client.TopStories(105);

            Assert.IsTrue(ids.Count() == 100);
        }
예제 #5
0
        public void CanGetTopStoryIds()
        {
            HackerNewsApi     client = new HackerNewsApi();
            IEnumerable <int> ids    = client.TopStoryIds().Result;

            Assert.IsTrue(ids.Any());
        }
예제 #6
0
        public void CanGetStory()
        {
            HackerNewsApi  client    = new HackerNewsApi();
            HackerNewsItem storyItem = client.NewsItem(GOOD_STORY_ID).Result;

            Assert.IsNotNull(storyItem);
        }
예제 #7
0
        public void CanGetUserProfile()
        {
            HackerNewsApi         client      = new HackerNewsApi();
            HackerNewsUserProfile userProfile = client.UserProfile(GOOD_USER_ID).Result;

            Assert.IsNotNull(userProfile);
        }
예제 #8
0
        public void CanGetTopStories()
        {
            HackerNewsApi client             = new HackerNewsApi();
            IEnumerable <HackerNewsItem> ids = client.TopStories(2);

            Assert.IsTrue(ids.Count() == 2);
            Assert.IsTrue(ids.ElementAt(0) != null);
            Assert.IsTrue(ids.ElementAt(1) != null);
        }
예제 #9
0
        static void Main(string[] args)
        {
            var api = new HackerNewsApi();
            IEnumerable <HackerNewsItem> stories = api.TopStories(20);

            foreach (var item in stories)
            {
                Console.WriteLine(item.Title + " " + item.Score);
            }

            Console.ReadKey(true);
        }
예제 #10
0
        public ActionResult Index()
        {
            var api = new HackerNewsApi();

            return(View(api.GetTopStories(20)));
        }
예제 #11
0
        public void Load()
        {
            HackerNewsApi api = new HackerNewsApi();

            ErrorMessage = "";
            IsLoading = true;
            api.GetComments(Post.Item_ID, (comments) =>
            {
                comments = OrderComments(comments);
                Comments = new BindableCollection<CommentItem>(comments);
                IsLoading = false;
            }, (error) =>
            {
                IsLoading = false;
            });
        }
예제 #12
0
        public MainPage()
        {
            InitializeComponent();

            _apiClient = new HackerNewsApi();
        }
        public void Load()
        {
            ErrorMessage = "";
            Posts.Clear();
            IsLoading = true;
            HackerNewsApi api = new HackerNewsApi();
            api.GetPosts(PostType, (posts) =>
            {
                // last item is a reference to the next page, could fix by specifying a page (or use this with a "more" button)
                posts.RemoveAt(posts.Count - 1);

                // used to make the object know how to navigate... // hack
                foreach (PostItem post in posts)
                {
                    post.NavigationService = _navigationService;
                }

                Posts = new BindableCollection<PostItem>(posts);
                IsLoading = false;
            }, (error) =>
            {
                ErrorMessage = error;
                IsLoading = false;
            });
        }