Exemple #1
0
        /// <summary>
        /// Executes search query against the Twitter API
        /// </summary>
        /// <param name="search">The search query</param>
        /// <param name="count">The number of results to return</param>
        /// <returns></returns>
        public IList <TwitterStatus> GetSearch(string search, int count)
        {
            // Build query URL
            var sb = new StringBuilder();

            sb.AppendFormat(
                "http://search.twitter.com/search.atom?q={0}&rpp={1}",
                HttpUtility.UrlEncode(search),
                count
                );
            var queryUrl = sb.ToString();


            // Execute query
            var results = this.Query(queryUrl);

            // Parse results
            var defaultNS = "{http://www.w3.org/2005/Atom}";


            var statuses = new List <TwitterStatus>();
            var entries  = from e in results.Descendants(defaultNS + "entry")
                           select e;


            foreach (var entry in entries)
            {
                var newUser = new TwitterUser {
                    Name            = entry.Descendants(defaultNS + "name").FirstOrDefault().Value,
                    ProfileImageUrl = entry.Elements(defaultNS + "link")
                                      .Where(link => (string)link.Attribute("rel") == "image")
                                      .Select(link => (string)link.Attribute("href"))
                                      .First()
                };

                var newStatus = new TwitterStatus {
                    CreatedAt = DateTime.Parse(entry.Element(defaultNS + "published").Value),
                    Text      = entry.Element(defaultNS + "content").Value,
                    User      = newUser
                };

                statuses.Add(newStatus);
            }


            return(statuses.ToList());
        }
        private IList<TwitterStatus> GenerateFakeData()
        {
            var statuses = new List<TwitterStatus>();
            var twitterLogoUrl = ViewControl.Page.ClientScript.GetWebResourceUrl(
                this.GetType(), "Twitter.Twitter32.png");

            var user = new TwitterUser {
                ScreenName = "ajaxcontroltoolkit",
                Description = "Ajax Control Toolkit",
                Id = "ajaxcontroltoolkit",
                Name = "Ajax Control Toolkit",
                Location = "US",
                ProfileImageUrl = twitterLogoUrl
            };

            string search = "";
            if (_twitter.Mode == TwitterMode.Profile) {
                statuses.Add(new TwitterStatus {
                    CreatedAt = DateTime.Now,
                    Text = "Ajax Control Toolkit",
                    User = user
                });
                _twitter.Title = _twitter.Title ?? user.Name;
                _twitter.Caption = _twitter.Caption ?? user.ScreenName;
                _twitter.ProfileImageUrl = _twitter.ProfileImageUrl ?? user.ProfileImageUrl;

            } else {
                var searchText = _twitter.Search.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var s in searchText) {
                    search += "<em>" + s + "</em> ";
                }
                search = " " + search;
            }

            var text = new string[]
                           {
                               "Lorem <a href='http://www.sample_ipsum_link.com'>ipsum</a> dolor sit amet, "+search+"consectetur adipisicing elit, sed do eiusmod tempor incididunt ut",
                               "labore et dolore magna aliqua. Ut enim ad minim veniam, quis "+search+"nostrud exercitation",
                               "ullamco laboris "+search+"nisi ut aliquip ex ea <a href='http://comodo_sample_link'>commodo</a> consequat",
                               search + "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla",
                               "Excepteur sint "+search+"occaecat cupidatat non proident, sunt in culpa qui officia deserunt"
                           };

            int i = 0;
            var random = new Random();
            foreach (var s in text) {
                statuses.Add(new TwitterStatus {
                    CreatedAt = DateTime.Now.AddMinutes(random.Next(1, 1000) * -1),
                    Text = s,
                    User = user
                });
                i++;
                if (i > _twitter.Count)
                    break;
            }

            if (_twitter.Mode == TwitterMode.Profile && statuses.Count > 1) {
                statuses.RemoveAt(statuses.Count - 1);
            }

            return statuses;
        }
Exemple #3
0
        private IList <TwitterStatus> GenerateFakeData()
        {
            var statuses       = new List <TwitterStatus>();
            var twitterLogoUrl = ViewControl.Page.ClientScript.GetWebResourceUrl(
                this.GetType(), "Twitter.Twitter32.png");

            var user = new TwitterUser {
                ScreenName      = "ajaxcontroltoolkit",
                Description     = "Ajax Control Toolkit",
                Id              = "ajaxcontroltoolkit",
                Name            = "Ajax Control Toolkit",
                Location        = "US",
                ProfileImageUrl = twitterLogoUrl
            };

            string search = "";

            if (_twitter.Mode == TwitterMode.Profile)
            {
                statuses.Add(new TwitterStatus {
                    CreatedAt = DateTime.Now,
                    Text      = "Ajax Control Toolkit",
                    User      = user
                });
                _twitter.Title           = _twitter.Title ?? user.Name;
                _twitter.Caption         = _twitter.Caption ?? user.ScreenName;
                _twitter.ProfileImageUrl = _twitter.ProfileImageUrl ?? user.ProfileImageUrl;
            }
            else
            {
                var searchText = _twitter.Search.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var s in searchText)
                {
                    search += "<em>" + s + "</em> ";
                }
                search = " " + search;
            }

            var text = new string[]
            {
                "Lorem <a href='http://www.sample_ipsum_link.com'>ipsum</a> dolor sit amet, " + search + "consectetur adipisicing elit, sed do eiusmod tempor incididunt ut",
                "labore et dolore magna aliqua. Ut enim ad minim veniam, quis " + search + "nostrud exercitation",
                "ullamco laboris " + search + "nisi ut aliquip ex ea <a href='http://comodo_sample_link'>commodo</a> consequat",
                search + "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla",
                "Excepteur sint " + search + "occaecat cupidatat non proident, sunt in culpa qui officia deserunt"
            };

            int i      = 0;
            var random = new Random();

            foreach (var s in text)
            {
                statuses.Add(new TwitterStatus {
                    CreatedAt = DateTime.Now.AddMinutes(random.Next(1, 1000) * -1),
                    Text      = s,
                    User      = user
                });
                i++;
                if (i > _twitter.Count)
                {
                    break;
                }
            }

            if (_twitter.Mode == TwitterMode.Profile && statuses.Count > 1)
            {
                statuses.RemoveAt(statuses.Count - 1);
            }

            return(statuses);
        }
        /// <summary>
        /// Executes search query against the Twitter API
        /// </summary>
        /// <param name="search">The search query</param>
        /// <param name="count">The number of results to return</param>
        /// <returns></returns>
        public IList<TwitterStatus> GetSearch(string search, int count)
        {
            // Build query URL
            var sb = new StringBuilder();
            sb.AppendFormat(
                "http://search.twitter.com/search.atom?q={0}&rpp={1}",
                HttpUtility.UrlEncode(search),
                count
            );
            var queryUrl = sb.ToString();

            // Execute query
            var results = this.Query(queryUrl);

            // Parse results
            var defaultNS = "{http://www.w3.org/2005/Atom}";

            var statuses = new List<TwitterStatus>();
            var entries = from e in results.Descendants(defaultNS + "entry")
                          select e;

            foreach (var entry in entries) {

                var newUser = new TwitterUser {
                    Name = entry.Descendants(defaultNS + "name").FirstOrDefault().Value,
                    ProfileImageUrl = entry.Elements(defaultNS + "link")
                      .Where(link => (string)link.Attribute("rel") == "image")
                      .Select(link => (string)link.Attribute("href"))
                      .First()
                };

                var newStatus = new TwitterStatus {
                    CreatedAt = DateTime.Parse(entry.Element(defaultNS + "published").Value),
                    Text = entry.Element(defaultNS + "content").Value,
                    User = newUser
                };

                statuses.Add(newStatus);

            }

            return statuses.ToList();
        }