Skip to content

Commit

Permalink
Add Uri overloads to WebAPIQuerier methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Elanis committed Nov 25, 2023
1 parent a0f2fe4 commit f4c4514
Showing 1 changed file with 50 additions and 10 deletions.
60 changes: 50 additions & 10 deletions Dysnomia.Common.WebAPIWrapper/WebAPIQuerier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,54 +77,94 @@ protected static async Task ThrowApiErrorsAsync(HttpResponseMessage response) {
ThrowOnStatusCode(response.StatusCode, apiError);
}

protected async Task<string> GetStringAsync(string url, Dictionary<string, string> headers) {
protected async Task<string> GetStringAsync(Uri url, Dictionary<string, string> headers) {
var response = await GetClient(headers).GetAsync(url);

await ThrowApiErrorsAsync(response);

return await response.Content.ReadAsStringAsync();
}

protected async Task<string> GetStringAsync(string url) {
protected async Task<string> GetStringAsync(Uri url) {
return await GetStringAsync(url, null);
}

protected async Task<T> GetAsync<T>(string url, Dictionary<string, string> headers) {
protected async Task<string> GetStringAsync(string url, Dictionary<string, string> headers) {
return await GetStringAsync(new Uri(url), headers);
}

protected async Task<string> GetStringAsync(string url) {

Check warning on line 96 in Dysnomia.Common.WebAPIWrapper/WebAPIQuerier.cs

View workflow job for this annotation

GitHub Actions / build

Refactor this method so it invokes the overload accepting a 'System.Uri' parameter. (https://rules.sonarsource.com/csharp/RSPEC-3997)

Check warning on line 96 in Dysnomia.Common.WebAPIWrapper/WebAPIQuerier.cs

View workflow job for this annotation

GitHub Actions / build

Refactor this method so it invokes the overload accepting a 'System.Uri' parameter. (https://rules.sonarsource.com/csharp/RSPEC-3997)
return await GetStringAsync(new Uri(url), null);
}

protected async Task<T> GetAsync<T>(Uri url, Dictionary<string, string> headers) {

Check warning on line 100 in Dysnomia.Common.WebAPIWrapper/WebAPIQuerier.cs

View workflow job for this annotation

GitHub Actions / build

Refactor this method to use all type parameters in the parameter list to enable type inference. (https://rules.sonarsource.com/csharp/RSPEC-4018)

Check warning on line 100 in Dysnomia.Common.WebAPIWrapper/WebAPIQuerier.cs

View workflow job for this annotation

GitHub Actions / build

Refactor this method to use all type parameters in the parameter list to enable type inference. (https://rules.sonarsource.com/csharp/RSPEC-4018)
return JsonSerializer.Deserialize<T>(await GetStringAsync(url, headers));
}

protected async Task<T> GetAsync<T>(string url) {
protected async Task<T> GetAsync<T>(Uri url) {

Check warning on line 104 in Dysnomia.Common.WebAPIWrapper/WebAPIQuerier.cs

View workflow job for this annotation

GitHub Actions / build

Refactor this method to use all type parameters in the parameter list to enable type inference. (https://rules.sonarsource.com/csharp/RSPEC-4018)

Check warning on line 104 in Dysnomia.Common.WebAPIWrapper/WebAPIQuerier.cs

View workflow job for this annotation

GitHub Actions / build

Refactor this method to use all type parameters in the parameter list to enable type inference. (https://rules.sonarsource.com/csharp/RSPEC-4018)
return await GetAsync<T>(url, null);
}

protected async Task<string> PostStringAsync(string url, HttpContent content, Dictionary<string, string> headers) {
protected async Task<T> GetAsync<T>(string url, Dictionary<string, string> headers) {

Check warning on line 108 in Dysnomia.Common.WebAPIWrapper/WebAPIQuerier.cs

View workflow job for this annotation

GitHub Actions / build

Refactor this method to use all type parameters in the parameter list to enable type inference. (https://rules.sonarsource.com/csharp/RSPEC-4018)

Check warning on line 108 in Dysnomia.Common.WebAPIWrapper/WebAPIQuerier.cs

View workflow job for this annotation

GitHub Actions / build

Refactor this method so it invokes the overload accepting a 'System.Uri' parameter. (https://rules.sonarsource.com/csharp/RSPEC-3997)

Check warning on line 108 in Dysnomia.Common.WebAPIWrapper/WebAPIQuerier.cs

View workflow job for this annotation

GitHub Actions / build

Refactor this method to use all type parameters in the parameter list to enable type inference. (https://rules.sonarsource.com/csharp/RSPEC-4018)

Check warning on line 108 in Dysnomia.Common.WebAPIWrapper/WebAPIQuerier.cs

View workflow job for this annotation

GitHub Actions / build

Refactor this method so it invokes the overload accepting a 'System.Uri' parameter. (https://rules.sonarsource.com/csharp/RSPEC-3997)
return await GetAsync<T>(new Uri(url), headers);
}

protected async Task<T> GetAsync<T>(string url) {

Check warning on line 112 in Dysnomia.Common.WebAPIWrapper/WebAPIQuerier.cs

View workflow job for this annotation

GitHub Actions / build

Refactor this method to use all type parameters in the parameter list to enable type inference. (https://rules.sonarsource.com/csharp/RSPEC-4018)

Check warning on line 112 in Dysnomia.Common.WebAPIWrapper/WebAPIQuerier.cs

View workflow job for this annotation

GitHub Actions / build

Refactor this method to use all type parameters in the parameter list to enable type inference. (https://rules.sonarsource.com/csharp/RSPEC-4018)

Check warning on line 112 in Dysnomia.Common.WebAPIWrapper/WebAPIQuerier.cs

View workflow job for this annotation

GitHub Actions / build

Refactor this method so it invokes the overload accepting a 'System.Uri' parameter. (https://rules.sonarsource.com/csharp/RSPEC-3997)
return await GetAsync<T>(new Uri(url), null);
}

protected async Task<string> PostStringAsync(Uri url, HttpContent content, Dictionary<string, string> headers) {
var response = await GetClient(headers).PostAsync(url, content);

await ThrowApiErrorsAsync(response);

return await response.Content.ReadAsStringAsync();
}

protected async Task<string> PostStringAsync(string url, HttpContent content) {
protected async Task<string> PostStringAsync(Uri url, HttpContent content) {
return await PostStringAsync(url, content, null);
}

protected async Task PostAsync(string url, HttpContent content, Dictionary<string, string> headers) {
protected async Task<string> PostStringAsync(string url, HttpContent content, Dictionary<string, string> headers) {
return await PostStringAsync(new Uri(url), content, headers);
}

protected async Task<string> PostStringAsync(string url, HttpContent content) {
return await PostStringAsync(new Uri(url), content, null);
}

protected async Task PostAsync(Uri url, HttpContent content, Dictionary<string, string> headers) {
var response = await GetClient(headers).PostAsync(url, content);

await ThrowApiErrorsAsync(response);
}

protected async Task PostAsync(string url, HttpContent content) {
protected async Task PostAsync(Uri url, HttpContent content) {
await PostAsync(url, content, null);
}

protected async Task<T> PostAsync<T>(string url, HttpContent content, Dictionary<string, string> headers) {
protected async Task PostAsync(string url, HttpContent content, Dictionary<string, string> headers) {
await PostAsync(new Uri(url), content, headers);
}

protected async Task PostAsync(string url, HttpContent content) {
await PostAsync(new Uri(url), content, null);
}

protected async Task<T> PostAsync<T>(Uri url, HttpContent content, Dictionary<string, string> headers) {
return JsonSerializer.Deserialize<T>(await PostStringAsync(url, content, headers));
}

protected async Task<T> PostAsync<T>(string url, HttpContent content) {
protected async Task<T> PostAsync<T>(Uri url, HttpContent content) {
return await PostAsync<T>(url, content, null);
}

protected async Task<T> PostAsync<T>(string url, HttpContent content, Dictionary<string, string> headers) {
return await PostAsync<T>(new Uri(url), content, headers);
}

protected async Task<T> PostAsync<T>(string url, HttpContent content) {
return await PostAsync<T>(new Uri(url), content, null);
}
}
}

0 comments on commit f4c4514

Please sign in to comment.