Beispiel #1
0
        /// <inheritdoc />
        public async Task <IApiDocumentation> GetApiDocumentation(Uri url, CancellationToken cancellationToken)
        {
            var apiDocumentation = await GetApiDocumentationUrl(
                url ?? throw new ArgumentNullException(nameof(url), NoUrlProvided),
                cancellationToken);

            var options  = new HypermediaProcessingOptions(apiDocumentation.Response, url);
            var resource = await GetResourceFrom(apiDocumentation.Url, options, cancellationToken);

            var result = resource.OfType(hydra.ApiDocumentation).FirstOrDefault() as IApiDocumentation;

            if (result == null)
            {
                throw new NoEntrypointDefinedException();
            }

            return(result);
        }
Beispiel #2
0
        private async Task <IHypermediaContainer> GetResourceFrom(Uri url, IHypermediaProcessingOptions options, CancellationToken cancellationToken)
        {
            var response = await MakeRequestTo(
                url ?? throw new ArgumentNullException(nameof(url), NoUrlProvided),
                null,
                cancellationToken);

            if (response.Status != 200)
            {
                throw new InvalidResponseException(response.Status);
            }

            var hypermediaProcessor = GetHypermediaProcessor(response);

            if (hypermediaProcessor == null)
            {
                throw new ResponseFormatNotSupportedException();
            }

            options = new HypermediaProcessingOptions(url, LinksPolicy).MergeWith(options);
            return(await hypermediaProcessor.Process(response, this, options));
        }