Пример #1
0
        /// <summary>
        /// Returns latest tweets for a given user.
        /// </summary>
        /// <param name="username">User name.</param>
        /// <param name="cacheFor">Cache duration.</param>
        /// <returns>Latest tweets for a given user.</returns>
        public static IEnumerable <string> GetTweets(string username, TimeSpan?cacheFor = null)
        {
            string html = string.Empty;
            IEnumerable <string> ret = null;

            if (!WebSource.TryGetFromCache(username, cacheFor, out ret))
            {
                try
                {
                    using (var client = new WebSource.SpecializedWebClient())
                        html = client.DownloadString(string.Format("https://mobile.twitter.com/{0}", username));

                    WebSource.AddToCache(username, cacheFor, ret = ParseTweets(html));
                }
                catch (System.Net.WebException) { WebSource.AddToCache(username, cacheFor, new List <string>()); }
            }

            if (ret == null)
            {
                ret = Enumerable.Empty <string>();
            }

            return(ret);
        }
Пример #2
0
        /// <summary>
        /// Returns latest RSS items for a given URL.
        /// </summary>
        /// <param name="URL">RSS feed URL.</param>
        /// <param name="cacheFor">Cache duration.</param>
        /// <returns>Latest items for a given URL.</returns>
        public static IEnumerable <RssFeedItem> GetItems(string url, TimeSpan?cacheFor = null)
        {
            string xml = string.Empty;
            IEnumerable <RssFeedItem> ret = null;

            if (!WebSource.TryGetFromCache(url, cacheFor, out ret))
            {
                try
                {
                    using (var client = new WebSource.SpecializedWebClient())
                        xml = client.DownloadString(url);

                    WebSource.AddToCache(url, cacheFor, ret = ParseItems(xml));
                }
                catch (System.Net.WebException) { WebSource.AddToCache(url, cacheFor, new List <RssFeedItem>()); }
            }

            if (ret == null)
            {
                ret = Enumerable.Empty <RssFeedItem>();
            }

            return(ret);
        }