예제 #1
0
        /// <inheritdoc/>
        public Task <List <LoanPipelineData> > ViewPipelineAsync(PipelineParameters parameters, int?limit, bool?ignoreInvalidFields, CancellationToken cancellationToken = default)
        {
            Preconditions.NotNull(parameters, nameof(parameters));
            if (limit.HasValue)
            {
                Preconditions.GreaterThan(limit.GetValueOrDefault(), nameof(limit), 0);
            }

            var queryParameters = new QueryParameters();

            if (limit.HasValue)
            {
                queryParameters.Add("limit", limit.GetValueOrDefault().ToString());
            }
            if (ignoreInvalidFields.HasValue)
            {
                queryParameters.Add("ignoreInvalidFields", ignoreInvalidFields.ToString().ToLower());
            }

            return(PostAsync <List <LoanPipelineData> >(null, queryParameters.ToString(), JsonStreamContent.Create(parameters), nameof(ViewPipelineAsync), null, cancellationToken));
        }
예제 #2
0
        /// <summary>
        /// Creates a cursor to paginate large data sets.
        /// </summary>
        /// <param name="parameters">The pipeline parameters used to specify the loans and fields to include.</param>
        /// <param name="ignoreInvalidFields">Ignores the invalid fields specified in the request body if set to <c>true</c>, else will return an error with list of invalid fields.</param>
        /// <param name="cancellationToken">The token to monitor for cancellation requests. The default value is <see cref="CancellationToken.None"/>.</param>
        /// <returns></returns>
        public Task <LoanPipelineCursor> CreateCursorAsync(PipelineParameters parameters, bool?ignoreInvalidFields, CancellationToken cancellationToken = default)
        {
            Preconditions.NotNull(parameters, nameof(parameters));

            var queryParameters = new QueryParameters(
                new QueryParameter("limit", "1"),
                new QueryParameter("cursorType", "randomAccess"));

            if (ignoreInvalidFields.HasValue)
            {
                queryParameters.Add("ignoreInvalidFields", ignoreInvalidFields.ToString().ToLower());
            }

            return(PostAsync(null, queryParameters.ToString(), JsonStreamContent.Create(parameters), nameof(CreateCursorAsync), null, cancellationToken, async response =>
            {
                var headers = response.Headers;
                const string countHeaderName = "x-total-count";
                if (!headers.TryGetValues(countHeaderName, out var counts))
                {
                    throw await EncompassApiException.CreateAsync($"{nameof(CreateCursorAsync)} missing {countHeaderName} header", response).ConfigureAwait(false);
                }
                var countString = counts.First();
                if (!int.TryParse(countString, out var count) || count < 0)
                {
                    throw await EncompassApiException.CreateAsync($"{nameof(CreateCursorAsync)} invalid {countHeaderName} header value", response).ConfigureAwait(false);
                }
                string?cursorId = null;
                if (count > 0)
                {
                    const string cursorIdHeaderName = "x-cursor";
                    if (!headers.TryGetValues(cursorIdHeaderName, out var cursorIds))
                    {
                        throw await EncompassApiException.CreateAsync($"{nameof(CreateCursorAsync)} missing {cursorIdHeaderName} header", response).ConfigureAwait(false);
                    }
                    cursorId = cursorIds.First();
                }
                return new LoanPipelineCursor(Client, cursorId, count, parameters.Fields);
            }));
        }
예제 #3
0
 /// <inheritdoc/>
 public Task <List <LoanPipelineData> > ViewPipelineAsync(PipelineParameters parameters, bool?ignoreInvalidFields, CancellationToken cancellationToken = default) => ViewPipelineAsync(parameters, null, ignoreInvalidFields, cancellationToken);
예제 #4
0
 /// <inheritdoc/>
 public Task <List <LoanPipelineData> > ViewPipelineAsync(PipelineParameters parameters, int?limit, CancellationToken cancellationToken = default) => ViewPipelineAsync(parameters, limit, null, cancellationToken);
예제 #5
0
 async Task <ILoanPipelineCursor> IPipeline.CreateCursorAsync(PipelineParameters parameters, bool?ignoreInvalidFields, CancellationToken cancellationToken) => await CreateCursorAsync(parameters, ignoreInvalidFields, cancellationToken).ConfigureAwait(false);
예제 #6
0
 Task <ILoanPipelineCursor> IPipeline.CreateCursorAsync(PipelineParameters parameters, CancellationToken cancellationToken) => ((IPipeline)this).CreateCursorAsync(parameters, null, cancellationToken);
예제 #7
0
 /// <summary>
 /// Creates a cursor to paginate large data sets.
 /// </summary>
 /// <param name="parameters">The pipeline parameters used to specify the loans and fields to include.</param>
 /// <param name="cancellationToken">The token to monitor for cancellation requests. The default value is <see cref="CancellationToken.None"/>.</param>
 /// <returns></returns>
 public Task <LoanPipelineCursor> CreateCursorAsync(PipelineParameters parameters, CancellationToken cancellationToken = default) => CreateCursorAsync(parameters, null, cancellationToken);