示例#1
0
 protected T DeleteRequest <T>(string url, BaseOptions options, RequestOptions requestOptions)
 {
     return(Mapper <T> .MapFromJson(
                Requestor.Delete(
                    this.ApplyAllParameters(options, url),
                    this.SetupRequestOptions(requestOptions))));
 }
示例#2
0
 protected T GetRequest <T>(string url, BaseOptions options, RequestOptions requestOptions, bool isListMethod)
 {
     return(Mapper <T> .MapFromJson(
                Requestor.GetString(
                    this.ApplyAllParameters(options, url, isListMethod),
                    this.SetupRequestOptions(requestOptions))));
 }
示例#3
0
 protected async Task <T> GetRequestAsync <T>(string url, BaseOptions options, RequestOptions requestOptions, bool isListMethod, CancellationToken cancellationToken)
 {
     return(Mapper <T> .MapFromJson(
                await Requestor.GetStringAsync(
                    this.ApplyAllParameters(options, url, isListMethod),
                    this.SetupRequestOptions(requestOptions),
                    cancellationToken).ConfigureAwait(false)));
 }
示例#4
0
 protected async Task <T> DeleteRequestAsync <T>(string url, BaseOptions options, RequestOptions requestOptions, CancellationToken cancellationToken)
 {
     return(Mapper <T> .MapFromJson(
                await Requestor.DeleteAsync(
                    this.ApplyAllParameters(options, url),
                    this.SetupRequestOptions(requestOptions),
                    cancellationToken).ConfigureAwait(false)));
 }
示例#5
0
        private static HttpContent BuildContent(HttpMethod method, BaseOptions options)
        {
            if (method != HttpMethod.Post)
            {
                return(null);
            }

            return(FormEncoder.CreateHttpContent(options));
        }
示例#6
0
 protected TEntityReturned CreateNestedEntity(
     string parentId,
     BaseOptions options,
     RequestOptions requestOptions)
 {
     return(this.Request(
                HttpMethod.Post,
                this.ClassUrl(parentId),
                options,
                requestOptions));
 }
示例#7
0
 protected TEntityReturned GetNestedEntity(
     string parentId,
     string id,
     BaseOptions options,
     RequestOptions requestOptions)
 {
     return(this.Request(
                HttpMethod.Get,
                this.InstanceUrl(parentId, id),
                options,
                requestOptions));
 }
示例#8
0
 protected Task <TEntityReturned> CreateNestedEntityAsync(
     string parentId,
     BaseOptions options,
     RequestOptions requestOptions,
     CancellationToken cancellationToken)
 {
     return(this.RequestAsync(
                HttpMethod.Post,
                this.ClassUrl(parentId),
                options,
                requestOptions,
                cancellationToken));
 }
示例#9
0
 protected Task <TEntityReturned> GetNestedEntityAsync(
     string parentId,
     string id,
     BaseOptions options,
     RequestOptions requestOptions,
     CancellationToken cancellationToken)
 {
     return(this.RequestAsync(
                HttpMethod.Get,
                this.InstanceUrl(parentId, id),
                options,
                requestOptions,
                cancellationToken));
 }
示例#10
0
        /// <summary>Sends a request to Stripe's API as an asynchronous operation.</summary>
        /// <typeparam name="T">Type of the Stripe entity returned by the API.</typeparam>
        /// <param name="method">The HTTP method.</param>
        /// <param name="path">The path of the request.</param>
        /// <param name="options">The parameters of the request.</param>
        /// <param name="requestOptions">The special modifiers of the request.</param>
        /// <param name="cancellationToken">The cancellation token to cancel operation.</param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        /// <exception cref="StripeException">Thrown if the request fails.</exception>
        public async Task <T> RequestAsync <T>(
            HttpMethod method,
            string path,
            BaseOptions options,
            RequestOptions requestOptions,
            CancellationToken cancellationToken = default(CancellationToken))
            where T : IStripeEntity
        {
            var request = new StripeRequest(this, method, path, options, requestOptions);

            var response = await this.HttpClient.MakeRequestAsync(request, cancellationToken)
                           .ConfigureAwait(false);

            return(ProcessResponse <T>(response));
        }
        /// <inheritdoc/>
        public async Task <Stream> RequestStreamingAsync(
            HttpMethod method,
            string path,
            BaseOptions options,
            RequestOptions requestOptions,
            CancellationToken cancellationToken = default)
        {
            var request = new StripeRequest(this, method, path, options, requestOptions);

            var response = await this.HttpClient.MakeStreamingRequestAsync(request, cancellationToken)
                           .ConfigureAwait(false);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                return(response.Body);
            }

            var readResponse = await response.ToStripeResponseAsync().ConfigureAwait(false);

            throw BuildStripeException(readResponse);
        }
示例#12
0
        /// <summary>Initializes a new instance of the <see cref="StripeRequest"/> class.</summary>
        /// <param name="client">The client creating the request.</param>
        /// <param name="method">The HTTP method.</param>
        /// <param name="path">The path of the request.</param>
        /// <param name="options">The parameters of the request.</param>
        /// <param name="requestOptions">The special modifiers of the request.</param>
        public StripeRequest(
            IStripeClient client,
            HttpMethod method,
            string path,
            BaseOptions options,
            RequestOptions requestOptions)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            this.options = options;

            this.Method = method;

            this.Uri = BuildUri(client, method, path, options, requestOptions);

            this.AuthorizationHeader = BuildAuthorizationHeader(client, requestOptions);

            this.StripeHeaders = BuildStripeHeaders(method, requestOptions);
        }
示例#13
0
        private static Uri BuildUri(
            IStripeClient client,
            HttpMethod method,
            string path,
            BaseOptions options,
            RequestOptions requestOptions)
        {
            var b = new StringBuilder();

            b.Append(requestOptions?.BaseUrl ?? client.ApiBase);
            b.Append(path);

            if ((method != HttpMethod.Post) && (options != null))
            {
                var queryString = FormEncoder.CreateQueryString(options);
                if (!string.IsNullOrEmpty(queryString))
                {
                    b.Append("?");
                    b.Append(queryString);
                }
            }

            return(new Uri(b.ToString()));
        }
示例#14
0
 protected Task <EntityReturned> UpdateNestedEntityAsync(string parentId, string id, BaseOptions options, RequestOptions requestOptions, CancellationToken cancellationToken)
 {
     return(this.PostRequestAsync <EntityReturned>(this.InstanceUrl(parentId, id), options, requestOptions, cancellationToken));
 }
示例#15
0
 protected EntityReturned UpdateNestedEntity(string parentId, string id, BaseOptions options, RequestOptions requestOptions)
 {
     return(this.PostRequest <EntityReturned>(this.InstanceUrl(parentId, id), options, requestOptions));
 }
示例#16
0
 protected EntityReturned GetNestedEntity(string parentId, string id, BaseOptions options, RequestOptions requestOptions)
 {
     return(this.GetRequest <EntityReturned>(this.InstanceUrl(parentId, id), options, requestOptions, false));
 }
示例#17
0
 protected EntityReturned CreateNestedEntity(string parentId, BaseOptions options, RequestOptions requestOptions)
 {
     return(this.PostRequest <EntityReturned>(this.ClassUrl(parentId), options, requestOptions));
 }
示例#18
0
 protected Task <StripeList <EntityReturned> > ListNestedEntitiesAsync(string parentId, BaseOptions options, RequestOptions requestOptions, CancellationToken cancellationToken)
 {
     return(this.GetRequestAsync <StripeList <EntityReturned> >(this.ClassUrl(parentId), options, requestOptions, true, cancellationToken));
 }
示例#19
0
 protected EntityReturned CreateEntity(BaseOptions options, RequestOptions requestOptions)
 {
     return(this.PostRequest <EntityReturned>(this.ClassUrl(), options, requestOptions));
 }
示例#20
0
 protected Task <EntityReturned> CreateEntityAsync(BaseOptions options, RequestOptions requestOptions, CancellationToken cancellationToken)
 {
     return(this.PostRequestAsync <EntityReturned>(this.ClassUrl(), options, requestOptions, cancellationToken));
 }
示例#21
0
 protected EntityReturned DeleteEntity(string id, BaseOptions options, RequestOptions requestOptions)
 {
     return(this.DeleteRequest <EntityReturned>(this.InstanceUrl(id), options, requestOptions));
 }
示例#22
0
 protected StripeList <EntityReturned> ListNestedEntities(string parentId, BaseOptions options, RequestOptions requestOptions)
 {
     return(this.GetRequest <StripeList <EntityReturned> >(this.ClassUrl(parentId), options, requestOptions, true));
 }
示例#23
0
 protected Task <EntityReturned> GetEntityAsync(string id, BaseOptions options, RequestOptions requestOptions, CancellationToken cancellationToken)
 {
     return(this.GetRequestAsync <EntityReturned>(this.InstanceUrl(id), options, requestOptions, false, cancellationToken));
 }