Exemplo n.º 1
0
        internal static byte[] MakeRequest(this BaseRequest request, BaseWhitesourceService service)
        {
            var client     = new RestClient(service.ApiUrl);
            var webRequest = new RestRequest(Method.POST);

            webRequest.AddHeader("cache-control", "no-cache");
            webRequest.AddHeader("Content-Type", "application/json");
            webRequest.AddParameter("application/json", request.ToJson(), ParameterType.RequestBody);
            var response = client.DownloadData(webRequest);

            return(response);
        }
Exemplo n.º 2
0
        internal static IRestResponse <T> MakeRequest <T>(this BaseRequest request, BaseWhitesourceService service) where T : BaseResponse, new()
        {
            var client     = new RestClient(service.ApiUrl);
            var webRequest = new RestRequest(Method.POST);

            webRequest.AddHeader("cache-control", "no-cache");
            webRequest.AddHeader("Content-Type", "application/json");
            webRequest.AddParameter("application/json", request.ToJson(), ParameterType.RequestBody);
            var response = client.Execute <T>(webRequest, Method.POST);

            if (response.Data.IsSuccessful)
            {
                return(response);
            }
            throw new WhitesourceRequestException(response.Data);
        }
Exemplo n.º 3
0
        internal static async Task <byte[]> MakeRequestAsync(this BaseRequest request, BaseWhitesourceService service)
        {
            var client     = new RestClient(service.ApiUrl);
            var webRequest = new RestRequest(Method.POST);

            webRequest.AddHeader("cache-control", "no-cache");
            webRequest.AddHeader("Content-Type", "application/json");
            webRequest.AddParameter("application/json", request.ToJson(), ParameterType.RequestBody);
            var response = await client.ExecuteTaskAsync(webRequest);

            var contentType = response.ContentType.ToLower().Split(';').FirstOrDefault();

            switch (contentType)
            {
            case "application/json":
                var jsonContent = JsonConvert.DeserializeObject <BaseResponse>(response.Content);
                throw new WhitesourceRequestException(jsonContent);

            case "application/zip":
                return(response.RawBytes);

            default:
                throw new WhitesourceRequestException($"Unexpected content type: {contentType}");
            }
        }