Exemple #1
0
        /// <summary>
        /// lets logged-in user follow another user
        /// </summary>
        /// <param name="id">id of user to follow</param>
        /// <returns>followed friend user info</returns>
        public User CreateFriendship(string id, string userID, string screenName, bool follow)
        {
            if (string.IsNullOrEmpty(id) &&
                string.IsNullOrEmpty(userID) &&
                string.IsNullOrEmpty(screenName))
            {
                throw new ArgumentException("Either id, userID, or screenName is a required parameter.");
            }

            var destroyUrl = BaseUrl + "friendships/create/" + id + ".xml";

            var createParams = new Dictionary <string, string>
            {
                { "user_id", userID },
                { "screen_name", screenName }
            };

            // If follow exists in the parameter list, Twitter will
            // always treat it as true, even if the value is false;
            // Therefore, only add follow if it is true.
            if (follow)
            {
                createParams.Add("follow", "true");
            }

            var results =
                TwitterExecute.ExecuteTwitter(
                    destroyUrl,
                    createParams,
                    new UserRequestProcessor());

            return((results as IList <User>).FirstOrDefault());
        }
Exemple #2
0
        /// <summary>
        /// sends a new direct message to specified userr
        /// </summary>
        /// <param name="userID">id of user to send to</param>
        /// <param name="id">text to send</param>
        /// <returns>direct message element</returns>
        public DirectMessage NewDirectMessage(string userID, string text)
        {
            if (string.IsNullOrEmpty(userID))
            {
                throw new ArgumentException("userID is a required parameter.", "userID");
            }

            if (string.IsNullOrEmpty(text))
            {
                throw new ArgumentException("text is a required parameter.", "text");
            }

            if (text.Length > 140)
            {
                throw new ArgumentException("text must be no longer than 140 characters.", "text");
            }

            var newUrl = BaseUrl + "direct_messages/new.xml";

            var results =
                TwitterExecute.ExecuteTwitter(
                    newUrl,
                    new Dictionary <string, string>
            {
                { "user", userID },
                { "text", text }
            },
                    new DirectMessageRequestProcessor());

            return((results as IList <DirectMessage>).FirstOrDefault());
        }
Exemple #3
0
        /// <summary>
        /// Update Twitter colors
        /// </summary>
        /// <remarks>
        /// The # character prefix is optional.  At least one color argument must be provided.
        /// </remarks>
        /// <param name="background">background color</param>
        /// <param name="text">text color</param>
        /// <param name="link">link color</param>
        /// <param name="sidebarFill">sidebar color</param>
        /// <param name="sidebarBorder">sidebar border color</param>
        /// <returns>User info with new colors</returns>
        public User UpdateAccountColors(string background, string text, string link, string sidebarFill, string sidebarBorder)
        {
            var accountUrl = BaseUrl + "account/update_profile_colors.xml";

            if (string.IsNullOrEmpty(background) &&
                string.IsNullOrEmpty(text) &&
                string.IsNullOrEmpty(link) &&
                string.IsNullOrEmpty(sidebarFill) &&
                string.IsNullOrEmpty(sidebarBorder))
            {
                throw new ArgumentException("At least one of the colors (background, text, link, sidebarFill, or sidebarBorder) must be provided as arguments, but none are specified.");
            }

            var results =
                TwitterExecute.ExecuteTwitter(
                    accountUrl,
                    new Dictionary <string, string>
            {
                { "profile_background_color", background.TrimStart('#') },
                { "profile_text_color", text.TrimStart('#') },
                { "profile_link_color", link.TrimStart('#') },
                { "profile_sidebar_fill_color", sidebarFill.TrimStart('#') },
                { "profile_sidebar_border_color", sidebarBorder.TrimStart('#') }
            },
                    new UserRequestProcessor());

            return((results as IList <User>).FirstOrDefault());
        }
Exemple #4
0
        /// <summary>
        /// sends a status update
        /// </summary>
        /// <param name="status">(optional @UserName) and (required) status text</param>
        /// <param name="inReplyToStatusID">id of status replying to - optional - pass null if not used</param>
        /// <returns>IQueryable of sent status</returns>
        public Status UpdateStatus(string status, string inReplyToStatusID)
        {
            if (string.IsNullOrEmpty(status))
            {
                throw new ArgumentException("status is a required parameter.");
            }

            if (status.Length > 140)
            {
                throw new ArgumentException("status length must be no more than 140 characters.", "status");
            }

            status = status.Substring(0, Math.Min(140, status.Length));

            var updateUrl = BaseUrl + "statuses/update.xml";

            var results =
                TwitterExecute.ExecuteTwitter(
                    updateUrl,
                    new Dictionary <string, string>
            {
                { "status", status },
                { "in_reply_to_status_id", inReplyToStatusID }
            },
                    new StatusRequestProcessor());

            return((results as IList <Status>).FirstOrDefault());
        }
Exemple #5
0
        /// <summary>
        /// Update account profile info
        /// </summary>
        /// <param name="name">User Name</param>
        /// <param name="email">Email Address</param>
        /// <param name="url">Web Address</param>
        /// <param name="location">Geographic Location</param>
        /// <param name="description">Personal Description</param>
        /// <returns>User with new info</returns>
        public User UpdateAccountProfile(string name, string email, string url, string location, string description)
        {
            var accountUrl = BaseUrl + "account/update_profile.xml";

            if (string.IsNullOrEmpty(name) &&
                string.IsNullOrEmpty(email) &&
                string.IsNullOrEmpty(url) &&
                string.IsNullOrEmpty(location) &&
                string.IsNullOrEmpty(description))
            {
                throw new ArgumentException("At least one of the colors (name, email, url, location, or description) must be provided as arguments, but none are specified.");
            }

            if (!string.IsNullOrEmpty(name) && name.Length > 20)
            {
                throw new ArgumentException("name must be no longer than 20 characters", "name");
            }

            if (!string.IsNullOrEmpty(email) && email.Length > 40)
            {
                throw new ArgumentException("email must be no longer than 40 characters", "email");
            }

            if (!string.IsNullOrEmpty(url) && url.Length > 100)
            {
                throw new ArgumentException("url must be no longer than 100 characters", "url");
            }

            if (!string.IsNullOrEmpty(location) && location.Length > 30)
            {
                throw new ArgumentException("location must be no longer than 30 characters", "location");
            }

            if (!string.IsNullOrEmpty(description) && description.Length > 160)
            {
                throw new ArgumentException("description must be no longer than 160 characters", "description");
            }

            var results =
                TwitterExecute.ExecuteTwitter(
                    accountUrl,
                    new Dictionary <string, string>
            {
                { "name", name },
                { "email", email },
                { "url", url },
                { "location", location },
                { "description", description }
            },
                    new UserRequestProcessor());

            return((results as IList <User>).FirstOrDefault());
        }
Exemple #6
0
        /// <summary>
        /// sends a test message to twitter to check connectivity
        /// </summary>
        /// <returns>true</returns>
        public bool HelpTest()
        {
            var helpUrl = BaseUrl + "help/test.xml";

            var results =
                TwitterExecute.ExecuteTwitter(
                    helpUrl,
                    new Dictionary <string, string>(),
                    new HelpRequestProcessor());

            return((results as IList <bool>).FirstOrDefault());
        }
Exemple #7
0
        /// <summary>
        /// Updates notification device for account
        /// </summary>
        /// <param name="device">type of device to use</param>
        /// <returns>User info</returns>
        public User UpdateAccountDeliveryDevice(DeviceType device)
        {
            var accountUrl = BaseUrl + "account/update_delivery_device.xml";

            var results =
                TwitterExecute.ExecuteTwitter(
                    accountUrl,
                    new Dictionary <string, string>
            {
                { "device", device.ToString().ToLower() }
            },
                    new UserRequestProcessor());

            return((results as IList <User>).FirstOrDefault());
        }
Exemple #8
0
        /// <summary>
        /// Deletes a favorite from the logged-in user's profile
        /// </summary>
        /// <param name="id">id of status to add to favorites</param>
        /// <returns>status of favorite</returns>
        public Status DestroyFavorite(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentException("id is a required parameter.", "id");
            }

            var favoritesUrl = BaseUrl + "favorites/destroy/" + id + ".xml";

            var results =
                TwitterExecute.ExecuteTwitter(
                    favoritesUrl,
                    new Dictionary <string, string>(),
                    new StatusRequestProcessor());

            return((results as IList <Status>).FirstOrDefault());
        }
Exemple #9
0
        /// <summary>
        /// deletes a direct message
        /// </summary>
        /// <param name="id">id of direct message</param>
        /// <returns>direct message element</returns>
        public DirectMessage DestroyDirectMessage(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentException("id is a required parameter.", "id");
            }

            var destroyUrl = BaseUrl + "direct_messages/destroy/" + id + ".xml";

            var results =
                TwitterExecute.ExecuteTwitter(
                    destroyUrl,
                    new Dictionary <string, string>(),
                    new DirectMessageRequestProcessor());

            return((results as IList <DirectMessage>).FirstOrDefault());
        }
Exemple #10
0
        /// <summary>
        /// Unblocks a user
        /// </summary>
        /// <param name="id">id of user to unblock</param>
        /// <returns>User that was unblocked</returns>
        public User DestroyBlock(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentException("id is a required parameter.", "id");
            }

            var blocksUrl = BaseUrl + "blocks/destroy/" + id + ".xml";

            var results =
                TwitterExecute.ExecuteTwitter(
                    blocksUrl,
                    new Dictionary <string, string>(),
                    new UserRequestProcessor());

            return((results as IList <User>).FirstOrDefault());
        }
Exemple #11
0
        /// <summary>
        /// Ends the session for the currently logged in user
        /// </summary>
        /// <returns>true</returns>
        public TwitterHashResponse EndAccountSession()
        {
            var accountUrl = BaseUrl + "account/end_session.xml";

            var results =
                TwitterExecute.ExecuteTwitter(
                    accountUrl,
                    new Dictionary <string, string>(),
                    new AccountRequestProcessor());

            var acct = (results as IList <Account>).FirstOrDefault();

            if (acct != null)
            {
                return(acct.EndSessionStatus);
            }
            else
            {
                throw new WebException("Unknown Twitter Response.");
            }
        }
Exemple #12
0
        /// <summary>
        /// Disables notifications from specified user. (Notification Leave)
        /// </summary>
        /// <remarks>
        /// A least one parameter is required.
        /// </remarks>
        /// <param name="id">ID of user to disable notifications on.</param>
        /// <param name="userID">ID of user - disambiguates when ID is screen name.</param>
        /// <param name="screenName">Screen Name of user - disambiguates when ID is screen name.</param>
        /// <returns>Specified user info</returns>
        public User DisableNotifications(string id, string userID, string screenName)
        {
            if (string.IsNullOrEmpty(id) &&
                string.IsNullOrEmpty(userID) &&
                string.IsNullOrEmpty(screenName))
            {
                throw new ArgumentException("Either id, userID, or screenName is a required parameter.");
            }

            var notificationsUrl = BaseUrl + "notifications/leave/" + id + ".xml";

            var results =
                TwitterExecute.ExecuteTwitter(
                    notificationsUrl,
                    new Dictionary <string, string>
            {
                { "user_id", userID },
                { "screen_name", screenName }
            },
                    new UserRequestProcessor());

            return((results as IList <User>).FirstOrDefault());
        }