protected T DeleteRequest <T>(string url, BaseOptions options, RequestOptions requestOptions) { return(Mapper <T> .MapFromJson( Requestor.Delete( this.ApplyAllParameters(options, url), this.SetupRequestOptions(requestOptions)))); }
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)))); }
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))); }
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))); }
private static HttpContent BuildContent(HttpMethod method, BaseOptions options) { if (method != HttpMethod.Post) { return(null); } return(FormEncoder.CreateHttpContent(options)); }
protected TEntityReturned CreateNestedEntity( string parentId, BaseOptions options, RequestOptions requestOptions) { return(this.Request( HttpMethod.Post, this.ClassUrl(parentId), options, requestOptions)); }
protected TEntityReturned GetNestedEntity( string parentId, string id, BaseOptions options, RequestOptions requestOptions) { return(this.Request( HttpMethod.Get, this.InstanceUrl(parentId, id), options, requestOptions)); }
protected Task <TEntityReturned> CreateNestedEntityAsync( string parentId, BaseOptions options, RequestOptions requestOptions, CancellationToken cancellationToken) { return(this.RequestAsync( HttpMethod.Post, this.ClassUrl(parentId), options, requestOptions, cancellationToken)); }
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)); }
/// <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); }
/// <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); }
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())); }
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)); }
protected EntityReturned UpdateNestedEntity(string parentId, string id, BaseOptions options, RequestOptions requestOptions) { return(this.PostRequest <EntityReturned>(this.InstanceUrl(parentId, id), options, requestOptions)); }
protected EntityReturned GetNestedEntity(string parentId, string id, BaseOptions options, RequestOptions requestOptions) { return(this.GetRequest <EntityReturned>(this.InstanceUrl(parentId, id), options, requestOptions, false)); }
protected EntityReturned CreateNestedEntity(string parentId, BaseOptions options, RequestOptions requestOptions) { return(this.PostRequest <EntityReturned>(this.ClassUrl(parentId), options, requestOptions)); }
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)); }
protected EntityReturned CreateEntity(BaseOptions options, RequestOptions requestOptions) { return(this.PostRequest <EntityReturned>(this.ClassUrl(), options, requestOptions)); }
protected Task <EntityReturned> CreateEntityAsync(BaseOptions options, RequestOptions requestOptions, CancellationToken cancellationToken) { return(this.PostRequestAsync <EntityReturned>(this.ClassUrl(), options, requestOptions, cancellationToken)); }
protected EntityReturned DeleteEntity(string id, BaseOptions options, RequestOptions requestOptions) { return(this.DeleteRequest <EntityReturned>(this.InstanceUrl(id), options, requestOptions)); }
protected StripeList <EntityReturned> ListNestedEntities(string parentId, BaseOptions options, RequestOptions requestOptions) { return(this.GetRequest <StripeList <EntityReturned> >(this.ClassUrl(parentId), options, requestOptions, true)); }
protected Task <EntityReturned> GetEntityAsync(string id, BaseOptions options, RequestOptions requestOptions, CancellationToken cancellationToken) { return(this.GetRequestAsync <EntityReturned>(this.InstanceUrl(id), options, requestOptions, false, cancellationToken)); }