Пример #1
0
        public Status[] Search(string query, ulong since_id)
        {
            try
            {
                var list = new List<Status>();
                using (var reader = XmlReader.Create(string.Format("{2}search.atom?q={0}&since_id={1}&rpp=100&lang=ja", Uri.EscapeDataString(query), since_id, SearchApiUrl)))
                {
                    var doc = XDocument.Load(reader);
                    var xmlns = XNamespace.Get("http://www.w3.org/2005/Atom");
                    var twitter = XNamespace.Get("http://api.twitter.com/");
                    var statuses = from entry in doc.Descendants(xmlns + "entry")
                                   let id = entry.Element(xmlns + "id")
                                   let author = entry.Element(xmlns + "author")
                                   let name = author.Element(xmlns + "name")
                                   let link = entry.Elements(xmlns + "link").Where(p => p.Attribute("rel").Value == "image").First()
                                   select new Status
                                   {
                                       ID = ulong.Parse(id.Value.Substring(id.Value.LastIndexOf(':') + 1)),
                                       CreatedAt = DateTime.Parse(entry.Element(xmlns + "published").Value),
                                       Text = entry.Element(xmlns + "title").Value,
                                       Source = entry.Element(twitter + "source").Value,
                                       Sender = new User
                                       {
                                           Name = name.Value.Substring(name.Value.IndexOf(' ') + 2, name.Value.Length - name.Value.IndexOf(' ') - 3),
                                           ScreenName = name.Value.Remove(name.Value.IndexOf(' ')),
                                           ImageUrl = link.Attribute("href").Value
                                       }
                                   };
                    list.AddRange(statuses);
                }

                list.ForEach(item => { item.IsAuthor = item.Sender.ScreenName == LoginedUser.ScreenName; });

                return list.ToArray();// list.AsParallel().Where((status) => Properties.Settings.Default.GlobalFilter.Count != 0 ? Properties.Settings.Default.GlobalFilter.AsParallel().All((filter) => filter.Process(status)) : true).ToArray();
            }
            catch
            {
                return Statuses.Empty;
            }
        }
Пример #2
0
        private List[] GetListsSubscription(string name)
        {
            try
            {
                long cursor = -1;
                var lists = new List<List>();

                while (true)
                {
                    var response = Get(string.Format("{1}1/{0}/lists/subscriptions.xml", name, ApiBaseUrl), new { cursor = cursor });

                    var xd = XDocument.Parse(response);

                    var temp = from p in xd.Descendants("list")
                               select new List { ID = (int)p.Element("id"), Name = "@" + (string)p.Element("user").Element("screen_name") + "/" + (string)p.Element("name"), ScreenName = (string)p.Element("user").Element("screen_name") };

                    lists.AddRange(temp);

                    var element = xd.Descendants("next_cursor").FirstOrDefault();

                    if (element == null)
                    {
                        break;
                    }

                    var nextCursor = (long)element;

                    if (nextCursor == 0)
                    {
                        break;
                    }

                    cursor = nextCursor;
                }

                return lists.ToArray();
            }
            catch
            {
                return new List[0];
            }
        }
Пример #3
0
        public User[] GetListUsers(string name, int id)
        {
            try
            {
                long cursor = -1;
                var users = new List<User>();

                while (true)
                {
                    var response = Get(string.Format("{2}1/{0}/{1}/members.xml", name, id, ApiBaseUrl), new { cursor = cursor });

                    var xd = XDocument.Parse(response);

                    var temp = from p in xd.Descendants("user")
                                select new User { ID = (int)p.Element("id"), ScreenName = (string)p.Element("screen_name") };

                    users.AddRange(temp);

                    var element = xd.Descendants("next_cursor").FirstOrDefault();

                    if (element == null)
                    {
                        break;
                    }

                    var nextCursor = (long)element;

                    if (nextCursor == 0)
                    {
                        break;
                    }

                    cursor = nextCursor;
                }

                return users.ToArray();
            }
            catch
            {
                return Users.Empty;
            }
        }