Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add encodeURI logic #36

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 27 additions & 23 deletions src/ArcGISEarth.AutoAPI.Shared/AutomationAPIHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,10 @@ public static async Task<string> GetLayer(string layerId)
{
try
{
string encodedId = Uri.EscapeDataString(layerId);
string layerRequestUrl = $"{APIBaseUrl}/{LAYER_CONTROLLER_NAME}";
HttpClient httpClient = new HttpClient();
var layerIdUrl = $"{layerRequestUrl}/{layerId}";
HttpClient httpClient = new();
var layerIdUrl = $"{layerRequestUrl}/{encodedId}";
HttpResponseMessage responseMessage = await httpClient.GetAsync(layerIdUrl).ConfigureAwait(false);
return await GetResponseContent(responseMessage);
}
Expand All @@ -216,9 +217,10 @@ public static async Task<string> RemoveLayer(string layerId)
{
try
{
string encodedId = Uri.EscapeDataString(layerId);
string layerRequestUrl = $"{APIBaseUrl}/{LAYER_CONTROLLER_NAME}";
HttpClient httpClient = new HttpClient();
var layerIdUrl = $"{layerRequestUrl}/{layerId}";
HttpClient httpClient = new();
var layerIdUrl = $"{layerRequestUrl}/{encodedId}";
HttpResponseMessage responseMessage = await httpClient.DeleteAsync(layerIdUrl).ConfigureAwait(false);
return await GetResponseContent(responseMessage);
}
Expand All @@ -238,7 +240,7 @@ public static async Task<string> ClearLayers(string targetType)
try
{
string layersRequestUrl = $"{APIBaseUrl}/{LAYERS_CONTROLLER_NAME}/{targetType}";
HttpClient httpClient = new HttpClient();
HttpClient httpClient = new();
HttpResponseMessage responseMessage = await httpClient.DeleteAsync(layersRequestUrl).ConfigureAwait(false);
return await GetResponseContent(responseMessage);
}
Expand Down Expand Up @@ -294,9 +296,10 @@ public static async Task<string> GetGraphic(string graphicId)
{
try
{
string encodedId = Uri.EscapeDataString(graphicId);
string graphicRequestUrl = $"{APIBaseUrl}/{GRAPHIC_CONTROLLER_NAME}";
HttpClient httpClient = new HttpClient();
var graphicIdUrl = $"{graphicRequestUrl}/{graphicId}";
HttpClient httpClient = new();
var graphicIdUrl = $"{graphicRequestUrl}/{encodedId}";
HttpResponseMessage responseMessage = await httpClient.GetAsync(graphicIdUrl).ConfigureAwait(false);
return await GetResponseContent(responseMessage);
}
Expand Down Expand Up @@ -333,7 +336,7 @@ public static async Task<string> UpdateGraphic(string inputJsonStr)
try
{
string graphicRequestUrl = $"{APIBaseUrl}/{GRAPHIC_CONTROLLER_NAME}";
HttpClient httpClient = new HttpClient();
HttpClient httpClient = new();
HttpContent postContent = ConvertJsonToHttpContent(inputJsonStr);
HttpResponseMessage responseMessage = await httpClient.PatchAsync(graphicRequestUrl, postContent).ConfigureAwait(false);
return await GetResponseContent(responseMessage);
Expand All @@ -353,9 +356,10 @@ public static async Task<string> RemoveGraphic(string graphicId)
{
try
{
string encodedId = Uri.EscapeDataString(graphicId);
string graphicRequestUrl = $"{APIBaseUrl}/{GRAPHIC_CONTROLLER_NAME}";
HttpClient httpClient = new HttpClient();
var graphicIdUrl = $"{graphicRequestUrl}/{graphicId}";
HttpClient httpClient = new();
var graphicIdUrl = $"{graphicRequestUrl}/{encodedId}";
HttpResponseMessage responseMessage = await httpClient.DeleteAsync(graphicIdUrl).ConfigureAwait(false);
return await GetResponseContent(responseMessage);
}
Expand All @@ -374,7 +378,7 @@ public static async Task<string> ClearGraphics()
try
{
string graphicsRequestUrl = $"{APIBaseUrl}/{GRAPHIC_CONTROLLER_NAME}";
HttpClient httpClient = new HttpClient();
HttpClient httpClient = new();
HttpResponseMessage responseMessage = await httpClient.DeleteAsync(graphicsRequestUrl).ConfigureAwait(false);
return await GetResponseContent(responseMessage);
}
Expand Down Expand Up @@ -424,7 +428,7 @@ public static async Task<string> AddDrawing(string inputJsonStr)
try
{
string drawingsRequestUrl = $"{APIBaseUrl}/{DRAWING_CONTROLLER_NAME}";
HttpClient httpClient = new HttpClient();
HttpClient httpClient = new();
HttpContent postContent = ConvertJsonToHttpContent(inputJsonStr);
HttpResponseMessage responseMessage = await httpClient.PostAsync(drawingsRequestUrl, postContent).ConfigureAwait(false);
return await GetResponseContent(responseMessage);
Expand All @@ -444,9 +448,10 @@ public static async Task<string> RemoveDrawing(string drawingId)
{
try
{
string encodedId = Uri.EscapeDataString(drawingId);
string drawingsRequestUrl = $"{APIBaseUrl}/{DRAWING_CONTROLLER_NAME}";
HttpClient httpClient = new HttpClient();
var drawingIdUrl = $"{drawingsRequestUrl}/{drawingId}";
HttpClient httpClient = new();
var drawingIdUrl = $"{drawingsRequestUrl}/{encodedId}";
HttpResponseMessage responseMessage = await httpClient.DeleteAsync(drawingIdUrl).ConfigureAwait(false);
return await GetResponseContent(responseMessage);
}
Expand All @@ -465,7 +470,7 @@ public static async Task<string> ClearDrawings()
try
{
string drawingsRequestUrl = $"{APIBaseUrl}/{DRAWING_CONTROLLER_NAME}";
HttpClient httpClient = new HttpClient();
HttpClient httpClient = new();
HttpResponseMessage responseMessage = await httpClient.DeleteAsync(drawingsRequestUrl).ConfigureAwait(false);
return await GetResponseContent(responseMessage);
}
Expand All @@ -489,7 +494,7 @@ public static async Task<string> GetWorkspace()
try
{
string workspaceRequestUrl = $"{APIBaseUrl}/{WORKSPACE_CONTROLLER_NAME}";
HttpClient httpClient = new HttpClient();
HttpClient httpClient = new();
HttpResponseMessage responseMessage = await httpClient.GetAsync(workspaceRequestUrl).ConfigureAwait(false);
return await GetResponseContent(responseMessage);
}
Expand All @@ -514,7 +519,7 @@ public static async Task<string> ImportWorkspace(string inputJsonStr)
try
{
string workspaceRequestUrl = $"{APIBaseUrl}/{WORKSPACE_CONTROLLER_NAME}";
HttpClient httpClient = new HttpClient();
HttpClient httpClient = new();
HttpContent putContent = ConvertJsonToHttpContent(inputJsonStr);
HttpResponseMessage responseMessage = await httpClient.PutAsync(workspaceRequestUrl, putContent).ConfigureAwait(false);
return await GetResponseContent(responseMessage);
Expand All @@ -534,7 +539,7 @@ public static async Task<string> ClearWorkspace()
try
{
string workspaceRequestUrl = $"{APIBaseUrl}/{WORKSPACE_CONTROLLER_NAME}";
HttpClient httpClient = new HttpClient();
HttpClient httpClient = new();
HttpResponseMessage responseMessage = await httpClient.DeleteAsync(workspaceRequestUrl).ConfigureAwait(false);
return await GetResponseContent(responseMessage);
}
Expand All @@ -553,10 +558,10 @@ public static async Task<ImageSource> TakeSnapshot()
try
{
string snapshotRequestUrl = $"{APIBaseUrl}/{SNAPSHOT_CONTROLLER_NAME}";
HttpClient httpClient = new HttpClient();
HttpClient httpClient = new();
HttpResponseMessage responseMessage = await httpClient.GetAsync(snapshotRequestUrl);
HttpContent content = responseMessage.Content;
BitmapImage bmpImg = new BitmapImage();
BitmapImage bmpImg = new();
using (Stream stream = await content.ReadAsStreamAsync().ConfigureAwait(false))
{
bmpImg.BeginInit();
Expand Down Expand Up @@ -655,9 +660,8 @@ public static async Task<HttpResponseMessage> PatchAsync(this HttpClient client,
{
Content = content
};

HttpResponseMessage response = new HttpResponseMessage();
response = await client.SendAsync(request);
_ = new HttpResponseMessage();
HttpResponseMessage response = await client.SendAsync(request);

return response;
}
Expand Down