Skip to content

Commit

Permalink
Made methods in ListExtensions.cs async (#25)
Browse files Browse the repository at this point in the history
* Made methods in ListExtensions.cs async

* Added missing await

Co-authored-by: Christian Højgaard <[email protected]>
  • Loading branch information
hoejgaard-12 and Christian Højgaard authored Aug 31, 2021
1 parent e5c6bcb commit e3ed9ca
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
using System.Collections.Generic;
using System.Globalization;
using System.Net.Http;
using System.Threading.Tasks;
using GoogleMeasurementProtocol.Parameters;

namespace GoogleMeasurementProtocol.Extensions
{
public static class ListExtensions
{
public static string GenerateQueryString(this List<Parameter> list)
public static async Task<string> GenerateQueryStringAsync(this List<Parameter> list)
{
if (list == null)
{
Expand Down Expand Up @@ -39,13 +40,13 @@ public static string GenerateQueryString(this List<Parameter> list)

using (var formUrlEncodedContent = new FormUrlEncodedContent(paramsDictionary))
{
return formUrlEncodedContent.ReadAsStringAsync().Result;
return await formUrlEncodedContent.ReadAsStringAsync();
}
}

public static StringContent GenerateStringContent(this List<Parameter> list)
public static async Task<StringContent> GenerateStringContentAsync(this List<Parameter> list)
{
return new StringContent(list.GenerateQueryString());
return new StringContent(await list.GenerateQueryStringAsync());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private async Task MakeRequestAsync()

foreach (var request in _requests)
{
sb.AppendLine(request.Parameters.GenerateQueryString());
sb.AppendLine(await request.Parameters.GenerateQueryStringAsync());
}

var response =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ internal async Task<string> MakeRequestAsync(string httpMethod, HttpClient httpC
ValidateRequestParams();

if (httpMethod == HttpMethod.GET)
return await httpClient.GetStringAsync($"{url}?{Parameters.GenerateQueryString()}").ConfigureAwait(false);
return await httpClient.GetStringAsync($"{url}?{await Parameters.GenerateQueryStringAsync()}").ConfigureAwait(false);

var response = await httpClient.PostAsync(url, Parameters.GenerateStringContent()).ConfigureAwait(false);
var response = await httpClient.PostAsync(url, await Parameters.GenerateStringContentAsync()).ConfigureAwait(false);
response.EnsureSuccessStatusCode();

return await response.Content.ReadAsStringAsync();
Expand Down

0 comments on commit e3ed9ca

Please sign in to comment.