using CryptoExchange.Net.Interfaces;
using System.Collections.Generic;
using System.Net.Http;
namespace CryptoExchange.Net.Objects
{
///
/// Rest request configuration
///
public class RestRequestConfiguration
{
private string? _bodyContent;
private string? _queryString;
///
/// The request definition for the request
///
public RequestDefinition RequestDefinition { get; set; }
///
/// Query parameters
///
public Parameters? QueryParameters { get; set; }
///
/// Body parameters
///
public Parameters? BodyParameters { get; set; }
///
/// Request headers
///
public IDictionary? Headers { get; set; }
///
/// Array serialization type
///
public ArrayParametersSerialization ArraySerialization { get; set; }
///
/// Position of the parameters
///
public HttpMethodParameterPosition ParameterPosition { get; set; }
///
/// Body format
///
public RequestBodyFormat BodyFormat { get; set; }
///
/// ctor
///
public RestRequestConfiguration(
RequestDefinition requestDefinition,
Parameters? queryParams,
Parameters? bodyParams,
IDictionary? headers,
HttpMethodParameterPosition parametersPosition,
RequestBodyFormat bodyFormat)
{
RequestDefinition = requestDefinition;
QueryParameters = queryParams;
BodyParameters = bodyParams;
Headers = headers;
ParameterPosition = parametersPosition;
BodyFormat = bodyFormat;
}
///
/// Get the parameter collection based on the ParameterPosition
///
public Parameters GetPositionParameters()
{
if (ParameterPosition == HttpMethodParameterPosition.InBody)
{
BodyParameters ??= new Parameters(ParameterSerializationSettings.Default);
return BodyParameters;
}
QueryParameters ??= new Parameters(ParameterSerializationSettings.Default);
return QueryParameters;
}
///
/// Get the query string. If it's not previously set it will return a newly formatted query string. If previously set return that.
///
/// Whether to URL encode the parameter string if creating new
public string GetQueryString(bool urlEncode = true)
{
return _queryString ?? QueryParameters?.CreateParamString(urlEncode, ArraySerialization) ?? string.Empty;
}
///
/// Set the query string of the request. Will be returned by subsequent calls
///
public void SetQueryString(string value)
{
_queryString = value;
}
///
/// Get the body content if it's previously set
///
public string? GetBodyContent()
{
return _bodyContent;
}
///
/// Set the body content for the request
///
public void SetBodyContent(string content)
{
_bodyContent = content;
}
}
}