This commit is contained in:
@@ -122,19 +122,18 @@ namespace AyaNova.PlugIn.V8
|
||||
|
||||
|
||||
|
||||
public async static Task<ApiResponse> GetAsync(string route, string authToken = null, string bodyJsonData = null)
|
||||
public async static Task<ApiResponse> GetAsync(string route)
|
||||
{
|
||||
|
||||
|
||||
var requestMessage = new HttpRequestMessage(HttpMethod.Get, route);
|
||||
if (!string.IsNullOrWhiteSpace(JWT))
|
||||
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", JWT);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(bodyJsonData))
|
||||
requestMessage.Content = new StringContent(bodyJsonData, System.Text.Encoding.UTF8, "application/json");
|
||||
|
||||
HttpResponseMessage response = await client.SendAsync(requestMessage);
|
||||
var responseAsString = await response.Content.ReadAsStringAsync();
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
throw new Exception("GET error, route: " + route + "\n" + responseAsString + "\n" + response.ReasonPhrase);
|
||||
}
|
||||
|
||||
return new ApiResponse() { HttpResponse = response, ObjectResponse = Parse(responseAsString) };
|
||||
}
|
||||
@@ -159,6 +158,27 @@ namespace AyaNova.PlugIn.V8
|
||||
return new ApiResponse() { HttpResponse = response, ObjectResponse = Parse(responseAsString) };
|
||||
}
|
||||
|
||||
public async static Task<ApiResponse> PutAsync(string route, string putJson = null)
|
||||
{
|
||||
|
||||
|
||||
var requestMessage = new HttpRequestMessage(HttpMethod.Put, route);
|
||||
if (!string.IsNullOrWhiteSpace(JWT))
|
||||
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", JWT);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(putJson))
|
||||
requestMessage.Content = new StringContent(putJson, System.Text.Encoding.UTF8, "application/json");
|
||||
|
||||
HttpResponseMessage response = await client.SendAsync(requestMessage);
|
||||
var responseAsString = await response.Content.ReadAsStringAsync();
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
throw new Exception("PUT error, route: " + route + "\n" + responseAsString + "\n" + response.ReasonPhrase);
|
||||
}
|
||||
|
||||
return new ApiResponse() { HttpResponse = response, ObjectResponse = Parse(responseAsString) };
|
||||
}
|
||||
|
||||
|
||||
//eoc
|
||||
public class ApiResponse
|
||||
@@ -186,6 +206,17 @@ namespace AyaNova.PlugIn.V8
|
||||
}
|
||||
return JObject.Parse(jsonString);
|
||||
}
|
||||
|
||||
|
||||
public static long IdFromResponse(ApiResponse a)
|
||||
{
|
||||
return a.ObjectResponse["data"]["id"].Value<long>();
|
||||
}
|
||||
|
||||
public static uint CTokenFromResponse(ApiResponse a)
|
||||
{
|
||||
return a.ObjectResponse["data"]["concurrencyToken"].Value<uint>();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Misc utils
|
||||
@@ -228,7 +259,7 @@ namespace AyaNova.PlugIn.V8
|
||||
if (s.Length > maxLength)
|
||||
s = s.Substring(0, maxLength);
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
Reference in New Issue
Block a user