Ejemplo n.º 1
0
        public static async Task <T> PostAsync <T>(IXApiContext context, string path,
                                                   object?parameters = default,
                                                   Func <HttpContent, Task <T> >?contentDeserializer = default)
        {
            using var request  = CreateRequest(context, HttpMethod.Post, path, parameters);
            using var response = await _client.SendAsync(request).ConfigureAwait(false);

            return(await DeserializeContentAsync(response, contentDeserializer).ConfigureAwait(false));
        }
Ejemplo n.º 2
0
        public static async Task <T> PostAsync <T>(IXApiContext context, string path,
                                                   object parameters = default,
                                                   Func <HttpContent, CancellationToken, Task <T> > contentDeserializer = default,
                                                   CancellationToken cancellationToken = default)
        {
            using HttpRequestMessage request   = CreateRequest(context, HttpMethod.Post, path, parameters);
            using HttpResponseMessage response = await _client.SendAsync(request, cancellationToken).ConfigureAwait(false);

            return(await DeserializeContentAsync(response, contentDeserializer, cancellationToken).ConfigureAwait(false));
        }
Ejemplo n.º 3
0
        public static HttpRequestMessage CreateRequest(IXApiContext context, HttpMethod method, string path,
                                                       object parameters = default)
        {
            var request = new HttpRequestMessage(method, context.BaseUri.GetLeftPart(UriPartial.Authority) + path);

            if (!string.IsNullOrEmpty(context.Key))
            {
                request.Headers.Add("X-Key", context.Key);
            }

            if (parameters is not null)
            {
                request.Content = JsonContent.Create(parameters, options: _serializerOptions);
            }

            return(request);
        }
Ejemplo n.º 4
0
        public static HttpRequestMessage CreateRequest(IXApiContext context, HttpMethod method, string path,
                                                       object?parameters = default)
        {
            var request = new HttpRequestMessage(method, context.BaseUri.GetLeftPart(UriPartial.Authority) + path);

            if (!string.IsNullOrEmpty(context.Key))
            {
                request.Headers.Add("X-Key", context.Key);
            }

            if (parameters != default)
            {
                string jsonContent = JsonSerializer.Serialize(parameters, _serializerOptions);
                request.Content = new StringContent(jsonContent, Encoding.UTF8, "application/json");
            }
            return(request);
        }
Ejemplo n.º 5
0
        public static async Task <T> GetAsync <T>(IXApiContext context, string path,
                                                  Dictionary <string, object>?queryParameters       = default,
                                                  Func <HttpContent, Task <T> >?contentDeserializer = default)
        {
            if (queryParameters?.Count > 0)
            {
                var query = HttpUtility.ParseQueryString(string.Empty); //We need QueryBuilder
                foreach (var(key, value) in queryParameters)
                {
                    query.Add(key, value.ToString());
                }
                path += "?" + query.ToString();
            }

            using var request  = CreateRequest(context, HttpMethod.Get, path);
            using var response = await _client.SendAsync(request).ConfigureAwait(false);

            return(await DeserializeContentAsync(response, contentDeserializer).ConfigureAwait(false));
        }
Ejemplo n.º 6
0
 protected SearchApi(string apiPathSegment, IXApiContext context)
 {
     _apiPathSegment = apiPathSegment;
     _context        = context;
 }
 public PhoneBookSearchApi(IXApiContext context)
     : base("/phonebook", context)
 {
 }
Ejemplo n.º 8
0
 public FileApi(IXApiContext context)
 {
     _context = context;
 }
Ejemplo n.º 9
0
 public ItemApi(IXApiContext context)
 {
     _context = context;
 }
Ejemplo n.º 10
0
 public static Task <AuthenticationInfo> GetAuthenticationInfoAsync(IXApiContext context, CancellationToken cancellationToken = default)
 => GetAsync <AuthenticationInfo>(context, "/authenticate/info", cancellationToken: cancellationToken);
Ejemplo n.º 11
0
 public IntelligentSearchApi(IXApiContext context)
     : base("/intelligent", context)
 {
 }
Ejemplo n.º 12
0
 public static Task <AuthenticationInfo> GetAuthenticationInfoAsync(IXApiContext context) => GetAsync <AuthenticationInfo>(context, "/authenticate/info");