public async Task <PostStatusParams> UploadAsync(IMediaItem[] mediaItems, PostStatusParams postParams) { if (mediaItems == null) { throw new ArgumentNullException(nameof(mediaItems)); } if (mediaItems.Length == 0) { throw new ArgumentException("Err:Media not specified."); } foreach (var item in mediaItems) { if (item == null) { throw new ArgumentException("Err:Media not specified."); } if (!item.Exists) { throw new ArgumentException("Err:Media not found."); } } var uploadTasks = from m in mediaItems select this.UploadMediaItem(m); var mediaIds = await Task.WhenAll(uploadTasks) .ConfigureAwait(false); postParams.MediaIds = mediaIds; return(postParams); }
public async Task <PostStatusParams> UploadAsync(IMediaItem[] mediaItems, PostStatusParams postParams) { if (mediaItems == null) { throw new ArgumentNullException(nameof(mediaItems)); } if (mediaItems.Length != 1) { throw new ArgumentOutOfRangeException(nameof(mediaItems)); } var item = mediaItems[0]; if (item == null) { throw new ArgumentException("Err:Media not specified."); } if (!item.Exists) { throw new ArgumentException("Err:Media not found."); } XDocument xml; try { xml = await this.imgurApi.UploadFileAsync(item, postParams.Text) .ConfigureAwait(false); } catch (HttpRequestException ex) { throw new WebApiException("Err:" + ex.Message, ex); } catch (OperationCanceledException ex) { throw new WebApiException("Err:Timeout", ex); } var imageElm = xml.Element("data"); if (imageElm.Attribute("success").Value != "1") { throw new WebApiException("Err:" + imageElm.Attribute("status").Value); } var imageUrl = imageElm.Element("link").Value; postParams.Text += " " + imageUrl.Trim(); return(postParams); }
public async Task <PostStatusParams> UploadAsync(IMediaItem[] mediaItems, PostStatusParams postParams) { if (mediaItems == null) { throw new ArgumentNullException(nameof(mediaItems)); } if (mediaItems.Length == 0) { throw new ArgumentException("Err:Media not specified."); } foreach (var item in mediaItems) { if (item == null) { throw new ArgumentException("Err:Media not specified."); } if (!item.Exists) { throw new ArgumentException("Err:Media not found."); } } long[] mediaIds; if (Twitter.DMSendTextRegex.IsMatch(postParams.Text)) { mediaIds = new[] { await this.UploadMediaForDM(mediaItems).ConfigureAwait(false) } } ; else { mediaIds = await this.UploadMediaForTweet(mediaItems).ConfigureAwait(false); } postParams.MediaIds = mediaIds; return(postParams); }
public async Task <PostStatusParams> UploadAsync(IMediaItem[] mediaItems, PostStatusParams postParams) { if (mediaItems == null) { throw new ArgumentNullException(nameof(mediaItems)); } if (mediaItems.Length != 1) { throw new ArgumentOutOfRangeException(nameof(mediaItems)); } var item = mediaItems[0]; if (item == null) { throw new ArgumentException("Err:Media not specified."); } if (!item.Exists) { throw new ArgumentException("Err:Media not found."); } var xml = await this.mobypictureApi.UploadFileAsync(item, postParams.Text) .ConfigureAwait(false); var imageUrlElm = xml.XPathSelectElement("/rsp/media/mediaurl"); if (imageUrlElm == null) { throw new WebApiException("Invalid API response", xml.ToString()); } postParams.Text += " " + imageUrlElm.Value.Trim(); return(postParams); }