initial commit
This commit is contained in:
70
Helper/APIHelper.cs
Normal file
70
Helper/APIHelper.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Microsoft.SelfService.Portal.Core.API.Helper
|
||||
{
|
||||
public class APIHelper
|
||||
{
|
||||
public static HttpClient ApiClient { get; set; } = new HttpClient();
|
||||
|
||||
public static String _Url;
|
||||
public static String _Body;
|
||||
|
||||
public APIHelper()
|
||||
{
|
||||
ApiClient = new HttpClient();
|
||||
ApiClient.BaseAddress = new Uri("http://rz1vcmsma001.cm.p01s01.ccis.svc.intranetbw.de:8080");
|
||||
ApiClient.DefaultRequestHeaders.Accept.Clear();
|
||||
ApiClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
|
||||
|
||||
ApiClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(
|
||||
Encoding.UTF8.GetBytes("CCIS-P01S01-CM\\ASA_Administrator:UQp7AurAkH4M")
|
||||
));
|
||||
}
|
||||
|
||||
public static void SetUrl(Guid RunbookId, String RestEndpointMethod)
|
||||
{
|
||||
_Url = string.Format("/00000000-0000-0000-0000-000000000000/Runbooks(guid'{0}')/{1}", RunbookId, RestEndpointMethod);
|
||||
}
|
||||
|
||||
public static string GetUrl()
|
||||
{
|
||||
return _Url;
|
||||
}
|
||||
|
||||
public static StringContent SetRequestHeaders(String ContentType)
|
||||
{
|
||||
MediaTypeHeaderValue JsonMediaType = null;
|
||||
MediaTypeHeaderValue.TryParse(ContentType, out JsonMediaType);
|
||||
|
||||
return new StringContent(_Body, Encoding.UTF8, JsonMediaType); ;
|
||||
}
|
||||
|
||||
public static void SetRequestBody(Guid parameters)
|
||||
{
|
||||
var obj = new
|
||||
{
|
||||
parameters = new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
__metadata = new
|
||||
{
|
||||
type = "Orchestrator.ResourceModel.NameValuePair"
|
||||
},
|
||||
Name = "deploymentId",
|
||||
Value = parameters
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
_Body = JsonSerializer.Serialize(obj);
|
||||
}
|
||||
|
||||
public static String GetRequestBody()
|
||||
{
|
||||
return _Body;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user