Example #1
0
        public async Task UploadImageBinaryRequest_AreEqual()
        {
            var client         = new ImgurClient("123", "1234");
            var requestBuilder = new ImageRequestBuilder();
            var url            = $"{client.EndpointUrl}image";

            var image   = File.ReadAllBytes("banana.gif");
            var request = requestBuilder.UploadImageBinaryRequest(url, image, "TheAlbum", "TheTitle",
                                                                  "TheDescription");

            Assert.IsNotNull(request);
            Assert.AreEqual("https://api.imgur.com/3/image", request.RequestUri.ToString());
            Assert.AreEqual(HttpMethod.Post, request.Method);

            var content      = (MultipartFormDataContent)request.Content;
            var imageContent =
                (ByteArrayContent)content.FirstOrDefault(x => x.Headers.ContentDisposition.Name == "image");
            var album       = (StringContent)content.FirstOrDefault(x => x.Headers.ContentDisposition.Name == "album");
            var type        = (StringContent)content.FirstOrDefault(x => x.Headers.ContentDisposition.Name == "type");
            var title       = (StringContent)content.FirstOrDefault(x => x.Headers.ContentDisposition.Name == "title");
            var description =
                (StringContent)content.FirstOrDefault(x => x.Headers.ContentDisposition.Name == "description");

            Assert.IsNotNull(imageContent);
            Assert.IsNotNull(type);
            Assert.IsNotNull(album);
            Assert.IsNotNull(title);
            Assert.IsNotNull(description);

            Assert.AreEqual(image.Length, imageContent.Headers.ContentLength);
            Assert.AreEqual("file", await type.ReadAsStringAsync());
            Assert.AreEqual("TheAlbum", await album.ReadAsStringAsync());
            Assert.AreEqual("TheTitle", await title.ReadAsStringAsync());
            Assert.AreEqual("TheDescription", await description.ReadAsStringAsync());
        }
Example #2
0
        private async Task <IImage> UploadVideoInternalAsync(Stream image,
                                                             string album                        = null,
                                                             string name                         = null,
                                                             string title                        = null,
                                                             string description                  = null,
                                                             IProgress <int> progress            = null,
                                                             int?bufferSize                      = 4096,
                                                             CancellationToken cancellationToken = default)
        {
            const string url = "upload";

            using (var request = ImageRequestBuilder.UploadVideoStreamRequest(url,
                                                                              image,
                                                                              album,
                                                                              name,
                                                                              title,
                                                                              description,
                                                                              progress,
                                                                              bufferSize))
            {
                var response = await SendRequestAsync <Image>(request,
                                                              cancellationToken).ConfigureAwait(false);

                return(response);
            }
        }
 public void TestIsDiskCacheDisabledIfRequested7()
 {
     ImageRequestBuilder builder =
         ImageRequestBuilder.NewBuilderWithSource(new Uri("data:image/png;base64"));
     builder.DisableDiskCache();
     Assert.IsFalse(builder.IsDiskCacheEnabled);
 }
Example #4
0
        public void TestDownloadHandler()
        {
            _imageRequest = ImageRequestBuilder
                            .NewBuilderWithSource(IMAGE_URL)
                            .SetProgressiveRenderingEnabled(true)
                            .Build();

            _producerContext = new SettableProducerContext(
                _imageRequest,
                $"{ _imageRequest.SourceUri.ToString() }2",
                _producerListener,
                new object(),
                RequestLevel.FULL_FETCH,
                false,
                true,
                Priority.MEDIUM);

            _networkFetchProducer.ProduceResults(_consumer, _producerContext);

            // Wait for callback
            _completion.WaitOne();

            Assert.IsTrue(_onNewResultImplCalls > 1);
            Assert.IsTrue(_intermediateResultProducerEventCalls > 1);
        }
        private async void FetchDecodedImage()
        {
            try
            {
                Uri uri = MainPage.GenerateImageUri();
                ImageRequestBuilder builder = ImageRequestBuilder.NewBuilderWithSource(uri);
                if (GrayscaleRadioButton.IsChecked.Value)
                {
                    builder.SetPostprocessor(GrayscalePostprocessor);
                }
                else if (InvertRadioButton.IsChecked.Value)
                {
                    builder.SetPostprocessor(InvertPostprocessor);
                }

                ImageRequest    request = builder.Build();
                WriteableBitmap bitmap  = await _imagePipeline.FetchDecodedBitmapImageAsync(request);

                var image = new Image();
                image.Width  = image.Height = MainPage.VIEW_DIMENSION;
                image.Source = bitmap;
                ImageGrid.Items.Add(image);
            }
            catch (Exception)
            {
                // Invalid uri, try again
                FetchDecodedImage();
            }
        }
Example #6
0
        public void TestExceptionInFetchImage()
        {
            _imageRequest = ImageRequestBuilder
                            .NewBuilderWithSource(FAILURE_URL)
                            .SetProgressiveRenderingEnabled(true)
                            .Build();

            _producerContext = new SettableProducerContext(
                _imageRequest,
                _imageRequest.SourceUri.ToString(),
                _producerListener,
                new object(),
                RequestLevel.FULL_FETCH,
                false,
                true,
                Priority.MEDIUM);

            _networkFetchProducer.ProduceResults(_consumer, _producerContext);

            // Wait for callback
            _completion.WaitOne();

            Assert.IsTrue(_onProducerFinishWithFailureFuncCalls == 1);
            Assert.AreEqual(_internalRequestId, _imageRequest.SourceUri.ToString());
            Assert.AreEqual(_internalProducerName, NetworkFetchProducer.PRODUCER_NAME);
            Assert.IsNotNull(_internalError);
            Assert.IsNull(_internalExtraMap);
        }
 public void TestIsDiskCacheDisabledIfRequested4()
 {
     ImageRequestBuilder builder =
         ImageRequestBuilder.NewBuilderWithSource(new Uri("ms-appx-web:///request"));
     builder.DisableDiskCache();
     Assert.IsFalse(builder.IsDiskCacheEnabled);
 }
Example #8
0
        /// <summary>
        ///     Return the images the user has favorited in the gallery.
        /// </summary>
        /// <param name="username">The user account. Default: me</param>
        /// <param name="page">Set the page number so you don't have to retrieve all the data at once. Default: null.</param>
        /// <param name="sort">Indicates the order that a list of items are sorted. Default: Newest.</param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ImgurException"></exception>
        /// <exception cref="MashapeException"></exception>
        /// <exception cref="OverflowException"></exception>
        /// <returns></returns>
        public async Task <ICollection <IGalleryAlbumImageBase> > GetAccountGalleryFavoritesAsync(string username       = "******",
                                                                                                  int?page              = null,
                                                                                                  GallerySortOrder?sort = GallerySortOrder.Newest)
        {
            if (string.IsNullOrEmpty(username))
            {
                throw new ArgumentNullException(nameof(username));
            }

            if (username.Equals("me", StringComparison.OrdinalIgnoreCase) &&
                ApiClient.OAuth2Token == null)
            {
                throw new ArgumentNullException(nameof(ApiClient.OAuth2Token), OAuth2RequiredExceptionMessage);
            }

            var sortValue = $"{sort ?? GallerySortOrder.Newest}".ToLower();
            var url       = $"account/{username}/gallery_favorites/{page}/{sortValue}";

            using (var request = ImageRequestBuilder.CreateRequest(HttpMethod.Get, url))
            {
                var favorites = await SendRequestAsync <IGalleryAlbumImageBase[]>(request);

                return(favorites);
            }
        }
Example #9
0
        public void UploadImageBinaryRequest_WithUrlNull_ThrowsArgumentNullException()
        {
            var requestBuilder = new ImageRequestBuilder();
            var image          = File.ReadAllBytes("banana.gif");

            requestBuilder.UploadImageBinaryRequest(null, image);
        }
Example #10
0
        public void Initialize()
        {
            _request       = ImageRequestBuilder.NewBuilderWithSource(new Uri("http://request")).Build();
            _callerContext = new object();
            _error         = new Exception();
            _immutableMap  = new Dictionary <string, string>();

            ProducerListenerImpl producerListener1 = new ProducerListenerImpl(
                (_, __) => { ++_onProducerStartFuncCalls1; },
                (_, __, ___) => { ++_onProducerEventFuncCalls1; },
                (_, __, ___) => { ++_onProducerFinishWithSuccessFuncCalls1; },
                (_, __, ___, ____) => { ++_onProducerFinishWithFailureFuncCalls1; },
                (_, __, ___) => { ++_onProducerFinishWithCancellationFuncCalls1; },
                (_) => { ++_requiresExtraMapFuncCalls1; return(false); });

            ProducerListenerImpl producerListener2 = new ProducerListenerImpl(
                (_, __) => { ++_onProducerStartFuncCalls2; },
                (_, __, ___) => { ++_onProducerEventFuncCalls2; },
                (_, __, ___) => { ++_onProducerFinishWithSuccessFuncCalls2; },
                (_, __, ___, ____) => { ++_onProducerFinishWithFailureFuncCalls2; },
                (_, __, ___) => { ++_onProducerFinishWithCancellationFuncCalls2; },
                (_) => { ++_requiresExtraMapFuncCalls2; return(false); });

            ProducerListenerImpl producerListener3 = new ProducerListenerImpl(
                (_, __) => { ++_onProducerStartFuncCalls3; },
                (_, __, ___) => { ++_onProducerEventFuncCalls3; },
                (_, __, ___) => { ++_onProducerFinishWithSuccessFuncCalls3; },
                (_, __, ___, ____) => { ++_onProducerFinishWithFailureFuncCalls3; },
                (_, __, ___) => { ++_onProducerFinishWithCancellationFuncCalls3; },
                (_) => { ++_requiresExtraMapFuncCalls3; return(false); });

            _requestListener1 = new RequestListenerImpl(
                producerListener1,
                (_, __, ___, ____) => { ++_onRequestStartFuncCalls1; },
                (_, __, ___) => { ++_onRequestSuccessFuncCall1; },
                (_, __, ___, ____) => { ++_onRequestFailureFuncCalls1; },
                (_) => { ++_onRequestCancellationFuncCalls1; });

            _requestListener2 = new RequestListenerImpl(
                producerListener2,
                (_, __, ___, ____) => { ++_onRequestStartFuncCalls2; },
                (_, __, ___) => { ++_onRequestSuccessFuncCall2; },
                (_, __, ___, ____) => { ++_onRequestFailureFuncCalls2; },
                (_) => { ++_onRequestCancellationFuncCalls2; });

            _requestListener3 = new RequestListenerImpl(
                producerListener3,
                (_, __, ___, ____) => { ++_onRequestStartFuncCalls3; },
                (_, __, ___) => { ++_onRequestSuccessFuncCall3; },
                (_, __, ___, ____) => { ++_onRequestFailureFuncCalls3; },
                (_) => { ++_onRequestCancellationFuncCalls3; });

            _listenerManager = new ForwardingRequestListener(new HashSet <IRequestListener>
            {
                _requestListener1,
                _requestListener2,
                _requestListener3
            });
        }
Example #11
0
        public void UploadImageBinaryRequest_WithImageNull_ThrowsArgumentNullException()
        {
            var client         = new ImgurClient("123", "1234");
            var requestBuilder = new ImageRequestBuilder();
            var url            = $"{client.EndpointUrl}image";

            requestBuilder.UploadImageBinaryRequest(url, null);
        }
Example #12
0
        public void UploadStreamBinaryRequest_WithUrlNull_ThrowsArgumentNullException()
        {
            var requestBuilder = new ImageRequestBuilder();

            using (var fs = new FileStream("banana.gif", FileMode.Open))
            {
                requestBuilder.UploadImageStreamRequest(null, fs);
            }
        }
        /// <summary>
        /// Returns whether the image is stored in the disk cache.
        /// Performs disk cache check synchronously. It is not
        /// recommended to use this unless you know what exactly
        /// you are doing. Disk cache check is a costly operation,
        /// the call will block the caller thread until the cache
        /// check is completed.
        /// </summary>
        /// <param name="uri">
        /// The uri for the image to be looked up.
        /// </param>
        /// <param name="cacheChoice">
        /// The cacheChoice for the cache to be looked up.
        /// </param>
        /// <returns>
        /// true if the image was found in the disk cache,
        /// false otherwise.
        /// </returns>
        public bool IsInDiskCacheSync(Uri uri, CacheChoice cacheChoice)
        {
            ImageRequest imageRequest = ImageRequestBuilder
                                        .NewBuilderWithSource(uri)
                                        .SetCacheChoice(cacheChoice)
                                        .Build();

            return(IsInDiskCacheSync(imageRequest));
        }
        public void getSize(string uriString, IPromise promise)
        {
            if (string.IsNullOrEmpty(uriString))
            {
                promise.Reject(ErrorInvalidUri, "Cannot get the size of an image for an empty URI.");
                return;
            }

            var uri            = new Uri(uriString);
            var imagePipeline  = ImagePipelineFactory.Instance.GetImagePipeline();
            var request        = ImageRequestBuilder.NewBuilderWithSource(uri).Build();
            var dataSource     = imagePipeline.FetchDecodedImage(request, null);
            var dataSubscriber = new BaseDataSubscriberImpl <CloseableReference <CloseableImage> >(
                response =>
            {
                if (!response.IsFinished())
                {
                    return(Task.CompletedTask);
                }

                CloseableReference <CloseableImage> reference = response.GetResult();
                if (reference != null)
                {
                    try
                    {
                        CloseableImage image = reference.Get();
                        promise.Resolve(new JObject
                        {
                            { "width", image.Width },
                            { "height", image.Height },
                        });
                    }
                    catch (Exception ex)
                    {
                        promise.Reject(ErrorGetSizeFailure, ex.Message);
                    }
                    finally
                    {
                        CloseableReference <CloseableImage> .CloseSafely(reference);
                    }
                }
                else
                {
                    promise.Reject(ErrorGetSizeFailure, Invariant($"Invalid URI '{uri}' provided."));
                }

                return(Task.CompletedTask);
            },
                response =>
            {
                promise.Reject(ErrorGetSizeFailure, response.GetFailureCause());
            });

            dataSource.Subscribe(dataSubscriber, FBCore.Concurrency.CallerThreadExecutor.Instance);
        }
Example #15
0
        /// <summary>
        ///     Updates the title or description of an image.
        ///     You can only update an image you own and is associated with your account.
        ///     For an anonymous image, {id} must be the image's deletehash.
        /// </summary>
        /// <param name="imageId">The image id.</param>
        /// <param name="title">The title of the image.</param>
        /// <param name="description">The description of the image.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when a null reference is passed to a method that does not accept it as a
        ///     valid argument.
        /// </exception>
        /// <exception cref="ImgurException">Thrown when an error is found in a response from an Imgur endpoint.</exception>
        /// <exception cref="MashapeException">Thrown when an error is found in a response from a Mashape endpoint.</exception>
        /// <returns></returns>
        private async Task <bool> UpdateImageInternalAsync(string imageId, string title = null, string description = null)
        {
            var url = $"image/{imageId}";

            using (var request = ImageRequestBuilder.UpdateImageRequest(url, title, description))
            {
                var updated = await SendRequestAsync <bool>(request).ConfigureAwait(false);

                return(updated);
            }
        }
Example #16
0
        public void UploadStreamBinaryRequest_WithImageNull_ThrowsArgumentNullException()
        {
            var client         = new ImgurClient("123", "1234");
            var requestBuilder = new ImageRequestBuilder();
            var url            = $"{client.EndpointUrl}image";

            using (var fs = new FileStream("banana.gif", FileMode.Open))
            {
                requestBuilder.UploadImageStreamRequest(url, null);
            }
        }
Example #17
0
        /// <summary>
        ///     Upload a new image using a URL.
        /// </summary>
        /// <param name="upload">The Stream file of the image/video.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="fileType">The Filetype (image/video).</param>
        /// <param name="albumId">
        ///     The id of the album you want to add the image to. For anonymous albums, {albumId} should be the
        ///     deletehash that is returned at creation.
        /// </param>
        /// <param name="name">The name of the file.</param>
        /// <param name="title">The title of the image.</param>
        /// <param name="description">The description of the image.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when a null reference is passed to a method that does not accept it as a
        ///     valid argument.
        /// </exception>
        /// <exception cref="ImgurException">Thrown when an error is found in a response from an Imgur endpoint.</exception>
        /// <exception cref="MashapeException">Thrown when an error is found in a response from a Mashape endpoint.</exception>
        /// <returns></returns>
        private async ValueTask <IImage> UploadFileInternalAsync(Stream upload, string fileName, FileType fileType = FileType.Image, string albumId = null, string name = null, string title = null, string description = null)
        {
            const string url = nameof(upload);

            using (var request = ImageRequestBuilder.UploadFileRequest(url, upload, fileName, fileType, albumId, name, title, description))
            {
                var returnImage = await SendRequestAsync <Image>(request).ConfigureAwait(false);

                return(returnImage);
            }
        }
        public void UploadImageUrlRequest_WithUrlNull_ThrowsArgumentNullException()
        {
            var exception = Record.Exception(() => ImageRequestBuilder.UploadImageUrlRequest(null, null));

            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);

            var argNullException = (ArgumentNullException)exception;

            Assert.Equal("url", argNullException.ParamName);
        }
Example #19
0
        /// <summary>
        ///     Upload a new image using a stream.
        /// </summary>
        /// <param name="image">A stream.</param>
        /// <param name="albumId">
        ///     The id of the album you want to add the image to. For anonymous albums, {albumId} should be the
        ///     deletehash that is returned at creation.
        /// </param>
        /// <param name="name">The name of the file.</param>
        /// <param name="title">The title of the image.</param>
        /// <param name="description">The description of the image.</param>
        /// <param name="progressBytes">A provider for progress updates.</param>
        /// <param name="progressBufferSize">The amount of bytes that should be uploaded while performing a progress upload.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when a null reference is passed to a method that does not accept it as a
        ///     valid argument.
        /// </exception>
        /// <exception cref="ImgurException">Thrown when an error is found in a response from an Imgur endpoint.</exception>
        /// <exception cref="MashapeException">Thrown when an error is found in a response from a Mashape endpoint.</exception>
        /// <returns></returns>
        private async Task <IImage> UploadImageStreamInternalAsync(Stream image, string albumId = null, string name                   = null, string title = null,
                                                                   string description           = null, IProgress <int> progressBytes = null, int progressBufferSize = 4096)
        {
            const string url = nameof(image);

            using (var request = ImageRequestBuilder.UploadImageStreamRequest(url, image, albumId, name, title, description, progressBytes, progressBufferSize))
            {
                var returnImage = await SendRequestAsync <Image>(request).ConfigureAwait(false);

                return(returnImage);
            }
        }
Example #20
0
        /// <summary>
        ///     Upload a new image using a URL.
        /// </summary>
        /// <param name="image">The URL for the image.</param>
        /// <param name="albumId">
        ///     The id of the album you want to add the image to. For anonymous albums, {albumId} should be the
        ///     deletehash that is returned at creation.
        /// </param>
        /// <param name="name">The name of the file.</param>
        /// <param name="title">The title of the image.</param>
        /// <param name="description">The description of the image.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when a null reference is passed to a method that does not accept it as a
        ///     valid argument.
        /// </exception>
        /// <exception cref="ImgurException">Thrown when an error is found in a response from an Imgur endpoint.</exception>
        /// <exception cref="MashapeException">Thrown when an error is found in a response from a Mashape endpoint.</exception>
        /// <returns></returns>
        private async Task <IImage> UploadImageUrlInternalAsync(string image, string albumId = null, string name = null, string title = null,
                                                                string description           = null)
        {
            const string url = nameof(image);

            using (var request = ImageRequestBuilder.UploadImageUrlRequest(url, image, albumId, name, title, description))
            {
                var returnImage = await SendRequestAsync <Image>(request).ConfigureAwait(false);

                return(returnImage);
            }
        }
        public void UploadVideoStreamRequest_WithUrlNull_ThrowsArgumentNullException()
        {
            using var ms = new MemoryStream(new byte[9]);
            var exception = Record.Exception(() => ImageRequestBuilder.UploadVideoStreamRequest(null, ms));

            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);

            var argNullException = (ArgumentNullException)exception;

            Assert.Equal("url", argNullException.ParamName);
        }
Example #22
0
        public void UpdateImageRequest_WithUrlNull_ThrowsArgumentNullException()
        {
            var requestBuilder = new ImageRequestBuilder();

            var exception = Record.Exception(() => ImageRequestBuilder.UpdateImageRequest(null, "1234Xyz9"));

            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);

            var argNullException = (ArgumentNullException)exception;

            Assert.Equal(argNullException.ParamName, "url");
        }
Example #23
0
        public void UploadImageUrlRequest_WithUrlNull_ThrowsArgumentNullException()
        {
            var requestBuilder = new ImageRequestBuilder();

            var exception = Record.Exception(() => ImageRequestBuilder.UploadImageBinaryRequest(null, new byte[9]));

            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);

            var argNullException = (ArgumentNullException)exception;

            Assert.Equal(argNullException.ParamName, "url");
        }
        public void UploadImageUrlRequest_WithImageNull_ThrowsArgumentNullException()
        {
            var apiClient = new ApiClient("123");
            var mockUrl   = $"{apiClient.BaseAddress}image";

            var exception = Record.Exception(() => ImageRequestBuilder.UploadImageUrlRequest(mockUrl, null));

            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);

            var argNullException = (ArgumentNullException)exception;

            Assert.Equal("imageUrl", argNullException.ParamName);
        }
        public async Task UpdateImageRequest_Equal()
        {
            var apiClient = new ApiClient("123");

            var mockUrl = $"{apiClient.BaseAddress}image/1234Xyz9";
            var request = ImageRequestBuilder.UpdateImageRequest(mockUrl, "TheTitle", "TheDescription");

            Assert.NotNull(request);
            Assert.Equal("https://api.imgur.com/3/image/1234Xyz9", request.RequestUri.ToString());
            Assert.Equal(HttpMethod.Post, request.Method);

            var expected = await request.Content.ReadAsStringAsync();

            Assert.Equal("title=TheTitle&description=TheDescription", expected);
        }
Example #26
0
        public void UploadImageBinaryRequest_WithImageNull_ThrowsArgumentNullException()
        {
            var client         = new ImgurClient("123", "1234");
            var requestBuilder = new ImageRequestBuilder();
            var mockUrl        = $"{client.EndpointUrl}image";

            var exception = Record.Exception(() => ImageRequestBuilder.UploadImageBinaryRequest(mockUrl, null));

            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);

            var argNullException = (ArgumentNullException)exception;

            Assert.Equal(argNullException.ParamName, "image");
        }
Example #27
0
        public async Task TestFetchLocalJpegExif()
        {
            var imageRequest = ImageRequestBuilder
                               .NewBuilderWithSource(LOCAL_JPEG_EXIF_URL)
                               .SetAutoRotateEnabled(true)
                               .Build();

            var bitmap = await _imagePipeline.FetchDecodedBitmapImageAsync(imageRequest)
                         .ConfigureAwait(false);

            await DispatcherHelpers.RunOnDispatcherAsync(() =>
            {
                Assert.IsTrue(bitmap.PixelWidth != 0);
                Assert.IsTrue(bitmap.PixelHeight != 0);
            });
        }
Example #28
0
        /// <summary>
        ///     Returns the users favorited images. OAuth authentication required.
        /// </summary>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ImgurException"></exception>
        /// <exception cref="MashapeException"></exception>
        /// <exception cref="OverflowException"></exception>
        /// <returns></returns>
        public async Task <ICollection <IGalleryAlbumImageBase> > GetAccountFavoritesAsync()
        {
            if (ApiClient.OAuth2Token == null)
            {
                throw new ArgumentNullException(nameof(ApiClient.OAuth2Token), OAuth2RequiredExceptionMessage);
            }

            var url = "account/me/favorites";

            using (var request = ImageRequestBuilder.CreateRequest(HttpMethod.Get, url))
            {
                var favorites = await SendRequestAsync <IGalleryAlbumImageBase[]>(request);

                return(favorites);
            }
        }
Example #29
0
        /// <summary>
        ///     Updates the title or description of an image.
        ///     You can only update an image you own and is associated with your account.
        ///     For an anonymous image, {id} must be the image's deletehash.
        /// </summary>
        /// <param name="imageId">The image id.</param>
        /// <param name="title">The title of the image.</param>
        /// <param name="description">The description of the image.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when a null reference is passed to a method that does not accept it as a
        ///     valid argument.
        /// </exception>
        /// <exception cref="ImgurException">Thrown when an error is found in a response from an Imgur endpoint.</exception>
        /// <exception cref="MashapeException">Thrown when an error is found in a response from a Mashape endpoint.</exception>
        /// <returns></returns>
        public async Task <bool> UpdateImageAsync(string imageId, string title = null, string description = null)
        {
            if (string.IsNullOrWhiteSpace(imageId))
            {
                throw new ArgumentNullException(nameof(imageId));
            }

            var url = $"image/{imageId}";

            using (var request = ImageRequestBuilder.UpdateImageRequest(url, title, description))
            {
                var updated = await SendRequestAsync <bool>(request).ConfigureAwait(false);

                return(updated);
            }
        }
Example #30
0
        public async Task UpdateImageRequest_Equal()
        {
            var client         = new ImgurClient("123", "1234");
            var requestBuilder = new ImageRequestBuilder();

            var mockUrl = $"{client.EndpointUrl}image/1234Xyz9";
            var request = ImageRequestBuilder.UpdateImageRequest(mockUrl, "TheTitle", "TheDescription");

            Assert.NotNull(request);
            Assert.Equal("https://api.imgur.com/3/image/1234Xyz9", request.RequestUri.ToString());
            Assert.Equal(HttpMethod.Post, request.Method);

            var expected = await request.Content.ReadAsStringAsync().ConfigureAwait(false);

            Assert.Equal("title=TheTitle&description=TheDescription", expected);
        }