public async Task UploadImageUrlAsync_Equal() { var mockUrl = "https://api.imgur.com/3/image"; var mockResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(MockImageEndpointResponses.Imgur.UploadImage) }; var client = new ImgurClient("123", "1234"); var endpoint = new ImageEndpoint(client, new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse))); var image = await endpoint.UploadImageUrlAsync("http://i.imgur.com/kiNOcUl.gif").ConfigureAwait(false); Assert.NotNull(image); Assert.Equal(true, image.Animated); Assert.Equal(0, image.Bandwidth); Assert.Equal(new DateTimeOffset(new DateTime(2015, 8, 23, 23, 43, 31, DateTimeKind.Utc)), image.DateTime); Assert.Equal("nGxOKC9ML6KyTWQ", image.DeleteHash); Assert.Equal("Description Test", image.Description); Assert.Equal(false, image.Favorite); Assert.Equal("http://i.imgur.com/kiNOcUl.gifv", image.Gifv); Assert.Equal(189, image.Height); Assert.Equal("kiNOcUl", image.Id); Assert.Equal("http://i.imgur.com/kiNOcUl.gif", image.Link); Assert.Equal(true, image.Looping); Assert.Equal("http://i.imgur.com/kiNOcUl.mp4", image.Mp4); Assert.Equal("", image.Name); Assert.Equal(null, image.Nsfw); Assert.Equal(null, image.Section); Assert.Equal(1038889, image.Size); Assert.Equal("Title Test", image.Title); Assert.Equal("image/gif", image.Type); Assert.Equal(0, image.Views); Assert.Equal(null, image.Vote); Assert.Equal(290, image.Width); }
public static async Task <IImage> UploadImageAsync(string url, string albumId = null, string name = null, string description = null) { var endpoint = new ImageEndpoint(Client); var image = await endpoint.UploadImageUrlAsync(url, albumId, name, description); return(image); }
internal static async Task Osu(ReceivedMessage Message) { var client = new ImgurClient(Bot.Config["ImgurId"], Bot.Config["ImgurSecret"]); var endpoint = new ImageEndpoint(client); var Image = await endpoint.UploadImageUrlAsync($"http://lemmmy.pw/osusig/sig.php?uname={Message.Text}&flagshadow&xpbar&xpbarhex&pp=2"); await Message.Respond($"{Image.Link}\nhttps://osu.ppy.sh/u/{Uri.EscapeDataString(Message.Text)}", false); }
private async Task <DialogTurnResult> WriteReportStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { //_logger.LogInformation($"TripReportDialog.WriteReportStepAsync"); var callbackOptions = (CallbackOptions)stepContext.Options; var answers = (ReportAnswers)stepContext.Values[ReportAnswersKey]; var userProfileTemporary = await _userProfileTemporaryAccessor.GetAsync(stepContext.Context); try { if (stepContext.Context.Activity.Attachments != null && stepContext.Context.Activity.Attachments.Count >= 1) { // Intercept image attachments here foreach (Attachment attachment in stepContext.Context.Activity.Attachments) { if (answers.PhotoURLs == null) { answers.PhotoURLs = new string[] { }; } if (attachment.ContentType.StartsWith("image/", StringComparison.InvariantCulture)) { var webClient = new WebClient(); byte[] attachmentImgBytes = webClient.DownloadData(attachment.ContentUrl); // Upload to Imgur // uses: https://github.com/lauchacarro/Imgur-NetCore var client = new ImgurClient(Consts.IMGUR_API_CLIENT_ID, Consts.IMGUR_API_CLIENT_SECRET); var endpoint = new ImageEndpoint(client); var image = await endpoint.UploadImageUrlAsync( //"http://randonauts.com/randonauts.jpg", attachment.ContentUrl, title : ("Randonaut Trip Report Photo" + ((callbackOptions.NearestPlaces != null && callbackOptions.NearestPlaces.Length >= 1) ? (" from " + callbackOptions.NearestPlaces[answers.PointNumberVisited]) : " from somewhere in the multiverse")), // TODO f**k I should stop trying to condense so much into one line in C#. I'm just drunk and lazy ATM. Now I'm just copy/pasting the same code in the morning sober... I'll come back to this really long one day and laugh :D description : (userProfileTemporary.UserId + " " + callbackOptions.ShortCodes[answers.PointNumberVisited]) ); answers.PhotoURLs = answers.PhotoURLs.Concat(new string[] { image.Link }).ToArray(); // Code for if passing the photo URLs over to reddit self posting logic directly //answers.PhotoURLs = answers.PhotoURLs.Concat(new string[] { attachment.ContentUrl }).ToArray(); } } } } catch (Exception e) { await stepContext.Context.SendActivityAsync(MessageFactory.Text($"Sorry, there was an error uploading your photo. ({e.GetType().Name}: {e.Message})")); } var promptOptions = new PromptOptions { Prompt = MessageFactory.Text("Lastly, write up your report. Typing up your report is limited to being sent in one message.") }; return(await stepContext.PromptAsync(nameof(TextPrompt), promptOptions, cancellationToken)); }
public async Task UploadImageUrlAsync_WithUrlNull_ThrowsArgumentNullException() { var client = new ImgurClient("123", "1234"); var endpoint = new ImageEndpoint(client); var exception = await Record.ExceptionAsync( async() => await endpoint.UploadImageUrlAsync(null).ConfigureAwait(false)) .ConfigureAwait(false); Assert.NotNull(exception); Assert.IsType <ArgumentNullException>(exception); }
public async Task UploadImageUrlAsync_WithImage_AreEqual() { var client = new ImgurClient(ClientId, ClientSecret); var endpoint = new ImageEndpoint(client); var image = await endpoint.UploadImageUrlAsync("http://i.imgur.com/Eg71tvs.gif", null, "url test title!", "url test desc!"); Assert.IsFalse(string.IsNullOrEmpty(image.Id)); Assert.AreEqual("url test title!", image.Title); Assert.AreEqual("url test desc!", image.Description); await GetImageAsync_WithImage_AreEqual(image); await UpdateImageAsync_WithImage_AreEqual(image); await DeleteImageAsync_WithImage_IsTrue(image); }
public async Task uploadURLImage(IOAuth2Token token, string url) { try { var client = new ImgurClient(_clientId, _clientSecret, token); var endpoint = new ImageEndpoint(client); var image = await endpoint.UploadImageUrlAsync(url); Debug.Write("Image uploaded. Image Url: " + image.Link); sendToken(); } catch (ImgurException imgurEx) { Debug.Write("An error occurred uploading an image to Imgur."); Debug.Write(imgurEx.Message); } catch (System.ArgumentNullException e) { Debug.Write("An error occurred uploading an image to Imgur."); Debug.Write(e.Message); } }
public async Task <string> GetReponse(Dictionary <string, object> parameters, string action) { if (_imgurClient == null) { return("Не могу загрузить без активного загрузчика"); } if (!parameters.ContainsKey("url")) { return ("Что-то пошло не так, попытка загрузить не ссылку (UploadPlugin.GetResponse - url is null)"); } if (parameters["url"].ToString().EndsWith(".")) { parameters["url"] += "jpg"; } Console.WriteLine("Запрос загрузки URL: " + parameters["url"]); try { if (!parameters["url"].ToString().EndsWith(".jpg") && !parameters["url"].ToString().EndsWith(".jpeg") && !parameters["url"].ToString().EndsWith(".png") && !parameters["url"].ToString().EndsWith(".gif")) { return("Прости, пока могу загружать только изображения."); } var endpoint = new ImageEndpoint(_imgurClient); var response = await endpoint.UploadImageUrlAsync(parameters["url"].ToString()); return(_doneList[_random.Next(0, _doneList.Count - 1)] + " " + response.Link); } catch (Exception e) { return("Не получилось загрузить изображение, ошибка: " + e.Message); } }
public async Task UploadImageUrlAsync_WithUrlNull_ThrowsArgumentNullException() { var client = new ImgurClient("123", "1234"); var endpoint = new ImageEndpoint(client); await endpoint.UploadImageUrlAsync(null); }