Exemple #1
0
        /// <summary>
        /// Revokes a key.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <param name="reason">The reason.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <exception cref="ArgumentNullException">id</exception>
        public async Task RevokeKeyAsync(string id, string reason, CancellationToken cancellationToken = default)
        {
            id = id ?? throw new ArgumentNullException(nameof(id));
            var httpClient = await HttpClientFactory
                             .ConfigureAwait(false);

            using (var response = await httpClient.DeleteAsync(GetUri(httpClient, $"{BaseUri}/{id}?reason={reason}"), cancellationToken)
                                  .ConfigureAwait(false))
            {
                await EnsureSuccess(response)
                .ConfigureAwait(false);
            }
        }
Exemple #2
0
        /// <summary>
        /// Gets keys.
        /// </summary>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public async Task <PageResponse <Key> > GetAllKeysAsync(CancellationToken cancellationToken = default)
        {
            var httpClient = await HttpClientFactory
                             .ConfigureAwait(false);

            using (var response = await httpClient.GetAsync(GetUri(httpClient, BaseUri), cancellationToken)
                                  .ConfigureAwait(false))
            {
                await EnsureSuccess(response)
                .ConfigureAwait(false);

                return(await DeserializeResponse <PageResponse <Key> >(response)
                       .ConfigureAwait(false));
            }
        }
Exemple #3
0
 public virtual async Task<T> CreateAsync(T entity, CancellationToken cancellationToken = default)
 {
     entity = entity ?? throw new ArgumentNullException(nameof(entity));
     var httpClient = await HttpClientFactory
         .ConfigureAwait(false);
     using (var content = new StringContent(SerializeEntity(entity), Encoding.UTF8, "application/json"))
     {
         using (var response = await httpClient.PostAsync(GetUri(httpClient, BaseUri), content, cancellationToken)
             .ConfigureAwait(false))
         {
             await EnsureSuccess(response).ConfigureAwait(false);
             return await DeserializeResponse(response)
                 .ConfigureAwait(false);
         }
     }
 }
Exemple #4
0
        public async Task <T> GetAsync(string id, GetRequest request, CancellationToken cancellationToken = default)
        {
            var httpClient = await HttpClientFactory
                             .ConfigureAwait(false);

            var expandParameter = request != null ? $"?expand={request.Expand}" : string.Empty;

            using (var response = await httpClient.GetAsync(GetUri(httpClient, $"{BaseUri}/{id}{expandParameter}"), cancellationToken)
                                  .ConfigureAwait(false))
            {
                await EnsureSuccess(response)
                .ConfigureAwait(false);

                return(await DeserializeResponse(response)
                       .ConfigureAwait(false));
            }
        }
Exemple #5
0
        public async Task <T> UpdateAsync(T entity, CancellationToken cancellationToken = default)
        {
            entity = entity ?? throw new ArgumentNullException(nameof(entity));

            var httpClient = await HttpClientFactory
                             .ConfigureAwait(false);

            using (var content = new StringContent(SerializeEntity(entity), Encoding.UTF8, "application/json"))
            {
                var id = _idProperty.GetValue(entity);
                using (var response = await httpClient.PutAsync(GetUri(httpClient, $"{BaseUri}/{id}"), content, cancellationToken)
                                      .ConfigureAwait(false))
                {
                    await EnsureSuccess(response).ConfigureAwait(false);

                    return(await DeserializeResponse(response)
                           .ConfigureAwait(false));
                }
            }
        }
Exemple #6
0
        public async Task <PageResponse <T> > GetAsync(PageRequest request, CancellationToken cancellationToken = default)
        {
            request = request ?? new PageRequest();

            var dictionary = typeof(PageRequest)
                             .GetProperties()
                             .Where(p => p.GetValue(request) != null)
                             .ToDictionary(p => p.Name.ToLowerInvariant(), p => p.GetValue(request).ToString());

            var httpClient = await HttpClientFactory
                             .ConfigureAwait(false);

            using (var response = await httpClient.GetAsync(GetUri(httpClient, QueryHelpers.AddQueryString(BaseUri, dictionary)), cancellationToken)
                                  .ConfigureAwait(false))
            {
                await EnsureSuccess(response)
                .ConfigureAwait(false);

                return(await DeserializeResponse <PageResponse <T> >(response)
                       .ConfigureAwait(false));
            }
        }