internal RequestHandler8( Method method, string path, ParameterResolver <T> resolverParam1, ParameterResolver <TR> resolverParam2, ParameterResolver <TU> resolverParam3, ParameterResolver <TI> resolverParam4, ParameterResolver <TJ> resolverParam5, ParameterResolver <TK> resolverParam6, ParameterResolver <TL> resolverParam7, ParameterResolver <TM> resolverParam8, IErrorHandler errorHandler, MediaTypeMapper mediaTypeMapper) : base(method, path, new List <IParameterResolver> { resolverParam1, resolverParam2, resolverParam3, resolverParam4, resolverParam5, resolverParam6, resolverParam7, resolverParam8 }, errorHandler, mediaTypeMapper) { ResolverParam1 = resolverParam1; ResolverParam2 = resolverParam2; ResolverParam3 = resolverParam3; ResolverParam4 = resolverParam4; ResolverParam5 = resolverParam5; ResolverParam6 = resolverParam6; ResolverParam7 = resolverParam7; ResolverParam8 = resolverParam8; }
public void GivenThatMediaTypeIsHardcover_WhenMapping_ThenReturnedMediaTypeIsHardcover() { var mapper = new MediaTypeMapper(); var mediaType = mapper.Map(MediaType.Hardcover, new UrlHelper()); Assert.AreEqual(AnApiOfIceAndFire.Models.v0.MediaType.Hardcover, mediaType); }
public void GivenThatMediaTypeIsGraphicNovel_WhenMapping_ThenReturnedMediaTypeIsGraphicNovel() { var mapper = new MediaTypeMapper(); var mediaType = mapper.Map(MediaType.GraphicNovel, new UrlHelper()); Assert.AreEqual(AnApiOfIceAndFire.Models.v1.MediaType.GraphicNovel, mediaType); }
public void GivenThatMediaTypeIsPaperback_WhenMapping_ThenReturnedMediaTypeIsPaperback() { var mapper = new MediaTypeMapper(); var mediaType = mapper.Map(MediaType.Paperback, new UrlHelper()); Assert.AreEqual(AnApiOfIceAndFire.Models.v1.MediaType.Paperback, mediaType); }
public static ParameterResolver <T> Body <T>(MediaTypeMapper mediaTypeMapper) => ParameterResolver <T> .Create( Type.Body, (request, mappedParameters) => { var assumedBodyContentType = ContentMediaType.Json.ToString(); var bodyMediaType = request.HeaderValueOr(RequestHeader.ContentType, assumedBodyContentType); return(mediaTypeMapper.From <T>(request.Body?.ToString(), ContentMediaType.ParseFromDescriptor(bodyMediaType))); });
internal static Response ToResponse( IObjectResponse objectResponse, Request request, MediaTypeMapper mediaTypeMapper, IErrorHandler errorHandler, ILogger logger) => Success.Of <Exception, Response>(objectResponse.ResponseFrom(request, mediaTypeMapper)) .Resolve( ex => ResourceErrorProcessor.ResourceHandlerError(errorHandler, logger, ex), response => response);
public static ParameterResolver <T> Body <T>(MediaTypeMapper mediaTypeMapper) { return(typeof(T).IsAssignableFrom(typeof(RequestData)) ? (ParameterResolver <T>)(object) ParameterResolver <RequestData> .Create(Type.Body, (request, mappedParameters) => { // This is a fall-back when content-type not provided for backwards compat for curl/cmd line users var bodyMediaType = BodyMediaTypeOrFallback(request); var contentEncodingHeader = request.Headers.HeaderOfOrDefault(ResponseHeader.ContentEncoding, RequestHeader.WithContentEncoding()); var contentEncoding = ContentEncoding.ParseFromHeader(contentEncodingHeader?.Value); return new RequestData(request.Body !, ContentMediaType.ParseFromDescriptor(bodyMediaType), contentEncoding); }) :
public RequestHandler2 <T, R> Body <R>(MediaTypeMapper mediaTypeMapper) { MediaTypeMapper = mediaTypeMapper; return(new RequestHandler2 <T, R>( Method, Path, Resolver, ParameterResolver.Body <R>(mediaTypeMapper), ErrorHandler, mediaTypeMapper)); }
public RequestHandler5 <T, TR, TU, TI, TJ> Body <TJ>(MediaTypeMapper mediaTypeMapper) => new RequestHandler5 <T, TR, TU, TI, TJ>( Method, Path, ResolverParam1, ResolverParam2, ResolverParam3, ResolverParam4, ParameterResolver.Body <TJ>(mediaTypeMapper), ErrorHandler, mediaTypeMapper);
public Response ResponseFrom(Request request, MediaTypeMapper mapper) { var acceptedMediaTypes = request.HeaderValueOr(RequestHeader.Accept, DefaultMediaType.ToString()); var responseMediaTypeSelector = new ResponseMediaTypeSelector(acceptedMediaTypes); var responseContentMediaType = responseMediaTypeSelector.SelectType(mapper.MappedMediaTypes); var bodyContent = mapper.From(_entity, responseContentMediaType); var body = Body.From(bodyContent); _headers.Add(ResponseHeader.Of(ResponseHeader.ContentType, responseContentMediaType.ToString())); return(Response.Of(_version, _status, _headers, body)); }
internal RequestHandler1( Method method, string path, ParameterResolver <T> resolver, IErrorHandler errorHandler, MediaTypeMapper mediaTypeMapper) : base(method, path, new List <IParameterResolver> { resolver }, errorHandler, mediaTypeMapper) { Resolver = resolver; }
public RequestHandler3 <T, TR, TU> Body <TU>(MediaTypeMapper mediaTypeMapper) { MediaTypeMapper = mediaTypeMapper; return(new RequestHandler3 <T, TR, TU>( Method, Path, ResolverParam1, ResolverParam2, ParameterResolver.Body <TU>(mediaTypeMapper), ErrorHandler, MediaTypeMapper)); }
internal RequestHandler2( Method method, string path, ParameterResolver <T> resolverParam1, ParameterResolver <TR> resolverParam2, IErrorHandler errorHandler, MediaTypeMapper mediaTypeMapper) : base(method, path, new List <IParameterResolver> { resolverParam1, resolverParam2 }, errorHandler, mediaTypeMapper) { ResolverParam1 = resolverParam1; ResolverParam2 = resolverParam2; }
internal RequestHandler( Method method, string path, IList <IParameterResolver> parameterResolvers, IErrorHandler errorHandler, MediaTypeMapper mediaTypeMapper) { Method = method; Path = path; ActionSignature = GenerateActionSignature(parameterResolvers); ContentSignature = DetectRequestBodyType(parameterResolvers).Map(p => p?.Name !).OrElse(null !); BodyType = DetectRequestBodyType(parameterResolvers).OrElse(null !); ErrorHandler = errorHandler; MediaTypeMapper = mediaTypeMapper; }
internal static ICompletes <Response> ExecuteRequest( Request request, MediaTypeMapper mediaTypeMapper, Func <ICompletes <IObjectResponse> > executeAction, IErrorHandler errorHandler, ILogger logger) { try { return(executeAction.Invoke() .AndThen(objectResponse => ToResponse(objectResponse, request, mediaTypeMapper, errorHandler, logger))); } catch (Exception ex) { return(Completes.WithFailure(ResourceErrorProcessor.ResourceHandlerError(errorHandler, logger, ex))); } }
internal RequestHandler5( Method method, string path, ParameterResolver <T> resolverParam1, ParameterResolver <TR> resolverParam2, ParameterResolver <TU> resolverParam3, ParameterResolver <TI> resolverParam4, ParameterResolver <TJ> resolverParam5, IErrorHandler errorHandler, MediaTypeMapper mediaTypeMapper) : base(method, path, new List <IParameterResolver> { resolverParam1, resolverParam2, resolverParam3, resolverParam4, resolverParam5 }, errorHandler, mediaTypeMapper) { ResolverParam1 = resolverParam1; ResolverParam2 = resolverParam2; ResolverParam3 = resolverParam3; ResolverParam4 = resolverParam4; ResolverParam5 = resolverParam5; }
public RequestHandler0 Mapper(MediaTypeMapper mediaTypeMapper) { MediaTypeMapper = mediaTypeMapper; return(this); }