/// <summary> /// Returns a task which retrieves latest tweets for a given user. /// </summary> /// <param name="username">User name.</param> /// <param name="cacheFor">Cache duration.</param> /// <returns>A task which retrieves latest tweets for a given user.</returns> public static async Task <IEnumerable <string> > GetTweetsAsync(string username, TimeSpan?cacheFor = null) { string html = string.Empty; IEnumerable <string> ret = null; if (!WebSource.TryGetFromCache(username, cacheFor, out ret)) { using (var client = new WebSource.SpecializedWebClient()) html = await client.DownloadStringTaskAsync(string.Format("https://mobile.twitter.com/{0}", username)); WebSource.AddToCache(username, cacheFor, ret = ParseTweets(html)); } if (ret == null) { ret = Enumerable.Empty <string>(); } return(ret); }
/// <summary> /// Returns a task which retrieves latest RSS items for a given URL. /// </summary> /// <param name="URL">RSS feed URL.</param> /// <param name="cacheFor">Cache duration.</param> /// <returns>A task which retrieves latest items for a given URL.</returns> public static async Task <IEnumerable <RssFeedItem> > GetItemsAsync(string url, TimeSpan?cacheFor = null) { string xml = string.Empty; IEnumerable <RssFeedItem> ret = null; if (!WebSource.TryGetFromCache(url, cacheFor, out ret)) { using (var client = new WebSource.SpecializedWebClient()) xml = await client.DownloadStringTaskAsync(url); WebSource.AddToCache(url, cacheFor, ret = ParseItems(xml)); } if (ret == null) { ret = Enumerable.Empty <RssFeedItem>(); } return(ret); }
/// <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); }
/// <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); }