Exemple #1
0
        public async Task RestoreAsync(IEnumerable <long> ticketIds)
        {
            if (ticketIds == null)
            {
                throw new ArgumentNullException($"{nameof(ticketIds)} must not be null", nameof(ticketIds));
            }

            var ticketIdList = ticketIds.ToList();

            if (ticketIdList.Count == 0 || ticketIdList.Count > 100)
            {
                throw new ArgumentException($"{nameof(ticketIds)} must have [0..100] elements", nameof(ticketIds));
            }

            var ticketIdsString = ZendeskFormatter.ToCsv(ticketIdList);

            using (_loggerScope(_logger, $"RestoreManyAsync({ticketIdsString})"))
                using (var client = _apiClient.CreateClient(ResourceUri))
                {
                    var response = await client
                                   .PutAsync($"restore_many?ids={ticketIdsString}", new StringContent(string.Empty))
                                   .ConfigureAwait(false);

                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        throw await new ZendeskRequestExceptionBuilder()
                              .WithResponse(response)
                              .WithExpectedHttpStatus(HttpStatusCode.OK)
                              .WithHelpDocsLink("core/tickets#restore-previously-deleted-tickets-in-bulk")
                              .Build();
                    }
                }
        }
Exemple #2
0
        public async Task DeleteAsync(IEnumerable <long> ticketIds)
        {
            if (ticketIds == null)
            {
                throw new ArgumentNullException($"{nameof(ticketIds)} must not be null", nameof(ticketIds));
            }

            var ticketIdList = ticketIds.ToList();

            if (ticketIdList.Count == 0 || ticketIdList.Count > 100)
            {
                throw new ArgumentException($"{nameof(ticketIds)} must have [0..100] elements", nameof(ticketIds));
            }

            var ticketIdsString = ZendeskFormatter.ToCsv(ticketIdList);

            using (_loggerScope(_logger, $"DeleteAsync({ticketIdsString})"))
                using (var client = _apiClient.CreateClient(ResourceUri))
                {
                    var response = await client.DeleteAsync($"destroy_many.json?ids={ticketIdsString}").ConfigureAwait(false);

                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        throw await new ZendeskRequestExceptionBuilder()
                              .WithResponse(response)
                              .WithExpectedHttpStatus(HttpStatusCode.OK)
                              .WithHelpDocsLink("support/tickets#bulk-delete-tickets")
                              .Build();
                    }
                }
        }
Exemple #3
0
        public async Task <JobStatusResponse> PurgeAsync(IEnumerable <long> ticketIds)
        {
            if (ticketIds == null)
            {
                throw new ArgumentNullException($"{nameof(ticketIds)} must not be null", nameof(ticketIds));
            }

            var ticketIdList = ticketIds.ToList();

            if (ticketIdList.Count == 0 || ticketIdList.Count > 100)
            {
                throw new ArgumentException($"{nameof(ticketIds)} must have [0..100] elements", nameof(ticketIds));
            }

            var ticketIdsString = ZendeskFormatter.ToCsv(ticketIdList);

            using (_loggerScope(_logger, $"PurgeAsync({ticketIdsString})"))
                using (var client = _apiClient.CreateClient(ResourceUri))
                {
                    var response = await client.DeleteAsync($"destroy_many?ids={ticketIdsString}").ConfigureAwait(false);

                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        throw await new ZendeskRequestExceptionBuilder()
                              .WithResponse(response)
                              .WithExpectedHttpStatus(HttpStatusCode.OK)
                              .WithHelpDocsLink("core/tickets#delete-multiple-tickets-permanently")
                              .Build();
                    }

                    var result = await response.Content.ReadAsAsync <SingleJobStatusResponse>();

                    return(result.JobStatus);
                }
        }
Exemple #4
0
        protected async Task <HttpResponseMessage> DeleteAsync(
            string resource,
            IReadOnlyList <long> ids,
            string docs,
            string scope = null,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (ids == null)
            {
                throw new ArgumentNullException($"{nameof(ids)} must not be null", nameof(ids));
            }

            if (ids.Count == 0 || ids.Count > 100)
            {
                throw new ArgumentException($"{nameof(ids)} must have [0..100] elements", nameof(ids));
            }

            var idsAsCsv = ZendeskFormatter.ToCsv(ids);

            return(await DeleteAsync(
                       $"{resource}?ids={idsAsCsv}",
                       docs,
                       HttpStatusCode.OK,
                       scope ?? $"DeleteAsync({idsAsCsv})",
                       cancellationToken));
        }
 public async Task <JobStatusResponse> MarkTicketAsSpamAndSuspendRequester(
     long[] ticketIds,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     return(await UpdateAsync <JobStatusResponse, object>(
                $"{ResourceUri}/mark_many_as_spam.json?ids={ZendeskFormatter.ToCsv(ticketIds)}",
                new {},
                "bulk-mark-tickets-as-spam",
                $"MarkTicketAsSpamAndSuspendRequester({ZendeskFormatter.ToCsv(ticketIds)})",
                cancellationToken));
 }
 public async Task <JobStatusResponse> TagListsUpdateAsync(
     long[] ticketIds,
     TicketTagListsUpdateRequest tickets,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     return(await UpdateAsync <JobStatusResponse, TicketRequest <TicketTagListsUpdateRequest> >(
                $"{ResourceUri}/update_many.json?ids={ZendeskFormatter.ToCsv(ticketIds)}",
                new TicketRequest <TicketTagListsUpdateRequest>(tickets),
                "updating-tag-lists",
                cancellationToken : cancellationToken));
 }
 public async Task <IPagination <Organization> > GetAllAsync(
     long[] organizationIds,
     PagerParameters pager = null,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     return(await GetAsync <OrganizationsResponse>(
                $"{ResourceUri}/show_many?ids={ZendeskFormatter.ToCsv(organizationIds)}",
                "show-many-organizations",
                $"GetAllAsync({ZendeskFormatter.ToCsv(organizationIds)})",
                pager,
                cancellationToken : cancellationToken));
 }
        public async Task <IPagination <TicketForm> > GetAllAsync(long[] ticketFormsIds, PagerParameters pager = null)
        {
            using (_loggerScope(_logger, $"GetAllAsync({ZendeskFormatter.ToCsv(ticketFormsIds)})"))
                using (var client = _apiClient.CreateClient(ResourceUri))
                {
                    var response = await client.GetAsync($"show_many?ids={ZendeskFormatter.ToCsv(ticketFormsIds)}", pager).ConfigureAwait(false);

                    response.EnsureSuccessStatusCode();

                    return(await response.Content.ReadAsAsync <TicketFormsResponse>());
                }
        }
Exemple #9
0
 public async Task <UsersListResponse> GetAllByExternalIdsAsync(
     string[] externalIds,
     PagerParameters pager = null,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     return(await GetAsync <UsersListResponse>(
                $"{ResourceUri}/show_many?external_ids={ZendeskFormatter.ToCsv(externalIds)}",
                "show-many-users",
                $"ListByExternalIdsAsync({ZendeskFormatter.ToCsv(externalIds)})",
                pager,
                cancellationToken : cancellationToken));
 }
 public async Task <IPagination <Ticket> > GetAllAsync(
     long[] ticketIds,
     PagerParameters pager = null,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     return(await GetAsync <TicketsListResponse>(
                $"{ResourceUri}/show_many?ids={ZendeskFormatter.ToCsv(ticketIds)}",
                "show-multiple-tickets",
                $"GetAllAsync({ZendeskFormatter.ToCsv(ticketIds)})",
                pager,
                cancellationToken : cancellationToken));
 }
 public async Task <IPagination <JobStatusResponse> > GetAllAsync(
     string[] statusIds,
     PagerParameters pagerParameters     = null,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     return(await GetAsync <JobStatusListResponse>(
                $"{ResourceUri}/show_many?ids={ZendeskFormatter.ToCsv(statusIds)}",
                "show-many-job-statuses",
                $"GetAllAsync({ZendeskFormatter.ToCsv(statusIds)})",
                pagerParameters,
                cancellationToken : cancellationToken));
 }
Exemple #12
0
        public async Task <JobStatusResponse> MarkTicketAsSpamAndSuspendRequester(long[] ticketIds)
        {
            using (_loggerScope(_logger, $"MarkTicketAsSpamAndSuspendRequester({ZendeskFormatter.ToCsv(ticketIds)})"))
                using (var client = _apiClient.CreateClient(ResourceUri))
                {
                    var response = await client.PutAsJsonAsync($"mark_many_as_spam?ids={ZendeskFormatter.ToCsv(ticketIds)}", "{ }").ConfigureAwait(false);

                    response.EnsureSuccessStatusCode();

                    return(await response.Content.ReadAsAsync <JobStatusResponse>());
                }
        }
        public void ToCsv_Called_ReturnsNumericItemsAsZendeskCompliantCsv()
        {
            // Given
            var list = new List <long> {
                1, 22, 333
            };

            // When
            var result = ZendeskFormatter.ToCsv(list);

            // Then
            Assert.Equal(result, "1,22,333");
        }
Exemple #14
0
        public void ToCsv_Called_ReturnsItemsTrimmed()
        {
            // Given
            var list = new List <string> {
                "                  a", "bb               ", "c cc "
            };

            // When
            var result = ZendeskFormatter.ToCsv(list);

            // Then
            Assert.That(result, Is.EqualTo("a,bb,c cc"));
        }
        public void ToCsv_Called_ReturnsItemsAsZendeskCompliantCsv()
        {
            // Given
            var list = new List <string> {
                "a", "bb", "ccc"
            };

            // When
            var result = ZendeskFormatter.ToCsv(list);

            // Then
            Assert.Equal(result, "a,bb,ccc");
        }
        public async Task <IPagination <TicketForm> > GetAllAsync(
            long[] ticketFormsIds,
            PagerParameters pager = null,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            var ids = ZendeskFormatter.ToCsv(ticketFormsIds);

            return(await GetAsync <TicketFormsResponse>(
                       $"{ResourceUri}/show_many?ids={ids}",
                       "show-many-ticket-forms",
                       $"GetAllAsync({ids})",
                       pager,
                       cancellationToken : cancellationToken));
        }
Exemple #17
0
        public async Task <UsersListResponse> ListByExternalIdsAsync(string[] externalIds, PagerParameters pager = null)
        {
            using (_loggerScope(_logger, $"ListByExternalIdsAsync({ZendeskFormatter.ToCsv(externalIds)})"))
                using (var client = _apiClient.CreateClient(ResourceUri))
                {
                    var response = await client.GetAsync($"show_many?external_ids={ZendeskFormatter.ToCsv(externalIds)}", pager).ConfigureAwait(false);

                    if (!response.IsSuccessStatusCode)
                    {
                        throw await new ZendeskRequestExceptionBuilder()
                              .WithResponse(response)
                              .WithHelpDocsLink("core/users#show-many-users")
                              .Build();
                    }

                    return(await response.Content.ReadAsAsync <UsersListResponse>());
                }
        }
Exemple #18
0
        public async Task <IPagination <JobStatusResponse> > GetAsync(string[] statusIds, PagerParameters pagerParameters = null)
        {
            using (_loggerScope(_logger, $"GetAsync({ZendeskFormatter.ToCsv(statusIds)})"))
                using (var client = _apiClient.CreateClient(ResourceUri))
                {
                    var response = await client.GetAsync($"show_many?ids={ZendeskFormatter.ToCsv(statusIds)}", pagerParameters)
                                   .ConfigureAwait(false);

                    if (!response.IsSuccessStatusCode)
                    {
                        throw await new ZendeskRequestExceptionBuilder()
                              .WithResponse(response)
                              .WithHelpDocsLink("support/job_statuses#show-many-job-statuses")
                              .Build();
                    }

                    return(await response.Content.ReadAsAsync <JobStatusListResponse>());
                }
        }
Exemple #19
0
        protected TResponse GetAll <TResponse>(IEnumerable <long> ids) where TResponse : IListResponse <T>
        {
            var requestUri = Client.BuildUri(string.Format("{0}/{1}", ResourceUri, ShowMany), string.Format("ids={0}", ZendeskFormatter.ToCsv(ids)));

            return(Client.Get <TResponse>(requestUri));
        }
        protected async Task <TResponse> GetAllAsync <TResponse>(IEnumerable <long> ids) where TResponse : IListResponse <T>
        {
            var requestUri = Client.BuildUri($"{ResourceUri}/{ShowMany}", $"ids={ZendeskFormatter.ToCsv(ids)}");

            return(await Client.GetAsync <TResponse>(requestUri).ConfigureAwait(false));
        }
Exemple #21
0
            protected TResponse GetAll <TResponse>(string url, IEnumerable <long> ids) where TResponse : IListResponse <T>
            {
                var requestUri = Client.BuildUri(url, $"ids={ZendeskFormatter.ToCsv(ids)}");

                return(Client.Get <TResponse>(requestUri, resource: ResourceName));
            }
        protected TResponse GetAll <TResponse>(IEnumerable <long> ids) where TResponse : IListResponse <T>
        {
            var requestUri = Client.BuildUri($"{ResourceUri}/{ShowMany}", $"ids={ZendeskFormatter.ToCsv(ids)}");

            return(Client.Get <TResponse>(requestUri));
        }
Exemple #23
0
            protected async Task <TResponse> GetAllAsync <TResponse>(string url, IEnumerable <long> ids) where TResponse : IListResponse <T>
            {
                var requestUri = Client.BuildUri(url, $"ids={ZendeskFormatter.ToCsv(ids)}");

                return(await Client.GetAsync <TResponse>(requestUri, resource : ResourceName).ConfigureAwait(false));
            }