RestSharp Сериализация / десериализация преобразования имен
Я пытаюсь обернуть Plivo API (да, я знаю, что это было сделано) используя RestSharp.
Однако я не могу найти метод для перевода соглашений об именах API в мои собственные, например:
A "Call` (https://www.plivo.com/docs/api/call/#make-an-outbound-call) требует минимум:
to
, from
, а такжеanswer_url
параметры должны быть предоставлены.
Эти параметры также чувствительны к регистру.
Я хотел бы иметь возможность предоставить класс CallRequest, упаковав данные, требуемые в моих предпочтительных соглашениях об именах, и затем каким-то образом перевести их перед сериализацией RestSharp.
Пример:
public class CallRequest
{
/// <summary>
/// The phone number to be used as the caller id (with the country code).For e.g, a USA caller id number could be, 15677654321, with '1' for the country code.
/// </summary>
public string From { get; set; }
/// <summary>
/// The regular number(s) or sip endpoint(s) to call. Regular number must be prefixed with country code but without the + sign). For e.g, to dial a number in the USA, the number could be, 15677654321, with '1' for the country code. Multiple numbers can be sent by using a delimiter. For e.g. 15677654321<12077657621<12047657621. Sip endpoints must be prefixed with sip: E.g., sip:[email protected]. To make bulk calls, the delimiter < is used. For eg. 15677654321<15673464321<sip:[email protected] Yes, you can mix regular numbers and sip endpoints.
/// </summary>
public string To { get; set; }
/// <summary>
/// The URL invoked by Plivo when the outbound call is answered.
/// </summary>
public string AnswerUrl { get; set; }
}
Эти данные затем будут переведены в соглашение Пливо в следующих функциях:
private T Execute<T>(IRestRequest request) where T : new()
{
var client = new RestClient
{
BaseUrl = new Uri(BaseUrl),
Authenticator = new HttpBasicAuthenticator(_accountId, _authToken),
UserAgent = "PlivoSharp"
};
request.AddHeader("Content-Type", "application/json");
request.AddParameter("auth_id", _accountId, ParameterType.UrlSegment);
request.RequestFormat = DataFormat.Json;
client.AddHandler("application/json", new JsonDeserializer());
var response = client.Execute<T>(request);
if (response.ErrorException == null) return response.Data;
const string message = "Error retrieving response. Check inner details for more info.";
var plivoException = new ApplicationException(message, response.ErrorException);
throw plivoException;
}
public CallResponse MakeCall(CallRequest callRequest)
{
var request = new RestRequest
{
RequestFormat = DataFormat.Json,
Resource = "Account/{auth_id}/Call/",
Method = Method.POST
};
//SOMEHOW TRANSLATE THE PROPERTIES INTO THE DATA BELOW
request.AddBody(new
{
to = "17#####",
from = "18#####",
answer_url = "http://m------.xml"
});
return Execute<CallResponse>(request);
}