protected IRestRequest BuildRequest <TResult>(string url, Method method) { var request = RestFactory.CreateRequest(url, method); SetupAuthorization(request); return(request); }
private void AddCategoryToProduct(int productId) { var request = RestFactory.CreateRequest(UrlProvider.AddCategory(productId, (int)Product.Category)); request.WithAuthorization(User.Token); request.Put(); }
/// <summary> /// Maps an given uri looking for @odata.id links. /// </summary> /// <param name="uri">Uri to map.</param> /// <returns></returns> private async Task MapUri(string uri) { IRequest request = RestFactory.CreateRequest(); request.Resource = uri; request.Method = Method.GET; client.Authenticate(authenticator, request); IResponse response = await client.ExecuteAsync(request); urisFollowed.Add(uri); JObject json = JObject.Parse(response.JsonContent); /* * During tests, we saw that not every resource has Id and @odata.id * for that reason we check for null before add to the Resources Dictionary * */ string jsonId = json["Id"] == null ? string.Empty : json["Id"].ToString(); string odataId = json["@odata.id"] == null ? string.Empty : json["@odata.id"].ToString(); if (!Resources.Keys.Contains(jsonId) && !String.IsNullOrEmpty(jsonId) && !String.IsNullOrEmpty(odataId)) { Resources.Add(jsonId, odataId); } foreach (JProperty item in json.Children()) { GetLinks(item); } }
public async Task <IResponse> CreateVolumeAsync(string pushUri, IEnumerable <string> drives, Enums.VolumeType type, long capacity, long ioSize, string name) { IRequest request = RestFactory.CreateRequest(); request.Resource = pushUri; request.Method = Method.POST; request.Format = DataFormat.Json; List <IDictionary <string, string> > volumeDrives = new List <IDictionary <string, string> >(); foreach (string drive in drives) { IDictionary <string, string> item = new Dictionary <string, string>(); item.Add("@odata.id", drive); volumeDrives.Add(item); } request.BodyParameters.Add("Drives", volumeDrives); request.BodyParameters.Add("VolumeType", type.ToString()); request.BodyParameters.Add("CapacityBytes", capacity); request.BodyParameters.Add("OptimumIOSizeBytes", ioSize); request.BodyParameters.Add("Name", name); client.Authenticate(authenticator, request); return(await client.ExecuteAsync(request)); }
//[RuleInterceptor] public virtual async Task <Log> ExecuteAsync() { //ignore SSL errors ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true; IRestClient client = RestFactory.CreateClient(Url); IRestRequest request = RestFactory.CreateRequest(Method); IRestResponse response = await client.ExecuteTaskAsync(request); if ((int)response.StatusCode == Code) { return(LogRepository.CreateLog(StatusEnum.Success)); } else { var log = LogRepository.CreateLog(StatusEnum.Failure); log.Message = FailureDescription(); log.FullData = $"Actual HTTP code: {(int)response.StatusCode} {response.StatusCode}. Expected: {Code}."; return(log); } }
public async Task <IResponse> SecureEraseAsync(string target) { IRequest request = RestFactory.CreateRequest(); request.Resource = target; request.Method = Method.POST; client.Authenticate(authenticator, request); return(await client.ExecuteAsync(request)); }
public async Task <IResponse> InitializeAsync(string target) { IRequest request = RestFactory.CreateRequest(); request.Resource = target; request.Method = Method.POST; request.Format = DataFormat.Json; client.Authenticate(authenticator, request); return(await client.ExecuteAsync(request)); }
/// <summary> /// Performs a DTMF software update /// </summary> /// <param name="image">The URI of the software image to be installed</param> /// <returns>Rest response of the update request</returns> public async Task <IResponse> SimpleUpdateAsync(string image) { IRequest request = RestFactory.CreateRequest(); request.Resource = await GetUpdateServiceUriAsync(); request.Method = Method.POST; request.BodyParameters.Add("ImageURI", image); client.Authenticate(authenticator, request); return(await client.ExecuteAsync(request)); }
public override void Execute() { var request = RestFactory.CreateRequest(UrlProvider.Product); var response = request.Get <IEnumerable <Product> >().Content; var product = response.FirstOrDefault(x => x.Title.Equals(Product.Title)); product.Should().NotBeNull("product was not found"); Driver.Open(UrlProvider.EditProduct(product.Id)); }
protected IRestRequest BuildRequest <TResult, TModel>(TModel model, string url, Method method) { var request = RestFactory.CreateRequest(url, method); if (model != null) { request = request.AddJsonBody(model); } SetupAuthorization(request); return(request); }
public void CreateRequestTest() { var factory = new RestFactory( new Mock <IBambooOptions>().Object, new Mock <IRestSerializer>().Object); var request = factory.CreateRequest("TestResource", Method.PUT); request.ShouldNotBeNull(); request.Resource.ShouldBe("TestResource"); request.Method.ShouldBe(Method.PUT); }
public async Task <IResponse> SetEncryptionKeyAsync(string target, string key) { IRequest request = RestFactory.CreateRequest(); request.Resource = target; request.Method = Method.POST; request.Format = DataFormat.Json; request.BodyParameters.Add("EncryptionKey", key); client.Authenticate(authenticator, request); return(await client.ExecuteAsync(request)); }
/// <summary> /// Performs a DTMF software update /// </summary> /// <param name="image">The URI of the software image to be installed</param> /// <param name="targets">The array of URIs indicating where the update image is to be applied</param> /// <param name="protocol">The network protocol used by the Update Service</param> /// <returns>Rest response of the update request</returns> public async Task <IResponse> SimpleUpdateAsync(string image, IEnumerable <string> targets, Enums.TransferProtocol protocol) { IRequest request = RestFactory.CreateRequest(); request.Resource = await GetUpdateServiceUriAsync(); request.Method = Method.POST; request.BodyParameters.Add("ImageURI", image); request.BodyParameters.Add("Targets", targets); request.BodyParameters.Add("TransferProtocol", protocol); client.Authenticate(authenticator, request); return(await client.ExecuteAsync(request)); }
/// <summary> /// Save to an local file an Scp File previously exported /// </summary> /// <param name="path">Local to save the file</param> /// <param name="location">Path to the export Job</param> /// <returns></returns> public async Task SaveLocalScpFileAsync(string path, string location) { IRequest request = RestFactory.CreateRequest(); request.Resource = location; request.Method = Method.GET; request.Format = DataFormat.Json; client.Authenticate(authenticator, request); IResponse response = await client.ExecuteAsync(request); File.WriteAllText(path, response.JsonContent); }
/// <summary> /// Upload an file to an given uri /// </summary> /// <param name="path">Local path of the file</param> /// <returns>Rest response of the upload</returns> public async Task <IResponse> UploadFileAsync(string path) { IRequest request = RestFactory.CreateRequest(); request.Resource = await GetUpdateServiceUriAsync(); request.Method = Method.POST; FileParameter file = new FileParameter(path, Path.GetFileName(path), "multipart/form-data"); request.AddFile(file); client.Authenticate(authenticator, request); return(await client.ExecuteAsync(request)); }
private async Task AuditAsync(AuditDetail data) { var client = RestFactory.CreateClient(BaseUrl); var request = RestFactory.CreateRequest("api/InssAuditMessaging", RestSharp.Method.POST); request = request.AddJsonBody(data); var response = await client.ExecuteAsync(request); if (!response.IsSuccessful) { Logger.LogWarning($"Auditing Failed: {response.StatusCode}"); } }
/// <summary> /// Exports an Scp File to a local file. /// </summary> /// <param name="format">File format</param> /// <param name="target">Items to add in the file</param> /// <returns>Rest response of export</returns> public async Task <IResponse> ExportLocalScpFileAsync(string format, string target) { IRequest request = RestFactory.CreateRequest(); request.Resource = exportUri; request.Method = Method.POST; request.Format = DataFormat.Json; request.BodyParameters.Add("ExportFormat", format); request.BodyParameters.Add("SharedParameters", new { Target = target }); client.Authenticate(authenticator, request); return(await client.ExecuteAsync(request)); }
protected IRestRequest BuildRequestDict(string url, params KeyValuePair <string, object>[] values) { var queryParams = HttpUtility.ParseQueryString(""); values .Where(x => x.Value != null) .ToList() .ForEach(x => queryParams.Add(x.Key, x.Value.ToString())); var uri = $"{url}?{queryParams}"; var request = RestFactory.CreateRequest(uri, Method.GET); SetupAuthorization(request); return(request); }
private User GetAuthenticatedUser() { var loginDto = new LoginDto { Email = User.Email, Password = User.Password }; var request = RestFactory.CreateRequest(UrlProvider.Authentication); request.AddJsonBody(loginDto); var response = request.Post <User>(); return(response.Content); }
protected virtual TokenResponse GetToken(AuthorityDetails authDetails) { var client = RestFactory.CreateClient(authDetails.ClientUrl); var request = RestFactory.CreateRequest("token", Method.POST); request.AddHeader("Content-Type", "application/x-www-form-urlencoded"); request.AddHeader("Accept", "application/json"); request.AddParameter("grant_type", "client_credentials"); request.AddParameter("resource", authDetails.ResourceUrl); if (!string.IsNullOrEmpty(authDetails.Scope)) { request.AddParameter(JwtClaimTypes.Scope, authDetails.Scope); } client.Authenticator = new HttpBasicAuthenticator(authDetails.ClientId, authDetails.ClientSecret); var response = client.Execute <TokenResponse>(request); return(response?.Data); }
private int GetProductIdFromCreateProduct() { var productDto = new CreateProductDto { Title = Product.Title, Price = Product.Price, ImageUrl = Product.ImageUrl }; var request = RestFactory.CreateRequest(UrlProvider.Product); request.AddJsonBody(productDto); request.WithAuthorization(User.Token); var responseContent = request.Post <dynamic>().Content; return((int)responseContent.id); }
/// <summary> /// Imports an Scp configuration from a local file. /// </summary> /// <param name="path">File path</param> /// <param name="target">Items who will be imported in the file</param> /// <param name="shutdownType">Shutdown method to apply the configurations</param> /// <param name="powerState">Server current power state.</param> /// <returns>Rest response of import</returns> public async Task <IResponse> ImportLocalScpFileAsync(string path, string target, string shutdownType, string powerState) { IRequest request = RestFactory.CreateRequest(); request.Resource = importUri; request.Method = Method.POST; request.Format = DataFormat.Json; string fileData = File.ReadAllText(path); request.BodyParameters.Add("ImportBuffer", fileData); request.BodyParameters.Add("SharedParameters", new { Target = target }); request.BodyParameters.Add("ShutdownType", shutdownType); request.BodyParameters.Add("HostPowerState", powerState); client.Authenticate(authenticator, request); return(await client.ExecuteAsync(request)); }
/// <summary> /// Upload an file to an given uri /// </summary> /// <param name="path">Local path of the file</param> /// <param name="headers">Custom headers for the upload request</param> /// <returns>Rest response of the update</returns> public async Task <IResponse> UploadFileAsync(string path, IDictionary <string, IList <string> > headers) { IRequest request = RestFactory.CreateRequest(); request.Resource = await GetUpdateServiceUriAsync(); request.Method = Method.POST; FileParameter file = new FileParameter(path, Path.GetFileName(path), "multipart/form-data"); request.AddFile(file); foreach (var header in headers) { request.Headers.Add(header); } client.Authenticate(authenticator, request); return(await client.ExecuteAsync(request)); }