Пример #1
0
        public object TransformHtml()
        {
            var queryString = Request.GetQueryNameValuePairs();
            var urlQuery    = queryString.Where(a => a.Key.Equals("url"));

            if (!urlQuery.Any())
            {
                return(BadRequest("Request parameter 'url' was missing"));
            }
            var url = urlQuery.First().Value;

            Logger.Info($"Recieved request with querystring url: {url}");

            var requestContent = Request.Content;
            var html           = requestContent.ReadAsStringAsync().Result;

            if (string.IsNullOrWhiteSpace(html))
            {
                return(BadRequest("Request body was empty"));
            }

            Logger.Info($"Recieved request with html: {html}");

            var extractor = new MultiExtractor(Settings.Default.TransformationsDirectory, "*.txt");

            var matchingExtractors = extractor.FindAllExtractors(url);

            if (!matchingExtractors.Any())
            {
                Logger.Info($"No extractors matched for url {url}");
                return(BadRequest($"Could not find any extractors configured that match url: {url}"));
            }

            return(extractor.ExtractAll(url, html));
        }