/// <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); }