public EncodedParameters Encode()
        {
            var result = new EncodedParameters(_options, AccessToken);

            result.TimeStamp = TimeStamp.ToEpochTime();

            if (Method != null)
            {
                Logger.LogDebug("Encoding method");
                result.Method = Method;
            }

            if (Host != null)
            {
                Logger.LogDebug("Encoding host");
                result.Host = Host;
            }

            if (Path != null)
            {
                Logger.LogDebug("Encoding path");
                result.Path = Path;
            }

            if (QueryParameters != null && QueryParameters.Any())
            {
                Logger.LogDebug("Encoding query params");
                var query = new EncodingQueryParameters(_options, QueryParameters);
                result.QueryParameters = query.Encode();
            }

            if (RequestHeaders != null && RequestHeaders.Any())
            {
                Logger.LogDebug("Encoding request headers");
                var headers = new EncodingHeaderList(_options, RequestHeaders);
                result.RequestHeaders = headers.Encode();
            }

            if (Body != null)
            {
                Logger.LogDebug("Encoding body");
                result.BodyHash = CalculateBodyHash();
            }

            return(result);
        }
Ejemplo n.º 2
0
        public bool IsSame(EncodedParameters other)
        {
            if (other == null)
            {
                return(false);
            }

            if (AccessToken != other.AccessToken)
            {
                Logger.LogDebug("AccessToken mismatch");
                return(false);
            }
            if (Method != other.Method)
            {
                Logger.LogDebug("Method mismatch");
                return(false);
            }
            if (Host != other.Host)
            {
                Logger.LogDebug("Host mismatch");
                return(false);
            }
            if (Path != other.Path)
            {
                Logger.LogDebug("Path mismatch");
                return(false);
            }
            if (BodyHash != other.BodyHash)
            {
                Logger.LogDebug("BodyHash mismatch");
                return(false);
            }

            if (QueryParameters == null && other.QueryParameters != null)
            {
                Logger.LogDebug("One QueryParameters is null, the other is not");
                return(false);
            }
            if (QueryParameters != null && other.QueryParameters == null)
            {
                Logger.LogDebug("One QueryParameters is null, the other is not");
                return(false);
            }
            if (QueryParameters != null && !QueryParameters.IsSame(other.QueryParameters))
            {
                Logger.LogDebug("QueryParameters mismatch");
                return(false);
            }

            if (RequestHeaders == null && other.RequestHeaders != null)
            {
                Logger.LogDebug("One RequestHeaders is null, the other is not");
                return(false);
            }
            if (RequestHeaders != null && other.RequestHeaders == null)
            {
                Logger.LogDebug("One RequestHeaders is null, the other is not");
                return(false);
            }
            if (RequestHeaders != null && !RequestHeaders.IsSame(other.RequestHeaders))
            {
                Logger.LogDebug("RequestHeaders mismatch");
                return(false);
            }

            return(true);
        }