internal async Task<BlipResponse> ExecuteCommand(Command command, string path, string content=null)
{
var encodedPath = Uri.EscapeUriString(path);
using (var httpClient = new HttpClient())
using (var client = ConfigureClient(httpClient))
{
switch (command)
{
case Command.Get:
{
using (var response = await client.GetAsync(encodedPath))
{
response.EnsureSuccessStatusCode();
return await BuildResponse(response);
}
}
case Command.Put:
{
using (var httpContent = new StringContent(content, Encoding.UTF8, "application/json"))
using (var response = await client.PutAsync(encodedPath, httpContent))
{
response.EnsureSuccessStatusCode();
return await BuildResponse(response);
}
}
case Command.Post:
{
using (var httpContent = new StringContent(content, Encoding.UTF8, "application/json"))
using (var response = await client.PostAsync(encodedPath, httpContent))
{
response.EnsureSuccessStatusCode();
return await BuildResponse(response);
}
}
case Command.Delete:
{
using (var response = await client.DeleteAsync(encodedPath))
{
response.EnsureSuccessStatusCode();
return await BuildResponse(response);
}
}
default:
throw new ArgumentOutOfRangeException($"Invalid HTTP Command: {command}");
}
}
}