Exemplo n.º 1
0
        /// <summary>
        ///     Updates the account settings for a given user. OAuth authentication required.
        /// </summary>
        /// <param name="bio">The biography of the user, is displayed in the gallery profile page.</param>
        /// <param name="publicImages">Set the users images to private or public by default.</param>
        /// <param name="messagingEnabled">Allows the user to enable / disable private messages.</param>
        /// <param name="albumPrivacy">Sets the default privacy level of albums the users creates.</param>
        /// <param name="acceptedGalleryTerms">The user agreement to the Imgur Gallery terms.</param>
        /// <param name="username">A valid Imgur username (between 4 and 63 alphanumeric characters).</param>
        /// <param name="showMature">Toggle display of mature images in gallery list endpoints.</param>
        /// <param name="newsletterSubscribed">Toggle subscription to email newsletter.</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 Basic <bool> UpdateAccountSettings(
            string bio                = null,
            bool?publicImages         = null,
            bool?messagingEnabled     = null,
            AlbumPrivacy?albumPrivacy = null,
            bool?acceptedGalleryTerms = null,
            string username           = null,
            bool?showMature           = null,
            bool?newsletterSubscribed = null)
        {
            if (ApiClient.OAuth2Token == null)
            {
                throw new ArgumentNullException(nameof(ApiClient.OAuth2Token), OAuth2RequiredExceptionMessage);
            }

            const string url = "account/me/settings";

            using (
                var request = AccountRequestBuilder.UpdateAccountSettingsRequest(url, bio, publicImages, messagingEnabled,
                                                                                 albumPrivacy, acceptedGalleryTerms, username, showMature, newsletterSubscribed))
            {
                var httpResponse = HttpClient.SendAsync(request).Result;
                var jsonString   = httpResponse.Content.ReadAsStringAsync().Result;
                var output       = Newtonsoft.Json.JsonConvert.DeserializeObject <Basic <bool> >(httpResponse.Content.ReadAsStringAsync().Result.ToString());
                return(output);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Updates the account settings for a given user. OAuth authentication required.
        /// </summary>
        /// <param name="bio">The biography of the user, is displayed in the gallery profile page.</param>
        /// <param name="publicImages">Set the users images to private or public by default.</param>
        /// <param name="messagingEnabled">Allows the user to enable / disable private messages.</param>
        /// <param name="albumPrivacy">Sets the default privacy level of albums the users creates.</param>
        /// <param name="acceptedGalleryTerms">The user agreement to the Imgur Gallery terms.</param>
        /// <param name="username">A valid Imgur username (between 4 and 63 alphanumeric characters).</param>
        /// <param name="showMature">Toggle display of mature images in gallery list endpoints.</param>
        /// <param name="newsletterSubscribed">Toggle subscription to email newsletter.</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> UpdateAccountSettingsAsync(
            string bio                = null,
            bool?publicImages         = null,
            bool?messagingEnabled     = null,
            AlbumPrivacy?albumPrivacy = null,
            bool?acceptedGalleryTerms = null,
            string username           = null,
            bool?showMature           = null,
            bool?newsletterSubscribed = null)
        {
            if (ApiClient.OAuth2Token == null)
            {
                throw new ArgumentNullException(nameof(ApiClient.OAuth2Token), OAuth2RequiredExceptionMessage);
            }

            const string url = "account/me/settings";

            using (
                var request = AccountRequestBuilder.UpdateAccountSettingsRequest(url, bio, publicImages, messagingEnabled,
                                                                                 albumPrivacy, acceptedGalleryTerms, username, showMature, newsletterSubscribed))
            {
                var updated = await SendRequestAsync <bool>(request).ConfigureAwait(false);

                return(updated);
            }
        }
Exemplo n.º 3
0
        public static async Task <AccountModel> SignUpAccount(this HttpClient client, long memberId)
        {
            var request  = AccountRequestBuilder.CreateSignUpAccountRequest(memberId);
            var response = await client.PostAsync(TestUrls.Account, JsonContent.Create(request));

            response.EnsureSuccessStatusCode();
            var content = await response.Content.ReadAsStringAsync();

            return(JsonConvert.DeserializeObject <ApiSimpleResponse <AccountModel> >(content).Data);
        }
Exemplo n.º 4
0
        public void CreateRequest_Equal()
        {
            var client         = new ImgurClient("123", "1234");
            var requestBuilder = new AccountRequestBuilder();

            var mockUrl = $"{client.EndpointUrl}account/bob";
            var request = RequestBuilderBase.CreateRequest(HttpMethod.Get, mockUrl);

            Assert.NotNull(request);
            Assert.Equal("https://api.imgur.com/3/account/bob", request.RequestUri.ToString());
            Assert.Equal(HttpMethod.Get, request.Method);
        }
Exemplo n.º 5
0
        public void UpdateAccountSettingsRequest_WithUrlNull_ThrowsArgumentNullException()
        {
            var requestBuilder = new AccountRequestBuilder();

            var exception = Record.Exception(() => AccountRequestBuilder.UpdateAccountSettingsRequest(null));

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

            var argNullException = (ArgumentNullException)exception;

            Assert.Equal(argNullException.ParamName, "url");
        }
Exemplo n.º 6
0
        public void ReportItemRequest_WithUrlNull_ThrowsArgumentNullException()
        {
            var requestBuilder = new AccountRequestBuilder();

            var exception = Record.Exception(() => RequestBuilderBase.ReportItemRequest(null, ReportReason.Abusive));

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

            var argNullException = (ArgumentNullException)exception;

            Assert.Equal(argNullException.ParamName, "url");
        }
Exemplo n.º 7
0
        public void CreateRequest_WithUrlNull_ThrowsArgumentNullException()
        {
            var requestBuilder = new AccountRequestBuilder();

            var exception = Record.Exception(() => RequestBuilderBase.CreateRequest(HttpMethod.Get, null));

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

            var argNullException = (ArgumentNullException)exception;

            Assert.Equal(argNullException.ParamName, "url");
        }
Exemplo n.º 8
0
        public void GivenAccountMapper_WhenMapSignUpAccountRequestToSignUpAccountCommand_ShouldMapSuccessful()
        {
            // assign
            var signUpAccountRequest = AccountRequestBuilder.CreateSignUpAccountRequest(133);

            // act
            var signUpAccountCommand = _mapper.Map <SignUpAccountCommand>(signUpAccountRequest);

            // assert
            signUpAccountRequest.ShouldSatisfyAllConditions(
                () => signUpAccountCommand.ShouldNotBeNull(),
                () => signUpAccountCommand.MemberId.ShouldBe(signUpAccountRequest.MemberId)
                );
        }
Exemplo n.º 9
0
        public void RegisterAction()
        {
            var response = AccountRequestBuilder.Initialize()
                           .AsRegister()
                           .WithUsername(Input.StringValue("Username:"******"Password:"******"Registration failed");
                return;
            }

            Output.Success($"Account created, you can login");
            Input.AwaitAny();
        }
Exemplo n.º 10
0
        public async Task UpdateAccountSettingsRequest_AreEqual()
        {
            var client         = new ImgurClient("123", "1234");
            var requestBuilder = new AccountRequestBuilder();

            var url     = $"{client.EndpointUrl}account/me/settings";
            var request = requestBuilder.UpdateAccountSettingsRequest(
                url, "BioTest", true, true, AlbumPrivacy.Public,
                true, "Bob2", true, true);

            Assert.IsNotNull(request);
            var expected =
                "public_images=true&messaging_enabled=true&album_privacy=public&accepted_gallery_terms=true&show_mature=true&newsletter_subscribed=true&username=Bob2&bio=BioTest";

            Assert.AreEqual(expected, await request.Content.ReadAsStringAsync());
            Assert.AreEqual("https://api.imgur.com/3/account/me/settings", request.RequestUri.ToString());
            Assert.AreEqual(HttpMethod.Post, request.Method);
        }
Exemplo n.º 11
0
        public void LoginAction()
        {
            Session.CurrentUser = AccountRequestBuilder.Initialize()
                                  .AsLogin()
                                  .WithUsername(Input.StringValue("Username:"******"Password:"******"Login failed");
                return;
            }
            Output.Success($"Welcome {Session.CurrentUser.Username}!");
            Input.AwaitAny();

            ConsoleMenu.NavigateTo <PageMainMenu>();
        }
Exemplo n.º 12
0
        public void GivenAccountMapper_WhenMapListAccountRequestToListAccountQuery_ShouldMapSuccessful()
        {
            // assign
            var pagination         = CommonRequestBuilder.CreateApiPaginationRequest(10, 3);
            var listAccountRequest = AccountRequestBuilder.CreateListAccountsRequest("active", "ZIP10000001", pagination);

            // act
            var listAccountQuery = _mapper.Map <ListAccountsQuery>(listAccountRequest);

            // assert
            listAccountQuery.ShouldSatisfyAllConditions(
                () => listAccountQuery.ShouldNotBeNull(),
                () => listAccountQuery.AccountNumber.ShouldBe(listAccountRequest.AccountNumber),
                () => listAccountQuery.AccountStatusId.ToString().ToLower().ShouldBe(listAccountRequest.AccountStatus.ToLower()),
                () => listAccountQuery.Pagination.ShouldNotBeNull(),
                () => listAccountQuery.Pagination.PageSize.ShouldBe(listAccountRequest.Pagination.PageSize),
                () => listAccountQuery.Pagination.PageNumber.ShouldBe(listAccountRequest.Pagination.PageNumber));
        }
Exemplo n.º 13
0
        public void UpdateAccountSettingsRequest_WithUrlNull_ThrowsArgumentNullException()
        {
            var requestBuilder = new AccountRequestBuilder();

            requestBuilder.UpdateAccountSettingsRequest(null);
        }
        public void CreateRequest_WithUrlNull_ThrowsArgumentNullException()
        {
            var requestBuilder = new AccountRequestBuilder();

            requestBuilder.CreateRequest(HttpMethod.Get, null);
        }