Exemplo n.º 1
0
        public HttpRequestMessage Encode(ApiRequest request)
        {
            var message = new HttpRequestMessage();

            switch (EncodingType)
            {
            case HttpRequestEncodingType.Get:
                message.Method     = HttpMethod.Get;
                message.RequestUri = new Uri($"{request.Endpoint}?{GetQueryString(request)}", UriKind.Relative);
                return(message);

            case HttpRequestEncodingType.PostWithQueryString:
                message.Method     = HttpMethod.Post;
                message.RequestUri = new Uri($"{request.Endpoint}?{GetQueryString(request)}", UriKind.Relative);
                return(message);

            case HttpRequestEncodingType.PostWithXml:
                message.Method     = HttpMethod.Post;
                message.RequestUri = request.Endpoint;
                message.Content    = new FormUrlEncodedContent(
                    new[] { new KeyValuePair <string, string>("pg_xml", _xmlPipeline.Serialize(request)) });
                return(message);

            default:
                throw new ArgumentOutOfRangeException(nameof(EncodingType), EncodingType, "Encoding not implemented");
            }
        }
        public CallbackResponse EncodeResponse(ApiCallbackResponse response)
        {
            _authenticator.Apply(response);
            var content = _xmlPipeline.Serialize(response);

            return(new CallbackResponse {
                Content = content
            });
        }