Beispiel #1
0
        public async Task <IPagination <SatisfactionRating> > GetAllAsync(PagerParameters pager = null)
        {
            using (_loggerScope(_logger, "GetAllAsync"))
                using (var client = _apiClient.CreateClient())
                {
                    var response = await client.GetAsync(ResourceUri, pager).ConfigureAwait(false);

                    response.EnsureSuccessStatusCode();

                    return(await response.Content.ReadAsAsync <SatisfactionRatingsResponse>());
                }
        }
Beispiel #2
0
        public async Task <SearchResponse <ISearchResult> > SearchAsync(Action <IZendeskQuery> builder, PagerParameters pager = null)
        {
            var query = new ZendeskQuery();

            builder(query);

            using (_loggerScope(_logger, "SearchAsync"))
                using (var client = _apiClient.CreateClient())
                {
                    var response = await client.GetAsync($"{SearchUri}?{query.BuildQuery()}", pager).ConfigureAwait(false);

                    return(await response.Content.ReadAsAsync <SearchResponse <ISearchResult> >(new SearchJsonConverter()));
                }
        }
Beispiel #3
0
        public async Task <UsersListResponse> ListAsync(PagerParameters pager = null)
        {
            using (_loggerScope(_logger, "ListAsync"))
                using (var client = _apiClient.CreateClient())
                {
                    var response = await client.GetAsync(ResourceUri, pager).ConfigureAwait(false);

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

                    return(await response.Content.ReadAsAsync <UsersListResponse>());
                }
        }
        public async Task <Attachment> GetAsync(long attachmentId)
        {
            using (_loggerScope(_logger, $"GetAsync({attachmentId})"))
                using (var client = _apiClient.CreateClient(AttachmentsResourceUri))
                {
                    var response = await client.GetAsync(attachmentId.ToString()).ConfigureAwait(false);

                    if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
                    {
                        _logger.LogInformation("Attachment {0} not found", attachmentId);
                        return(null);
                    }

                    response.EnsureSuccessStatusCode();

                    return(await response.Content.ReadAsAsync <Attachment>());
                }
        }
Beispiel #5
0
 protected async Task <HttpResponseMessage> ExecuteRequest(
     Func <HttpClient, CancellationToken, Task <HttpResponseMessage> > requestBodyAccessor,
     string scope,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     using (LoggerScope(Logger, scope))
         using (var client = ApiClient.CreateClient())
         {
             return(await requestBodyAccessor(client, cancellationToken));
         }
 }
        public async Task <TicketCommentsListResponse> ListAsync(long ticketId, PagerParameters pager = null)
        {
            using (_loggerScope(_logger, $"ListAsync({ticketId})"))
                using (var client = _apiClient.CreateClient())
                {
                    var response = await client.GetAsync(string.Format(ResourceUri, ticketId), pager).ConfigureAwait(false);

                    response.EnsureSuccessStatusCode();

                    return(await response.Content.ReadAsAsync <TicketCommentsListResponse>());
                }
        }
Beispiel #7
0
        public async Task <GroupListResponse> ListAsync(PagerParameters pager = null)
        {
            using (_loggerScope(_logger, "ListAsync"))
                using (var client = _apiClient.CreateClient())
                {
                    var response = await client.GetAsync(GroupsResourceUri, pager).ConfigureAwait(false);

                    response.EnsureSuccessStatusCode();

                    return(await response.Content.ReadAsAsync <GroupListResponse>());
                }
        }
Beispiel #8
0
        public async Task <IPagination <UserIdentity> > GetAllForUserAsync(long userId, PagerParameters pager = null)
        {
            using (_loggerScope(_logger, $"GetAllForUserAsync({userId})"))
                using (var client = _apiClient.CreateClient())
                {
                    var response = await client.GetAsync(string.Format(ResourceUriFormat, userId), pager).ConfigureAwait(false);

                    response.EnsureSuccessStatusCode();

                    return(await response.Content.ReadAsAsync <UserIdentitiesResponse>());
                }
        }
Beispiel #9
0
        public async System.Threading.Tasks.Task <Responses.IPagination <Article> > ListAsync(string query, PagerParameters pager = null)
        {
            using (_loggerScope(_logger, "ListAsync"))
                using (var client = _apiClient.CreateClient())
                {
                    var response = await client.GetAsync(ResourceUri + "search.json?query=" + query, pager).ConfigureAwait(false);

                    if (!response.IsSuccessStatusCode)
                    {
                        throw await new ZendeskRequestExceptionBuilder()
                              .WithResponse(response)
                              .WithHelpDocsLink("support/articles#list-articles")
                              .Build();
                    }

                    var data = await response.Content.ReadAsAsync <SearchResponse <Article> >();

                    return(data);
                }
        }
Beispiel #10
0
        public async Task <DeletedTicketsListResponse> GetAllAsync(PagerParameters pager = null)
        {
            using (_loggerScope(_logger, nameof(GetAllAsync)))
                using (var client = _apiClient.CreateClient(ResourceUri))
                {
                    var response = await client.GetAsync($"/{ResourceUri}.json", pager).ConfigureAwait(false);

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

                    return(await response.Content.ReadAsAsync <DeletedTicketsListResponse>());
                }
        }