/// <summary> /// Uploads a media (e.g. media) to be attached to a subsequent tweet. /// </summary> /// <param name="media">Media to upload</param> /// <param name="mediaType">Type of media. e.g. image/jpg, image/png, or video/mp4.</param> /// <param name="additionalOwners">User IDs of accounts that can used the returned media IDs</param> /// <param name="cancelToken">Allows you to cancel async operation</param> /// <returns>Status containing new reply</returns> public virtual async Task <Media> UploadMediaAsync(byte[] media, string mediaType, IEnumerable <ulong> additionalOwners, CancellationToken cancelToken = default(CancellationToken)) { if (media == null || media.Length == 0) { throw new ArgumentNullException("image", "You must provide a byte[] of image data."); } string updateUrl = UploadUrl + "media/upload.json"; string name = "media"; string randomUnusedFileName = new Random().Next(100, 999).ToString(); var parameters = new Dictionary <string, string>(); if (additionalOwners != null && additionalOwners.Any()) { parameters.Add("additional_owners", string.Join(",", additionalOwners)); } var reqProc = new StatusRequestProcessor <Status>(); RawResult = await TwitterExecutor.PostMediaAsync( updateUrl, new Dictionary <string, string>(), media, name, randomUnusedFileName, mediaType, cancelToken) .ConfigureAwait(false); Status status = reqProc.ProcessActionResult(RawResult, StatusAction.MediaUpload); return(status.Media); }
/// <summary> /// Deletes a favorite from the logged-in user's profile. /// </summary> /// <param name="id">id of status to add to favorites</param> /// <param name="includeEntities">Response doesn't include entities when false. (default: true)</param> /// <returns>status of favorite</returns> public async Task <Status> DestroyFavoriteAsync(ulong id, bool includeEntities, CancellationToken cancelToken = default(CancellationToken)) { if (id == 0) { throw new ArgumentException("id is a required parameter.", "id"); } var favoritesUrl = BaseUrl + "favorites/destroy.json"; var reqProc = new StatusRequestProcessor <Status>(); RawResult = await TwitterExecutor.PostFormUrlEncodedToTwitterAsync <Status>( HttpMethod.Post.ToString(), favoritesUrl, new Dictionary <string, string> { { "id", id.ToString() }, { "include_entities", includeEntities.ToString() } }, cancelToken) .ConfigureAwait(false); return(reqProc.ProcessActionResult(RawResult, FavoritesAction.SingleStatus)); }
/// <summary> /// Uploads a media (e.g. media) to be attached to a subsequent tweet. /// </summary> /// <param name="media">Media to upload</param> /// <param name="cancelToken">Allows you to cancel async operation</param> /// <returns>Status containing new reply</returns> public async Task <Media> UploadMediaAsync(byte[] media, CancellationToken cancelToken = default(CancellationToken)) { if (media == null || media.Length == 0) { throw new ArgumentNullException("image", "You must provide a byte[] of image data."); } string updateUrl = UploadUrl + "media/upload.json"; string imageType = "application/octet-stream"; string name = "media"; string randomUnusedFileName = new Random().Next(100, 999).ToString(); var reqProc = new StatusRequestProcessor <Status>(); RawResult = await TwitterExecutor.PostMediaAsync( updateUrl, new Dictionary <string, string>(), media, name, randomUnusedFileName, imageType, cancelToken) .ConfigureAwait(false); Status status = reqProc.ProcessActionResult(RawResult, StatusAction.MediaUpload); return(status.Media); }
/// <summary> /// sends a status update /// </summary> /// <param name="status">(optional @UserName) and (required) status text</param> /// <param name="latitude">Latitude coordinate of where tweet occurred</param> /// <param name="longitude">Longitude coordinate of where tweet occurred</param> /// <param name="placeID">ID of place (found via Geo Reverse lookup query)</param> /// <param name="displayCoordinates">Allow or prevent display of coordinates for this tweet</param> /// <param name="inReplyToStatusID">id of status replying to - optional - pass null if not used</param> /// <param name="callback">Async Callback used in Silverlight queries</param> /// <returns>IQueryable of sent status</returns> public static Status UpdateStatus(this TwitterContext ctx, string status, decimal latitude, decimal longitude, string placeID, bool displayCoordinates, string inReplyToStatusID, bool trimUser, Action <TwitterAsyncResponse <Status> > callback) { if (string.IsNullOrEmpty(status)) { throw new ArgumentException("status is a required parameter.", "status"); } var updateUrl = ctx.BaseUrl + "statuses/update.json"; var reqProc = new StatusRequestProcessor <Status>(); ITwitterExecute exec = ctx.TwitterExecutor; exec.AsyncCallback = callback; var resultsJson = exec.PostToTwitter( updateUrl, new Dictionary <string, string> { { "status", status }, { "in_reply_to_status_id", inReplyToStatusID }, { "lat", latitude == -1 ? null : latitude.ToString(Culture.US) }, { "long", longitude == -1 ? null : longitude.ToString(Culture.US) }, { "place_id", placeID }, { "display_coordinates", displayCoordinates ? displayCoordinates.ToString().ToLower() : null }, { "trim_user", trimUser ? trimUser.ToString().ToLower() : null } }, response => reqProc.ProcessActionResult(response, StatusAction.SingleStatus)); Status result = reqProc.ProcessActionResult(resultsJson, StatusAction.SingleStatus); return(result); }
/// <summary> /// Deletes a favorite from the logged-in user's profile /// </summary> /// <param name="id">id of status to add to favorites</param> /// <param name="includeEntities">Response doesn't include entities when false. (default: true)</param> /// <param name="callback">Async Callback used in Silverlight queries</param> /// <returns>status of favorite</returns> public static Status DestroyFavorite(this TwitterContext ctx, string id, bool includeEntities, Action <TwitterAsyncResponse <Status> > callback) { if (string.IsNullOrEmpty(id)) { throw new ArgumentException("id is a required parameter.", "id"); } var favoritesUrl = ctx.BaseUrl + "favorites/destroy.json"; var reqProc = new StatusRequestProcessor <Status>(); ITwitterExecute twitExe = ctx.TwitterExecutor; twitExe.AsyncCallback = callback; var resultsJson = twitExe.PostToTwitter( favoritesUrl, new Dictionary <string, string> { { "id", id }, { "include_entities", includeEntities.ToString() } }, response => reqProc.ProcessActionResult(response, FavoritesAction.SingleStatus)); Status result = reqProc.ProcessActionResult(resultsJson, FavoritesAction.SingleStatus); return(result); }
/// <summary> /// sends a status update with attached media /// </summary> /// <param name="twitterCtx">Your instance of TwitterContext</param> /// <param name="inReplyToStatusID">id of status replying to - optional - pass null if not used</param> /// <param name="status">(optional @UserName) and (required) status text</param> /// <param name="possiblySensitive">Set to true if media does not contain age appropriate content</param> /// <param name="latitude">Latitude coordinate of where tweet occurred</param> /// <param name="longitude">Longitude coordinate of where tweet occurred</param> /// <param name="placeID">ID of place (found via Geo Reverse lookup query)</param> /// <param name="displayCoordinates">Allow or prevent display of coordinates for this tweet</param> /// <param name="mediaItems">List of Media to send</param> /// <param name="callback">Async callback handler</param> /// <returns>Status containing new reply</returns> public static Status ReplyWithMedia(this TwitterContext twitterCtx, ulong inReplyToStatusID, string status, bool possiblySensitive, decimal latitude, decimal longitude, string placeID, bool displayCoordinates, List <Media> mediaItems, Action <TwitterAsyncResponse <Status> > callback) { if (string.IsNullOrEmpty(status)) { throw new ArgumentNullException("status", "status is a required parameter."); } if (mediaItems == null) { throw new ArgumentNullException("mediaItems", "You must pass at least one Media in mediaItems."); } if (mediaItems.Count == 0) { throw new ArgumentException("You must pass at least one Media in mediaItems.", "mediaItems"); } twitterCtx.TwitterExecutor.AsyncCallback = callback; var updateUrl = twitterCtx.BaseUrl + "statuses/update_with_media.json"; var reqProc = new StatusRequestProcessor <Status>(); string resultString = twitterCtx.TwitterExecutor.PostMedia( updateUrl, new Dictionary <string, string> { { "status", status }, { "possibly_sensitive", possiblySensitive ? true.ToString() : null }, { "lat", latitude == NoCoordinate ? null : latitude.ToString(Culture.US) }, { "long", longitude == NoCoordinate ? null : longitude.ToString(Culture.US) }, { "place_id", string.IsNullOrEmpty(placeID) ? null : placeID }, { "display_coordinates", displayCoordinates ? true.ToString() : null }, { "in_reply_to_status_id", inReplyToStatusID == NoReply ? null : inReplyToStatusID.ToString(CultureInfo.InvariantCulture) } }, mediaItems, reqProc); Status result = reqProc.ProcessActionResult(resultString, StatusAction.SingleStatus); return(result); }
public async Task <Status> ReplyWithMediaAsync(ulong inReplyToStatusID, string status, bool possiblySensitive, decimal latitude, decimal longitude, string placeID, bool displayCoordinates, byte[] image, CancellationToken cancelToken = default(CancellationToken)) { if (string.IsNullOrWhiteSpace(status)) { throw new ArgumentNullException("status", "status is a required parameter."); } if (image == null || image.Length == 0) { throw new ArgumentNullException("image", "You must provide a byte[] of image data."); } string updateUrl = BaseUrl + "statuses/update_with_media.json"; string imageType = "application/octet-stream"; string name = "media[]"; string randomUnusedFileName = new Random().Next(100, 999).ToString(); var reqProc = new StatusRequestProcessor <Status>(); RawResult = await TwitterExecutor.PostMediaAsync( updateUrl, new Dictionary <string, string> { { "status", status }, { "possibly_sensitive", possiblySensitive ? true.ToString() : null }, { "lat", latitude == NoCoordinate ? null : latitude.ToString(Culture.US) }, { "long", longitude == NoCoordinate ? null : longitude.ToString(Culture.US) }, { "place_id", string.IsNullOrWhiteSpace(placeID) ? null : placeID }, { "display_coordinates", displayCoordinates ? true.ToString() : null }, { "in_reply_to_status_id", inReplyToStatusID == NoReply ? null : inReplyToStatusID.ToString(CultureInfo.InvariantCulture) } }, image, name, randomUnusedFileName, imageType, cancelToken) .ConfigureAwait(false); return(reqProc.ProcessActionResult(RawResult, StatusAction.SingleStatus)); }
/// <summary> /// retweets a tweet /// </summary> /// <param name="id">id of status tweet</param> /// <param name="callback">Async Callback used in Silverlight queries</param> /// <returns>deleted status tweet</returns> public static Status Retweet(this TwitterContext ctx, string id, Action <TwitterAsyncResponse <Status> > callback) { if (string.IsNullOrEmpty(id)) { throw new ArgumentException("id is a required parameter.", "id"); } var retweetUrl = ctx.BaseUrl + "statuses/retweet/" + id + ".json"; var reqProc = new StatusRequestProcessor <Status>(); ITwitterExecute exec = ctx.TwitterExecutor; exec.AsyncCallback = callback; var resultsJson = exec.PostToTwitter( retweetUrl, new Dictionary <string, string>(), response => reqProc.ProcessActionResult(response, StatusAction.SingleStatus)); Status result = reqProc.ProcessActionResult(resultsJson, StatusAction.SingleStatus); return(result); }
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); }
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); }
/// <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); }