public ClientResponse Execute(Credentials LibertyApiAuth) { try { if (Client == null) { throw new Exception("Execute command requires a client object, which was not supplied"); } AddClientClass addClient = new AddClientClass(); addClient.Client = Client; LibertyApiAuth.GetCallTime(); var client = new RestClient("http://" + LibertyApiAuth.ServerName + ":" + LibertyApiAuth.ListenPortNumber + "/data/basicclient"); var request = new RestRequest(Method.POST); client.CookieContainer = LibertyApiAuth.Cookie; request.AddHeader("x-call-time", LibertyApiAuth.CallTime.ToString()); request.AddHeader("x-application-id", LibertyApiAuth.ApplicationID); request.AddHeader("x-api-version", LibertyApiAuth.ApiVersion); request.AddHeader("x-auth-string", LibertyApiAuth.AuthString()); request.AddParameter("application/json", addClient.ToJson(), ParameterType.RequestBody); IRestResponse response = client.Execute(request); if (response.StatusCode == HttpStatusCode.BadRequest) { throw new LibertyException(response.Content); } else { ClientResponse GetClientResponse = ClientResponse.FromJson(response.Content); return(GetClientResponse); } } catch (Exception ee) { throw ee; } }
public static string ToJson(this AddClientClass self) => JsonConvert.SerializeObject(self, Converter.Settings);