Skip to content

Commit

Permalink
Merge pull request #13 from TBCBank/feature/PostUrlFormAsync
Browse files Browse the repository at this point in the history
Add PostUrlFormAsync
  • Loading branch information
lachinchaladze authored Aug 22, 2022
2 parents efe7f05 + 2f691fa commit a7583d9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
24 changes: 12 additions & 12 deletions src/TBC.OpenAPI.SDK.Core/HttpHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ public async Task<ApiResponse<TResponseData>> PostJsonAsync<TRequestData, TRespo



public Task<ApiResponse<TResponseData>> PostJsonAsync<TResponseData>(string path, StringContent content, string mediaType = "application/json", CancellationToken cancellationToken = default)
=> PostJsonAsync<TResponseData>(path, content, null, null, mediaType, cancellationToken);
public Task<ApiResponse<TResponseData>> PostUrlFormAsync<TResponseData>(string path, UrlFormCollection content, CancellationToken cancellationToken = default)
=> PostUrlFormAsync<TResponseData>(path, content, null, null, cancellationToken);

public Task<ApiResponse<TResponseData>> PostJsonAsync<TResponseData>(string path, StringContent content, QueryParamCollection? query = null, string mediaType = "application/json", CancellationToken cancellationToken = default)
=> PostJsonAsync<TResponseData>(path, content, query, null,mediaType, cancellationToken);
public Task<ApiResponse<TResponseData>> PostUrlFormAsync<TResponseData>(string path, UrlFormCollection content, QueryParamCollection? query = null, CancellationToken cancellationToken = default)
=> PostUrlFormAsync<TResponseData>(path, content, query, null, cancellationToken);

public async Task<ApiResponse<TResponseData>> PostJsonAsync<TResponseData>(string path, StringContent content, QueryParamCollection? query = null, HeaderParamCollection? headers = null, string mediaType = "application/json", CancellationToken cancellationToken = default)
public async Task<ApiResponse<TResponseData>> PostUrlFormAsync<TResponseData>(string path, UrlFormCollection content, QueryParamCollection? query = null, HeaderParamCollection? headers = null, CancellationToken cancellationToken = default)
{
var httpClient = GetHttpClient();
var requestMessage = CreateRequestMessage(httpClient, HttpMethod.Post, path, query, headers);
requestMessage.Content = content;
requestMessage.Content = new FormUrlEncodedContent(content);
return await SendRequestMessage<TResponseData>(httpClient, requestMessage, cancellationToken).ConfigureAwait(false);
}

Expand All @@ -93,17 +93,17 @@ public async Task<ApiResponseBase> PostJsonAsync<TRequestData>(string path, TReq
}


public Task<ApiResponseBase> PostJsonAsync(string path, StringContent content, string mediaType = "application/json", CancellationToken cancellationToken = default)
=> PostJsonAsync(path, content, null, null,mediaType, cancellationToken);
public Task<ApiResponseBase> PostUrlFormAsync(string path, UrlFormCollection content, CancellationToken cancellationToken = default)
=> PostUrlFormAsync(path, content, null, null, cancellationToken);

public Task<ApiResponseBase> PostJsonAsync(string path, StringContent content, QueryParamCollection? query = null, string mediaType = "application/json", CancellationToken cancellationToken = default)
=> PostJsonAsync(path, content, query, null, mediaType, cancellationToken);
public Task<ApiResponseBase> PostUrlFormAsync(string path, UrlFormCollection content, QueryParamCollection? query = null, CancellationToken cancellationToken = default)
=> PostUrlFormAsync(path, content, query, null, cancellationToken);

public async Task<ApiResponseBase> PostJsonAsync(string path, StringContent content, QueryParamCollection? query = null, HeaderParamCollection? headers = null, string mediaType = "application/json", CancellationToken cancellationToken = default)
public async Task<ApiResponseBase> PostUrlFormAsync(string path, UrlFormCollection content, QueryParamCollection? query = null, HeaderParamCollection? headers = null, CancellationToken cancellationToken = default)
{
var httpClient = GetHttpClient();
var requestMessage = CreateRequestMessage(httpClient, HttpMethod.Post, path, query, headers);
requestMessage.Content = content;
requestMessage.Content = new FormUrlEncodedContent(content);
return await SendRequestMessage(httpClient, requestMessage, cancellationToken).ConfigureAwait(false);
}

Expand Down
12 changes: 6 additions & 6 deletions src/TBC.OpenAPI.SDK.Core/IHttpHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public interface IHttpHelper<TClient>
public Task<ApiResponse<TResponseData>> PostJsonAsync<TRequestData, TResponseData>(string path, TRequestData data, QueryParamCollection? query = null, HeaderParamCollection? headers = null, CancellationToken cancellationToken = default);


public Task<ApiResponse<TResponseData>> PostJsonAsync<TResponseData>(string path, StringContent content, string mediaType = "application/json", CancellationToken cancellationToken = default);
public Task<ApiResponse<TResponseData>> PostJsonAsync<TResponseData>(string path, StringContent content, QueryParamCollection? query = null, string mediaType = "application/json", CancellationToken cancellationToken = default);
public Task<ApiResponse<TResponseData>> PostJsonAsync<TResponseData>(string path, StringContent content, QueryParamCollection? query = null, HeaderParamCollection? headers = null, string mediaType = "application/json", CancellationToken cancellationToken = default);
public Task<ApiResponse<TResponseData>> PostUrlFormAsync<TResponseData>(string path, UrlFormCollection content, CancellationToken cancellationToken = default);
public Task<ApiResponse<TResponseData>> PostUrlFormAsync<TResponseData>(string path, UrlFormCollection content, QueryParamCollection? query = null, CancellationToken cancellationToken = default);
public Task<ApiResponse<TResponseData>> PostUrlFormAsync<TResponseData>(string path, UrlFormCollection content, QueryParamCollection? query = null, HeaderParamCollection? headers = null, CancellationToken cancellationToken = default);



Expand All @@ -30,9 +30,9 @@ public interface IHttpHelper<TClient>
public Task<ApiResponseBase> PostJsonAsync<TRequestData>(string path, TRequestData data, QueryParamCollection? query = null, HeaderParamCollection? headers = null, CancellationToken cancellationToken = default);


public Task<ApiResponseBase> PostJsonAsync(string path, StringContent content, string mediaType = "application/json", CancellationToken cancellationToken = default);
public Task<ApiResponseBase> PostJsonAsync(string path, StringContent content, QueryParamCollection? query = null, string mediaType = "application/json", CancellationToken cancellationToken = default);
public Task<ApiResponseBase> PostJsonAsync(string path, StringContent content, QueryParamCollection? query = null, HeaderParamCollection? headers = null, string mediaType = "application/json", CancellationToken cancellationToken = default);
public Task<ApiResponseBase> PostUrlFormAsync(string path, UrlFormCollection content, CancellationToken cancellationToken = default);
public Task<ApiResponseBase> PostUrlFormAsync(string path, UrlFormCollection content, QueryParamCollection? query = null, CancellationToken cancellationToken = default);
public Task<ApiResponseBase> PostUrlFormAsync(string path, UrlFormCollection content, QueryParamCollection? query = null, HeaderParamCollection? headers = null, CancellationToken cancellationToken = default);
#endregion

#region Put
Expand Down
10 changes: 10 additions & 0 deletions src/TBC.OpenAPI.SDK.Core/Models/UrlFormCollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace TBC.OpenAPI.SDK.Core.Models
{
public class UrlFormCollection : Dictionary<string, string>
{
}
}

0 comments on commit a7583d9

Please sign in to comment.