コード例 #1
0
        /// <summary>
        /// Sends an image file to Twitter to replace user image.
        /// </summary>
        /// <param name="image">byte array of image to upload</param>
        /// <param name="fileName">name to pass to Twitter for the file</param>
        /// <param name="imageType">type of image: must be one of jpg, gif, or png</param>
        /// <param name="includeEntities">Set to false to not include entities. (default: true)</param>
        /// <param name="skipStatus">Don't include status with response.</param>
        /// <returns>User with new image info</returns>
        public async Task <User> UpdateAccountImageAsync(byte[] image, string fileName, string imageType, bool includeEntities, bool skipStatus, CancellationToken cancelToken = default(CancellationToken))
        {
            var accountUrl = BaseUrl + "account/update_profile_image.json";

            if (image == null || image.Length == 0)
            {
                throw new ArgumentException("image is required.", "image");
            }

            if (string.IsNullOrWhiteSpace(fileName))
            {
                throw new ArgumentException("fileName is required.", "fileName");
            }

            if (string.IsNullOrWhiteSpace(imageType))
            {
                throw new ArgumentException("imageType is required.", "imageType");
            }

            var reqProc    = new UserRequestProcessor <User>();
            var parameters = new Dictionary <string, string>
            {
                { "include_entities", includeEntities.ToString().ToLower() },
                { "skip_status", skipStatus.ToString().ToLower() }
            };

            string name          = "image";
            string imageMimeType = "image/" + imageType;

            RawResult = await TwitterExecutor.PostMediaAsync(accountUrl, parameters, image, name, fileName, imageMimeType, cancelToken).ConfigureAwait(false);

            return(reqProc.ProcessActionResult(RawResult, UserAction.SingleUser));
        }
コード例 #2
0
        /// <summary>
        /// sends an image file to Twitter to replace background image
        /// </summary>
        /// <param name="imageFilePath">full path to file, including file name</param>
        /// <param name="tile">Tile image in background</param>
        /// <param name="use">Whether to use uploaded background image or not</param>
        /// <param name="includeEntities">Set to false to not include entities. (default: true)</param>
        /// <param name="skipStatus">Don't include status with response.</param>
        /// <param name="callback">Async Callback used in Silverlight queries</param>
        /// <returns>User with new image info</returns>
        public static User UpdateAccountBackgroundImage(this TwitterContext ctx, string imageFilePath, bool tile, bool use, bool includeEntities, bool skipStatus, Action <TwitterAsyncResponse <User> > callback)
        {
            var accountUrl = ctx.BaseUrl + "account/update_profile_background_image.json";

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

            var parameters = new Dictionary <string, string>
            {
                { "include_entities", includeEntities.ToString().ToLower() },
                { "skip_status", skipStatus.ToString().ToLower() }
            };

            if (tile)
            {
                parameters.Add("tile", true.ToString().ToLower());
                parameters.Add("use", use.ToString().ToLower());
            }

            var reqProc = new UserRequestProcessor <User>();

            ITwitterExecute exec = ctx.TwitterExecutor;

            exec.AsyncCallback = callback;
            var resultsJson =
                exec.PostTwitterFile(accountUrl, parameters, imageFilePath, reqProc);

            User user = reqProc.ProcessActionResult(resultsJson, UserAction.SingleUser);

            return(user);
        }
コード例 #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>
        /// <param name="includeEntities">Set to false to not include entities. (default: true)</param>
        /// <param name="skipStatus">Don't include status with response.</param>
        /// <returns>User info with new colors</returns>
        public async Task <User> UpdateAccountColorsAsync(string background, string text, string link, string sidebarFill, string sidebarBorder, bool includeEntities, bool skipStatus, CancellationToken cancelToken = default(CancellationToken))
        {
            var accountUrl = BaseUrl + "account/update_profile_colors.json";

            if (string.IsNullOrWhiteSpace(background) &&
                string.IsNullOrWhiteSpace(text) &&
                string.IsNullOrWhiteSpace(link) &&
                string.IsNullOrWhiteSpace(sidebarFill) &&
                string.IsNullOrWhiteSpace(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.", NoInputParam);
            }

            var reqProc = new UserRequestProcessor <User>();

            RawResult =
                await TwitterExecutor.PostToTwitterAsync <User>(
                    accountUrl,
                    new Dictionary <string, string>
            {
                { "profile_background_color", string.IsNullOrWhiteSpace(background) ? null : background.TrimStart('#') },
                { "profile_text_color", string.IsNullOrWhiteSpace(text) ? null : text.TrimStart('#') },
                { "profile_link_color", string.IsNullOrWhiteSpace(link) ? null : link.TrimStart('#') },
                { "profile_sidebar_fill_color", string.IsNullOrWhiteSpace(sidebarFill) ? null : sidebarFill.TrimStart('#') },
                { "profile_sidebar_border_color", string.IsNullOrWhiteSpace(sidebarBorder) ? null : sidebarBorder.TrimStart('#') },
                { "include_entities", includeEntities.ToString().ToLower() },
                { "skip_status", skipStatus.ToString().ToLower() }
            },
                    cancelToken)
                .ConfigureAwait(false);

            return(reqProc.ProcessActionResult(RawResult, UserAction.SingleUser));
        }
コード例 #4
0
        /// <summary>
        /// lets logged-in user report spam
        /// </summary>
        /// <param name="userID">user id of alleged spammer</param>
        /// <param name="screenName">screen name of alleged spammer</param>
        /// <param name="callback">Async Callback used in Silverlight queries</param>
        /// <returns>Alleged spammer user info</returns>
        public static User ReportSpam(this TwitterContext ctx, string userID, string screenName, Action <TwitterAsyncResponse <User> > callback)
        {
            if (string.IsNullOrEmpty(userID) &&
                string.IsNullOrEmpty(screenName))
            {
                throw new ArgumentException("Either userID or screenName is a required parameter.");
            }

            string reportSpamUrl = ctx.BaseUrl + "users/report_spam.json";

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

            var reqProc = new UserRequestProcessor <User>();

            ITwitterExecute exec = ctx.TwitterExecutor;

            exec.AsyncCallback = callback;
            var resultsJson =
                exec.PostToTwitter(
                    reportSpamUrl,
                    createParams,
                    response => reqProc.ProcessActionResult(response, UserAction.SingleUser));

            User user = reqProc.ProcessActionResult(resultsJson, UserAction.SingleUser);

            return(user);
        }
コード例 #5
0
        /// <summary>
        /// Sends an image to Twitter to be placed as the user's profile banner.
        /// </summary>
        /// <param name="banner">byte[] containing image data.</param>
        /// <param name="width">Pixel width to clip image.</param>
        /// <param name="height">Pixel height to clip image.</param>
        /// <param name="offsetLeft">Pixels to offset start of image from the left.</param>
        /// <param name="offsetTop">Pixels to offset start of image from the top.</param>
        /// <returns>
        /// Account of authenticated user who's profile banner will be updated.
        /// Url of new banner will appear in ProfileBannerUrl property.
        /// </returns>
        public async Task <User> UpdateProfileBannerAsync(byte[] banner, int width, int height, int offsetLeft, int offsetTop, CancellationToken cancelToken = default(CancellationToken))
        {
            var accountUrl = BaseUrl + "account/update_profile_banner.json";

            if (banner == null || banner.Length == 0)
            {
                throw new ArgumentException("banner is required.", "banner");
            }

            var parameters = new Dictionary <string, string?>
            {
                { "width", width.ToString() },
                { "height", height.ToString() },
                { "offset_left", offsetLeft.ToString() },
                { "offset_top", offsetTop.ToString() },
                { "banner", Convert.ToBase64String(banner) }
            };

            var reqProc = new UserRequestProcessor <User>();

            RawResult =
                await TwitterExecutor.PostFormUrlEncodedToTwitterAsync <User>(
                    HttpMethod.Post.ToString(),
                    accountUrl,
                    parameters,
                    cancelToken)
                .ConfigureAwait(false);

            return(new User());
        }
コード例 #6
0
        /// <summary>
        /// Update account profile info
        /// </summary>
        /// <param name="name">User Name</param>
        /// <param name="url">Web Address</param>
        /// <param name="location">Geographic Location</param>
        /// <param name="description">Personal Description</param>
        /// <param name="includeEntities">Set to false to not include entities. (default: true)</param>
        /// <param name="skipStatus">Don't include status with response.</param>
        /// <param name="callback">Async Callback used in Silverlight queries</param>
        /// <returns>User with new info</returns>
        public static User UpdateAccountProfile(this TwitterContext ctx, string name, string url, string location, string description, bool includeEntities, bool skipStatus, Action <TwitterAsyncResponse <User> > callback)
        {
            var accountUrl = ctx.BaseUrl + "account/update_profile.json";

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

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

            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 reqProc = new UserRequestProcessor <User>();

            ITwitterExecute exec = ctx.TwitterExecutor;

            exec.AsyncCallback = callback;
            var resultsJson =
                exec.PostToTwitter(
                    accountUrl,
                    new Dictionary <string, string>
            {
                { "name", name },
                { "url", url },
                { "location", location },
                { "description", description },
                { "include_entities", includeEntities.ToString().ToLower() },
                { "skip_status", skipStatus.ToString().ToLower() }
            },
                    response => reqProc.ProcessActionResult(response, UserAction.SingleUser));

            User user = reqProc.ProcessActionResult(resultsJson, UserAction.SingleUser);

            return(user);
        }
コード例 #7
0
        /// <summary>
        /// Update account profile info
        /// </summary>
        /// <param name="name">User Name</param>
        /// <param name="url">Web Address</param>
        /// <param name="location">Geographic Location</param>
        /// <param name="description">Personal Description</param>
        /// <param name="includeEntities">Set to false to not include entities. (default: true)</param>
        /// <param name="skipStatus">Don't include status with response.</param>
        /// <returns>User with new info</returns>
        public async Task <User> UpdateAccountProfileAsync(string name, string url, string location, string description, bool includeEntities, bool skipStatus, CancellationToken cancelToken = default(CancellationToken))
        {
            var accountUrl = BaseUrl + "account/update_profile.json";

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

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

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

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

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

            var reqProc = new UserRequestProcessor <User>();

            RawResult =
                await TwitterExecutor.PostFormUrlEncodedToTwitterAsync <User>(
                    HttpMethod.Post.ToString(),
                    accountUrl,
                    new Dictionary <string, string>
            {
                { "name", name },
                { "url", url },
                { "location", location },
                { "description", description },
                { "include_entities", includeEntities.ToString().ToLower() },
                { "skip_status", skipStatus.ToString().ToLower() }
            },
                    cancelToken)
                .ConfigureAwait(false);

            return(reqProc.ProcessActionResult(RawResult, UserAction.SingleUser));
        }
コード例 #8
0
        async Task <User?> UnMuteAsync(IDictionary <string, string?> muteParams, CancellationToken cancelToken = default(CancellationToken))
        {
            var muteUrl = BaseUrl + "mutes/users/destroy.json";

            var reqProc = new UserRequestProcessor <User>();

            RawResult =
                await TwitterExecutor
                .PostFormUrlEncodedToTwitterAsync <User>(HttpMethod.Post.ToString(), muteUrl, muteParams, cancelToken)
                .ConfigureAwait(false);

            return(reqProc.ProcessActionResult(RawResult, UserAction.SingleUser));
        }
コード例 #9
0
        async Task <User> MuteAsync(IDictionary <string, string> muteParams, CancellationToken cancelToken = default(CancellationToken))
        {
            var muteUrl = BaseUrl + "mutes/users/create.json";

            var reqProc = new UserRequestProcessor <User>();

            RawResult =
                await TwitterExecutor
                .PostToTwitterAsync <User>(muteUrl, muteParams, cancelToken)
                .ConfigureAwait(false);

            return(reqProc.ProcessActionResult(RawResult, UserAction.SingleUser));
        }
コード例 #10
0
        /// <summary>
        /// Removes banner from authenticated user's profile.
        /// </summary>
        /// <returns>Empty User instance.</returns>
        public async Task <User> RemoveProfileBannerAsync(CancellationToken cancelToken = default(CancellationToken))
        {
            var accountUrl = BaseUrl + "account/remove_profile_banner.json";

            var reqProc = new UserRequestProcessor <User>();

            RawResult =
                await TwitterExecutor.PostToTwitterAsync <User>(
                    accountUrl,
                    new Dictionary <string, string>(),
                    cancelToken)
                .ConfigureAwait(false);

            return(reqProc.ProcessActionResult(RawResult, UserAction.SingleUser));
        }
コード例 #11
0
        /// <summary>
        /// Removes banner from authenticated user's profile.
        /// </summary>
        /// <returns>Empty User instance.</returns>
        public async Task <User> RemoveProfileBannerAsync(CancellationToken cancelToken = default(CancellationToken))
        {
            var accountUrl = BaseUrl + "account/remove_profile_banner.json";

            var reqProc = new UserRequestProcessor <User>();

            RawResult =
                await TwitterExecutor.PostFormUrlEncodedToTwitterAsync <User>(
                    HttpMethod.Post.ToString(),
                    accountUrl,
                    new Dictionary <string, string?>(),
                    cancelToken)
                .ConfigureAwait(false);

            return(new User());
        }
コード例 #12
0
        /// <summary>
        /// Removes banner from authenticated user's profile.
        /// </summary>
        /// <param name="callback">Async Callback.</param>
        /// <returns>Empty User instance.</returns>
        public static User RemoveProfileBanner(this TwitterContext ctx, Action <TwitterAsyncResponse <User> > callback)
        {
            var accountUrl = ctx.BaseUrl + "account/remove_profile_banner.json";

            var reqProc = new UserRequestProcessor <User>();

            ITwitterExecute exec = ctx.TwitterExecutor;

            exec.AsyncCallback = callback;
            var resultsJson =
                exec.PostToTwitter(
                    accountUrl,
                    new Dictionary <string, string>(),
                    response => reqProc.ProcessActionResult(response, UserAction.SingleUser));

            User user = reqProc.ProcessActionResult(resultsJson, UserAction.SingleUser);

            return(user);
        }
コード例 #13
0
        /// <summary>
        /// Sends an image to Twitter to be placed as the user's profile banner.
        /// </summary>
        /// <param name="banner">byte[] containing image data.</param>
        /// <param name="width">Pixel width to clip image.</param>
        /// <param name="height">Pixel height to clip image.</param>
        /// <param name="offsetLeft">Pixels to offset start of image from the left.</param>
        /// <param name="offsetTop">Pixels to offset start of image from the top.</param>
        /// <param name="callback">Async callback routine.</param>
        /// <returns>
        /// Account of authenticated user who's profile banner will be updated.
        /// Url of new banner will appear in ProfileBannerUrl property.
        /// </returns>
        public static User UpdateProfileBanner(this TwitterContext ctx, byte[] banner, string fileName, string imageType, int width, int height, int offsetLeft, int offsetTop, Action <TwitterAsyncResponse <User> > callback)
        {
            var accountUrl = ctx.BaseUrl + "account/update_profile_banner.json";

            if (banner == null || banner.Length == 0)
            {
                throw new ArgumentException("banner is required.", "banner");
            }

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

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

            var parameters = new Dictionary <string, string>
            {
                { "width", width.ToString() },
                { "height", height.ToString() },
                { "offset_left", offsetLeft.ToString() },
                { "offset_top", offsetTop.ToString() },
                { "banner", "IMAGE_DATA" }
            };

            var reqProc = new UserRequestProcessor <User>();

            ITwitterExecute exec = ctx.TwitterExecutor;

            exec.AsyncCallback = callback;
            var resultsJson =
                exec.PostTwitterImage(accountUrl, parameters, banner, fileName, imageType, reqProc);

            User user = reqProc.ProcessActionResult(resultsJson, UserAction.SingleUser);

            return(user);
        }
コード例 #14
0
        /// <summary>
        /// Allows removal of background image by setting back to the default background.  Once the background image is removed
        /// it can not be turned back on.
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="skipStatus">Don't include status with response.</param>
        /// <returns></returns>
        public static User RemoveBackgroundImage(this TwitterContext ctx, bool skipStatus, Action <TwitterAsyncResponse <User> > callback)
        {
            var accountUrl = ctx.BaseUrl + "account/update_profile_background_image.json";
            var reqProc    = new UserRequestProcessor <User>();

            ITwitterExecute exec = ctx.TwitterExecutor;

            exec.AsyncCallback = callback;
            var resultsJson =
                exec.PostToTwitter(
                    accountUrl,
                    new Dictionary <string, string>
            {
                { "use", "false" },
                { "skip_status", skipStatus.ToString() }
            },
                    response => reqProc.ProcessActionResult(response, UserAction.SingleUser));

            User user = reqProc.ProcessActionResult(resultsJson, UserAction.SingleUser);

            return(user);
        }
コード例 #15
0
        /// <summary>
        /// Sends an image to Twitter to be placed as the user's profile banner.
        /// </summary>
        /// <param name="banner">byte[] containing image data.</param>
        /// <param name="fileName">Name of file.</param>
        /// <param name="imageType">Type of file (e.g. png or jpg)</param>
        /// <param name="width">Pixel width to clip image.</param>
        /// <param name="height">Pixel height to clip image.</param>
        /// <param name="offsetLeft">Pixels to offset start of image from the left.</param>
        /// <param name="offsetTop">Pixels to offset start of image from the top.</param>
        /// <returns>
        /// Account of authenticated user who's profile banner will be updated.
        /// Url of new banner will appear in ProfileBannerUrl property.
        /// </returns>
        public async Task <User> UpdateProfileBannerAsync(byte[] banner, string fileName, string imageType, int width, int height, int offsetLeft, int offsetTop, CancellationToken cancelToken = default(CancellationToken))
        {
            var accountUrl = BaseUrl + "account/update_profile_banner.json";

            if (banner == null || banner.Length == 0)
            {
                throw new ArgumentException("banner is required.", "banner");
            }

            if (string.IsNullOrWhiteSpace(fileName))
            {
                throw new ArgumentException("fileName is required.", "fileName");
            }

            if (string.IsNullOrWhiteSpace(imageType))
            {
                throw new ArgumentException("imageType is required.", "imageType");
            }

            var parameters = new Dictionary <string, string>
            {
                { "width", width.ToString() },
                { "height", height.ToString() },
                { "offset_left", offsetLeft.ToString() },
                { "offset_top", offsetTop.ToString() },
                //{ "banner", "FILE_DATA" }
            };

            var reqProc = new UserRequestProcessor <User>();

            string name          = "banner";
            string imageMimeType = "image/" + imageType;
            string mediaCategory = "tweet_image";

            RawResult = await TwitterExecutor.PostMediaAsync(accountUrl, parameters, banner, name, fileName, imageMimeType, mediaCategory, shared : false, cancelToken : cancelToken).ConfigureAwait(false);

            return(reqProc.ProcessActionResult(RawResult, UserAction.SingleUser));
        }
コード例 #16
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>
        /// <param name="includeEntities">Set to false to not include entities. (default: true)</param>
        /// <param name="skipStatus">Don't include status with response.</param>
        /// <param name="callback">Async Callback used in Silverlight queries</param>
        /// <returns>User info with new colors</returns>
        public static User UpdateAccountColors(this TwitterContext ctx, string background, string text, string link, string sidebarFill, string sidebarBorder, bool includeEntities, bool skipStatus, Action <TwitterAsyncResponse <User> > callback)
        {
            var accountUrl = ctx.BaseUrl + "account/update_profile_colors.json";

            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.", NoInputParam);
            }

            var reqProc = new UserRequestProcessor <User>();

            ITwitterExecute exec = ctx.TwitterExecutor;

            exec.AsyncCallback = callback;
            var resultsJson =
                exec.PostToTwitter(
                    accountUrl,
                    new Dictionary <string, string>
            {
                { "profile_background_color", string.IsNullOrEmpty(background) ? (string)null : background.TrimStart('#') },
                { "profile_text_color", string.IsNullOrEmpty(text) ? (string)null : text.TrimStart('#') },
                { "profile_link_color", string.IsNullOrEmpty(link) ? (string)null : link.TrimStart('#') },
                { "profile_sidebar_fill_color", string.IsNullOrEmpty(sidebarFill) ? (string)null : sidebarFill.TrimStart('#') },
                { "profile_sidebar_border_color", string.IsNullOrEmpty(sidebarBorder) ? (string)null : sidebarBorder.TrimStart('#') },
                { "include_entities", includeEntities.ToString().ToLower() },
                { "skip_status", skipStatus.ToString().ToLower() }
            },
                    response => reqProc.ProcessActionResult(response, UserAction.SingleUser));

            User user = reqProc.ProcessActionResult(resultsJson, UserAction.SingleUser);

            return(user);
        }
コード例 #17
0
        /// <summary>
        /// sends an image file to Twitter to replace user image
        /// </summary>
        /// <remarks>
        /// You can only run this method with a period of time between executions;
        /// otherwise you get WebException errors from Twitter
        /// </remarks>
        /// <param name="image">byte array of image to upload</param>
        /// <param name="fileName">name to pass to Twitter for the file</param>
        /// <param name="imageType">type of image: must be one of jpg, gif, or png</param>
        /// <param name="includeEntities">Set to false to not include entities. (default: true)</param>
        /// <param name="skipStatus">Don't include status with response.</param>
        /// <param name="callback">Async Callback used in Silverlight queries</param>
        /// <returns>User with new image info</returns>
        public static User UpdateAccountImage(this TwitterContext ctx, byte[] image, string fileName, string imageType, bool includeEntities, bool skipStatus, Action <TwitterAsyncResponse <User> > callback)
        {
            var accountUrl = ctx.BaseUrl + "account/update_profile_image.json";

            if (image == null || image.Length == 0)
            {
                throw new ArgumentException("image is required.", "image");
            }

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

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

            var reqProc    = new UserRequestProcessor <User>();
            var parameters = new Dictionary <string, string>
            {
                { "include_entities", includeEntities.ToString().ToLower() },
                { "skip_status", skipStatus.ToString().ToLower() }
            };

            ITwitterExecute exec = ctx.TwitterExecutor;

            exec.AsyncCallback = callback;
            var resultsJson =
                exec.PostTwitterImage(accountUrl, parameters, image, fileName, imageType, reqProc);

            User user = reqProc.ProcessActionResult(resultsJson, UserAction.SingleUser);

            return(user);
        }
コード例 #18
0
ファイル: TwitterContext.cs プロジェクト: chteam/choj
        /// <summary>
        /// factory method for returning a request processor
        /// </summary>
        /// <typeparam name="T">type of request</typeparam>
        /// <returns>request processor matching type parameter</returns>
        private IRequestProcessor CreateRequestProcessor(Expression expression, bool isEnumerable)
        {
            string requestType = string.Empty;

            if (expression != null)
            {
                if (isEnumerable)
                {
                    requestType = expression.Type.GetGenericArguments()[0].Name;
                }
                else
                {
                    requestType = expression.Type.Name;
                }
            }

            IRequestProcessor req;

            switch (requestType)
            {
            case "Account":
                req = new AccountRequestProcessor()
                {
                    BaseUrl = BaseUrl
                };
                break;

            case "Blocks":
                req = new BlocksRequestProcessor()
                {
                    BaseUrl = BaseUrl
                };
                break;

            case "DirectMessage":
                req = new DirectMessageRequestProcessor()
                {
                    BaseUrl = BaseUrl
                };
                break;

            case "Favorites":
                req = new FavoritesRequestProcessor()
                {
                    BaseUrl = BaseUrl
                };
                break;

            case "Friendship":
                req = new FriendshipRequestProcessor()
                {
                    BaseUrl = BaseUrl
                };
                break;

            case "SocialGraph":
                req = new SocialGraphRequestProcessor()
                {
                    BaseUrl = BaseUrl
                };
                break;

            case "Search":
                req = new SearchRequestProcessor()
                {
                    BaseUrl = SearchUrl
                };
                break;

            case "Status":
                req = new StatusRequestProcessor()
                {
                    BaseUrl = BaseUrl
                };
                break;

            case "Trend":
                req = new TrendRequestProcessor()
                {
                    BaseUrl = SearchUrl
                };
                break;

            case "User":
                req = new UserRequestProcessor()
                {
                    BaseUrl = BaseUrl
                };
                break;

            default:
                req = new StatusRequestProcessor()
                {
                    BaseUrl = BaseUrl
                };
                break;
            }

            Debug.Assert(req != null, "You you must assign a value to req.");

            return(req);
        }
コード例 #19
0
        /// <summary>
        /// Sends an image file to Twitter to replace background image.
        /// </summary>
        /// <param name="image">full path to file, including file name</param>
        /// <param name="mediaID">ID of media to use (posted via UploadMediaAsync)</param>
        /// <param name="fileName">name to pass to Twitter for the file</param>
        /// <param name="imageType">type of image: must be one of jpg, gif, or png</param>
        /// <param name="tile">Tile image across background.</param>
        /// <param name="includeEntities">Set to false to not include entities. (default: true)</param>
        /// <param name="skipStatus">Don't include status with response.</param>
        /// <returns>User with new image info</returns>
        public async Task <User> UpdateAccountBackgroundImageAsync(byte[] image, ulong mediaID, string fileName, string imageType, bool tile, bool includeEntities, bool skipStatus, CancellationToken cancelToken = default(CancellationToken))
        {
            var accountUrl = BaseUrl + "account/update_profile_background_image.json";

            if (mediaID == NoMediaID && image == NoImage)
            {
                throw new ArgumentException("Either image or mediaID must be provided, but you haven't specified one.", nameof(image) + "Or" + nameof(mediaID));
            }

            if (mediaID == NoMediaID && image.Length == 0)
            {
                throw new ArgumentException("Invalid image", nameof(image));
            }

            if (image != NoImage && mediaID != NoMediaID)
            {
                throw new ArgumentException("Either image or mediaID must be provided, but not both", nameof(image) + "Or" + nameof(mediaID));
            }

            if (string.IsNullOrWhiteSpace(fileName))
            {
                throw new ArgumentException("fileName is required.", nameof(fileName));
            }

            if (string.IsNullOrWhiteSpace(imageType))
            {
                throw new ArgumentException("imageType is required.", nameof(imageType));
            }

            var parameters = new Dictionary <string, string>
            {
                { "include_entities", includeEntities.ToString().ToLower() },
                { "skip_status", skipStatus.ToString().ToLower() }
            };

            if (tile)
            {
                parameters.Add("tile", true.ToString().ToLower());
            }

            if (mediaID != NoMediaID)
            {
                parameters.Add("media_id", mediaID.ToString());
            }

            var reqProc = new UserRequestProcessor <User>();

            string name          = "image";
            string imageMimeType = "image/" + imageType;
            string mediaCategory = "tweet_image";

            if (image != NoImage)
            {
                RawResult = await TwitterExecutor.PostMediaAsync(accountUrl, parameters, image, name, fileName, imageMimeType, mediaCategory, shared : false, cancelToken : cancelToken).ConfigureAwait(false);
            }
            else
            {
                RawResult = await TwitterExecutor.PostFormUrlEncodedToTwitterAsync <User>(HttpMethod.Post.ToString(), accountUrl, parameters, cancelToken).ConfigureAwait(false);
            }

            return(reqProc.ProcessActionResult(RawResult, UserAction.SingleUser));
        }
コード例 #20
0
        protected internal IRequestProcessor <T> CreateRequestProcessor <T>(string requestType)
            where T : class
        {
            var baseUrl = BaseUrl;
            IRequestProcessor <T> req;

            switch (requestType)
            {
            case "Account":
                req = new AccountRequestProcessor <T>();
                break;

            case "Blocks":
                req = new BlocksRequestProcessor <T>();
                break;

            case "ControlStream":
                req = new ControlStreamRequestProcessor <T>
                {
                    SiteStreamUrl = SiteStreamUrl
                };
                break;

            case "DirectMessage":
                req = new DirectMessageRequestProcessor <T>();
                break;

            case "Favorites":
                req = new FavoritesRequestProcessor <T>();
                break;

            case "Friendship":
                req = new FriendshipRequestProcessor <T>();
                break;

            case "Geo":
                req = new GeoRequestProcessor <T>();
                break;

            case "Help":
                req = new HelpRequestProcessor <T>();
                break;

            case "List":
                req = new ListRequestProcessor <T>();
                break;

            case "Mute":
                req = new MuteRequestProcessor <T>();
                break;

            case "Raw":
                req = new RawRequestProcessor <T>();
                break;

            case "SavedSearch":
                req = new SavedSearchRequestProcessor <T>();
                break;

            case "Search":
                req = new SearchRequestProcessor <T>();
                break;

            case "Status":
                req = new StatusRequestProcessor <T>();
                break;

            case "Streaming":
                baseUrl = StreamingUrl;
                req     = new StreamingRequestProcessor <T>
                {
                    UserStreamUrl   = UserStreamUrl,
                    SiteStreamUrl   = SiteStreamUrl,
                    TwitterExecutor = TwitterExecutor
                };
                break;

            case "Trend":
                req = new TrendRequestProcessor <T>();
                break;

            case "User":
                req = new UserRequestProcessor <T>();
                break;

            case "Vine":
                req = new VineRequestProcessor <T>
                {
                    VineUrl = VineUrl
                };
                break;

            default:
                throw new ArgumentException("Type, " + requestType + " isn't a supported LINQ to Twitter entity.", "requestType");
            }

            if (baseUrl != null)
            {
                req.BaseUrl = baseUrl;
            }

            return(req);
        }
コード例 #21
0
        protected internal IRequestProcessor <T> CreateRequestProcessor <T>(string requestType)
            where T : class
        {
            string baseUrl = BaseUrl;
            IRequestProcessor <T> req;

            switch (requestType)
            {
            case nameof(Account):
                req = new AccountRequestProcessor <T>();
                break;

            case nameof(AccountActivity):
                req = new AccountActivityRequestProcessor <T>();
                break;

            case nameof(Blocks):
                req = new BlocksRequestProcessor <T>();
                break;

            case nameof(ControlStream):
                req = new ControlStreamRequestProcessor <T>
                {
                    SiteStreamUrl = SiteStreamUrl
                };
                break;

            case nameof(DirectMessage):
                req = new DirectMessageRequestProcessor <T>();
                break;

            case nameof(DirectMessageEvents):
                req = new DirectMessageEventsRequestProcessor <T>();
                break;

            case nameof(Favorites):
                req = new FavoritesRequestProcessor <T>();
                break;

            case nameof(Friendship):
                req = new FriendshipRequestProcessor <T>();
                break;

            case nameof(Geo):
                req = new GeoRequestProcessor <T>();
                break;

            case nameof(Help):
                req = new HelpRequestProcessor <T>();
                break;

            case nameof(List):
                req = new ListRequestProcessor <T>();
                break;

            case nameof(Media):
                req = new MediaRequestProcessor <T>
                {
                    UploadUrl = UploadUrl
                };
                break;

            case nameof(Mute):
                req = new MuteRequestProcessor <T>();
                break;

            case nameof(Raw):
                req = new RawRequestProcessor <T>();
                break;

            case nameof(SavedSearch):
                req = new SavedSearchRequestProcessor <T>();
                break;

            case nameof(Search):
                req = new SearchRequestProcessor <T>();
                break;

            case nameof(Status):
                req = new StatusRequestProcessor <T>();
                break;

            case nameof(Streaming):
                baseUrl = StreamingUrl;
                req     = new StreamingRequestProcessor <T>
                {
                    UserStreamUrl   = UserStreamUrl,
                    SiteStreamUrl   = SiteStreamUrl,
                    TwitterExecutor = TwitterExecutor
                };
                break;

            case nameof(Trend):
                req = new TrendRequestProcessor <T>();
                break;

            case nameof(User):
                req = new UserRequestProcessor <T>();
                break;

            case nameof(Vine):
                req = new VineRequestProcessor <T>
                {
                    VineUrl = VineUrl
                };
                break;

            case nameof(WelcomeMessage):
                req = new WelcomeMessageRequestProcessor <T>();
                break;

            default:
                throw new ArgumentException($"Type, {requestType} isn't a supported LINQ to Twitter entity.", nameof(requestType));
            }

            if (baseUrl != null)
            {
                req.BaseUrl = baseUrl;
            }

            return(req);
        }