示例#1
0
文件: User.cs 项目: a1lic/Mystique
        /// <summary>
        /// Get users
        /// </summary>
        private static IEnumerable <TwitterUser> GetUsers(this CredentialProvider provider, string partialUri, IEnumerable <KeyValuePair <string, string> > para, out long prevCursor, out long nextCursor)
        {
            prevCursor = 0;
            nextCursor = 0;
            var doc = provider.RequestAPIv1(partialUri, CredentialProvider.RequestMethod.GET, para);

            if (doc == null)
            {
                return(null); // request returns error ?
            }
            var users = new List <TwitterUser>();
            var nc    = doc.Root.Element("next_cursor");

            if (nc != null)
            {
                nextCursor = (long)nc.ParseLong();
            }
            var pc = doc.Root.Element("previous_cursor");

            if (pc != null)
            {
                prevCursor = (long)pc.ParseLong();
            }
            System.Diagnostics.Debug.WriteLine("GetUser:::" + Environment.NewLine + doc.ToString());
            return(doc.Root.Element("users").Elements().Select(TwitterUser.FromNode).Where(s => s != null));
        }
示例#2
0
文件: User.cs 项目: a1lic/Mystique
        /// <summary>
        /// Get users
        /// </summary>
        private static IEnumerable <long> GetUserIds(this CredentialProvider provider, string partialUri, IEnumerable <KeyValuePair <string, string> > para, out long prevCursor, out long nextCursor)
        {
            prevCursor = 0;
            nextCursor = 0;
            var doc = provider.RequestAPIv1(partialUri, CredentialProvider.RequestMethod.GET, para);

            if (doc == null)
            {
                return(null); // request returns error ?
            }
            List <TwitterUser> users = new List <TwitterUser>();
            var nc = doc.Root.Element("next_cursor");

            if (nc != null)
            {
                nextCursor = (long)nc.ParseLong();
            }
            var pc = doc.Root.Element("previous_cursor");

            if (pc != null)
            {
                prevCursor = (long)pc.ParseLong();
            }
            if (doc.Root.Element("ids") != null)
            {
                return(doc.Root.Element("ids").Elements().Select(n => n.ParseLong()).Where(n => n != 0));
            }
            else
            {
                return(doc.Root.Elements().Select(n => n.ParseLong()).Where(n => n != 0));
            }
        }
示例#3
0
        /// <summary>
        /// Destroy friendship with someone
        /// </summary>
        /// <param name="provider">credential provider</param>
        /// <param name="userId">target user id</param>
        /// <param name="screenName">target user screen name</param>
        /// <remarks>
        /// user id or user screeen name must set.
        /// </remarks>
        public static TwitterUser DestroyFriendship(this CredentialProvider provider, long?userId = null, string screenName = null)
        {
            if (userId == null && String.IsNullOrEmpty(screenName))
            {
                throw new ArgumentException("User id or screen name is must set.");
            }
            List <KeyValuePair <string, string> > arg = new List <KeyValuePair <string, string> >();

            if (userId != null)
            {
                arg.Add(new KeyValuePair <string, string>("user_id", userId.ToString()));
            }
            if (!String.IsNullOrEmpty(screenName))
            {
                arg.Add(new KeyValuePair <string, string>("screen_name", screenName));
            }
            var ret = provider.RequestAPIv1("friendships/destroy.json", CredentialProvider.RequestMethod.POST, arg);

            if (ret != null && ret.Root != null)
            {
                return(TwitterUser.FromNode(ret.Root));
            }
            else
            {
                return(null);
            }
        }
示例#4
0
        /// <summary>
        /// Create friendship with someone
        /// </summary>
        /// <param name="provider">credential provider</param>
        /// <param name="userId">target user id</param>
        /// <param name="screenName">target user screen name</param>
        /// <param name="follow">send his tweet to specified device</param>
        /// <remarks>
        /// user id or user screeen name must set.
        /// </remarks>
        public static TwitterUser CreateFriendship(this CredentialProvider provider, long?userId = null, string screenName = null, bool follow = false)
        {
            if (userId == null && String.IsNullOrEmpty(screenName))
            {
                throw new ArgumentException("User id or screen name is must set.");
            }
            var para = CreateParamList();

            if (userId != null)
            {
                para.Add(new KeyValuePair <string, string>("user_id", userId.ToString()));
            }
            if (!String.IsNullOrEmpty(screenName))
            {
                para.Add(new KeyValuePair <string, string>("screen_name", screenName));
            }
            if (follow)
            {
                para.Add(new KeyValuePair <string, string>("follow", "true"));
            }
            var ret = provider.RequestAPIv1("friendships/create.json", CredentialProvider.RequestMethod.POST, para);

            if (ret != null && ret.Root != null)
            {
                return(TwitterUser.FromNode(ret.Root));
            }
            else
            {
                return(null);
            }
        }
示例#5
0
文件: Status.cs 项目: a1lic/Mystique
        /// <summary>
        /// Get status
        /// </summary>
        private static TwitterStatus GetStatus(this CredentialProvider provider, string partialUri, CredentialProvider.RequestMethod method, IEnumerable <KeyValuePair <string, string> > para)
        {
            var doc = provider.RequestAPIv1(partialUri, method, para);

            if (doc == null)
            {
                return(null);
            }
            return(TwitterStatus.FromNode(doc.Root));
        }
示例#6
0
文件: User.cs 项目: a1lic/Mystique
        /// <summary>
        /// Get users
        /// </summary>
        private static IEnumerable <TwitterUser> GetUsers(this CredentialProvider provider, string partialUri, IEnumerable <KeyValuePair <string, string> > para)
        {
            var doc = provider.RequestAPIv1(partialUri, CredentialProvider.RequestMethod.GET, para);

            if (doc == null)
            {
                return(null); // request returns error ?
            }
            System.Diagnostics.Debug.WriteLine("GetUsers ::: " + Environment.NewLine + doc);
            return(doc.Root.Element("users").Elements().Select(u => TwitterUser.FromNode(u)).Where(u => u != null));
        }
示例#7
0
        /// <summary>
        /// Get twitter timeline
        /// </summary>
        /// <param name="provider">credential provider</param>
        /// <param name="partialUri">partial uri</param>
        /// <param name="param">parameters</param>
        private static IEnumerable <TwitterStatus> GetTimeline(this CredentialProvider provider, string partialUri, IEnumerable <KeyValuePair <string, string> > param)
        {
            var doc = provider.RequestAPIv1(partialUri, CredentialProvider.RequestMethod.GET, param);

            if (doc == null)
            {
                return(null);
            }
            return(doc.Root.Elements()
                   .Select(n => TwitterStatus.FromNode(n))
                   .Where(s => s != null));
        }
示例#8
0
        /// <summary>
        /// Get direct messages
        /// </summary>
        private static IEnumerable <TwitterDirectMessage> GetDirectMessages(this CredentialProvider provider, string partialUri, IEnumerable <KeyValuePair <string, string> > param)
        {
            var doc = provider.RequestAPIv1(partialUri, CredentialProvider.RequestMethod.GET, param);

            if (doc == null)
            {
                return(null);
            }
            List <TwitterStatus> statuses = new List <TwitterStatus>();
            HashSet <string>     hashes   = new HashSet <string>();

            return(doc.Root.Elements().Select(n => TwitterDirectMessage.FromNode(n)).Where(d => d != null));
        }
示例#9
0
        /// <summary>
        /// Delete a direct message which you sent
        /// </summary>
        /// <param name="provider">credential provider</param>
        /// <param name="id">destroy id</param>
        public static TwitterDirectMessage DestroyDirectMessage(this CredentialProvider provider, long id)
        {
            List <KeyValuePair <string, string> > para = new List <KeyValuePair <string, string> >();

            para.Add(new KeyValuePair <string, string>("id", id.ToString()));

            var xmlDoc = provider.RequestAPIv1("direct_messages/destroy.json", CredentialProvider.RequestMethod.POST, para);

            if (xmlDoc == null)
            {
                return(null);
            }

            return(TwitterDirectMessage.FromNode(xmlDoc.Root));
        }
示例#10
0
        /// <summary>
        /// Send new direct message
        /// </summary>
        /// <param name="provider">credential provider</param>
        /// <param name="user">target user id or name</param>
        /// <param name="text">send body</param>
        public static TwitterDirectMessage SendDirectMessage(this CredentialProvider provider, string screenName, string text)
        {
            List <KeyValuePair <string, string> > para = new List <KeyValuePair <string, string> >();

            para.Add(new KeyValuePair <string, string>("text", HttpUtility.UrlEncodeStrict(text, Encoding.UTF8, true)));
            para.Add(new KeyValuePair <string, string>("screen_name", screenName));

            var xmlDoc = provider.RequestAPIv1("direct_messages/new.json", CredentialProvider.RequestMethod.POST, para);

            if (xmlDoc == null)
            {
                return(null);
            }

            return(TwitterDirectMessage.FromNode(xmlDoc.Root));
        }
示例#11
0
        /// <summary>
        /// Check exists friendship
        /// </summary>
        /// <param name="provider">credential provider</param>
        /// <param name="userA">user A</param>
        /// <param name="userB">user B</param>
        /// <returns>if user A or B is not existed, this method returns false.</returns>
        public static bool ExistsFriendship(this CredentialProvider provider, string userA, string userB)
        {
            List <KeyValuePair <string, string> > arg = new List <KeyValuePair <string, string> >();

            arg.Add(new KeyValuePair <string, string>("user_a", userA));
            arg.Add(new KeyValuePair <string, string>("user_b", userB));
            var ret = provider.RequestAPIv1("friendship/exists.json", CredentialProvider.RequestMethod.GET, arg);

            if (ret.Element("friends") != null)
            {
                return(ret.Element("friends").ParseBool());
            }
            else
            {
                return(false);
            }
        }
示例#12
0
文件: User.cs 项目: a1lic/Mystique
        /// <summary>
        /// Get user with full params
        /// </summary>
        private static TwitterUser GetUser(this CredentialProvider provider, string partialUri, CredentialProvider.RequestMethod method, long?userId, string screenName)
        {
            var para = new List <KeyValuePair <string, string> >();

            if (userId != null)
            {
                para.Add(new KeyValuePair <string, string>("user_id", userId.ToString()));
            }
            if (screenName != null)
            {
                para.Add(new KeyValuePair <string, string>("screen_name", screenName));
            }
            var doc = provider.RequestAPIv1(partialUri, method, para);

            if (doc == null)
            {
                return(null);
            }
            return(TwitterUser.FromNode(doc.Root));
        }
示例#13
0
文件: Listing.cs 项目: a1lic/Mystique
        /// <summary>
        /// Get single list data
        /// </summary>
        /// <param name="provider">credential provider</param>
        /// <param name="userScreenName">list owner user's id</param>
        /// <param name="listSlug">list slug</param>
        public static TwitterList GetList(this CredentialProvider provider, string userScreenName, string listSlug)
        {
            var para = new List <KeyValuePair <string, string> >();

            if (!String.IsNullOrEmpty(userScreenName))
            {
                para.Add(new KeyValuePair <string, string>("owner_screen_name", userScreenName));
            }
            if (!String.IsNullOrEmpty(listSlug))
            {
                para.Add(new KeyValuePair <string, string>("slug", OAuth.UrlEncode(listSlug, Encoding.UTF8, true)));
            }
            var list = provider.RequestAPIv1("lists/show.json",
                                             CredentialProvider.RequestMethod.GET, para).Root;

            if (list != null)
            {
                return(TwitterList.FromNode(list));
            }
            return(null);
        }
示例#14
0
文件: Listing.cs 项目: a1lic/Mystique
        /// <summary>
        /// Get list with full params
        /// </summary>
        private static IEnumerable <TwitterList> GetLists(this CredentialProvider provider, string partialUri, IEnumerable <KeyValuePair <string, string> > para, long?cursor, out long prevCursor, out long nextCursor)
        {
            var npara = new List <KeyValuePair <string, string> >();

            foreach (var pair in para)
            {
                npara.Add(pair);
            }
            if (cursor != null)
            {
                npara.Add(new KeyValuePair <string, string>("cursor", cursor.ToString()));
            }

            prevCursor = 0;
            nextCursor = 0;

            var doc = provider.RequestAPIv1(partialUri, CredentialProvider.RequestMethod.GET, npara);

            if (doc == null)
            {
                return(null);
            }
            var nc = doc.Root.Element("next_cursor");

            if (nc != null)
            {
                nextCursor = (long)nc.ParseLong();
            }
            var pc = doc.Root.Element("previous_cursor");

            if (pc != null)
            {
                prevCursor = (long)pc.ParseLong();
            }

            System.Diagnostics.Debug.WriteLine("Lists :::" + Environment.NewLine + doc);

            return(doc.Root.Elements().Select(TwitterList.FromNode).Where(n => n != null));
        }
示例#15
0
文件: Status.cs 项目: a1lic/Mystique
        /// <summary>
        /// Update new status
        /// </summary>
        /// <param name="provider">credential provider</param>
        /// <param name="body">body</param>
        /// <param name="inReplyToStatusId">tweet id which be replied this tweet</param>
        public static TwitterStatus UpdateStatus(this CredentialProvider provider, string body, long?inReplyToStatusId = null)
        {
            var para = CreateParamList();

            para.Add(new KeyValuePair <string, string>("status", HttpUtility.UrlEncodeStrict(body, Encoding.UTF8, true)));
            if (inReplyToStatusId != null && inReplyToStatusId.HasValue)
            {
                para.Add(new KeyValuePair <string, string>("in_reply_to_status_id", inReplyToStatusId.Value.ToString()));
            }

            para.Add(new KeyValuePair <string, string>("include_entities", "true"));

            var doc = provider.RequestAPIv1("statuses/update.json", CredentialProvider.RequestMethod.POST, para);

            if (doc != null)
            {
                return(TwitterStatus.FromNode(doc.Root));
            }
            else
            {
                return(null);
            }
        }
示例#16
0
        /// <summary>
        /// Report spam and block someone
        /// </summary>
        /// <param name="provider">credential provider</param>
        /// <param name="userId">block user id</param>
        /// <param name="screenName">block user screen name</param>
        /// <remarks>
        /// user id or user screeen name must set.
        /// </remarks>
        public static TwitterUser ReportSpam(this CredentialProvider provider, long?userId = null, string screenName = null)
        {
            if (userId == null && String.IsNullOrEmpty(screenName))
            {
                throw new ArgumentException("User id or screen name is must set.");
            }
            var para = CreateParamList();

            if (userId != null)
            {
                para.Add(new KeyValuePair <string, string>("user_id", userId.ToString()));
            }
            if (!String.IsNullOrEmpty(screenName))
            {
                para.Add(new KeyValuePair <string, string>("screen_name", screenName));
            }
            var ret = provider.RequestAPIv1("users/report_spam.json", CredentialProvider.RequestMethod.POST, para);

            if (ret != null && ret.Root != null)
            {
                return(TwitterUser.FromNode(ret.Root));
            }
            return(null);
        }