42 lines
1.5 KiB
C#
42 lines
1.5 KiB
C#
using System;
|
|
using System.Net;
|
|
using Kreta.Client.ClientBase.Interface;
|
|
using RestSharp;
|
|
|
|
namespace Kreta.Client.ClientBase
|
|
{
|
|
internal class RestResult : IRestResult
|
|
{
|
|
public string Result { get; set; }
|
|
public HttpStatusCode StatusCode { get; set; }
|
|
public string StatusDescription { get; set; }
|
|
public Exception Exception { get; set; }
|
|
public string ErrorMessage { get; set; }
|
|
public byte[] RawBytes { get; set; }
|
|
|
|
public static IRestResult Convert(IRestResponse restResponse) => new RestResult
|
|
{
|
|
Result = restResponse.Content,
|
|
StatusCode = restResponse.StatusCode,
|
|
StatusDescription = restResponse.StatusDescription,
|
|
Exception = restResponse.ErrorException,
|
|
ErrorMessage = restResponse.ErrorMessage,
|
|
RawBytes = restResponse.RawBytes
|
|
};
|
|
}
|
|
|
|
internal class RestResult<TResponse> : RestResult, IRestResult<TResponse>
|
|
{
|
|
public TResponse Result { get; set; }
|
|
|
|
public static IRestResult<TResponse> Convert(IRestResponse<TResponse> restResponse) => new RestResult<TResponse>
|
|
{
|
|
Result = restResponse.Data,
|
|
StatusCode = restResponse.StatusCode,
|
|
StatusDescription = restResponse.StatusDescription,
|
|
Exception = restResponse.ErrorException,
|
|
ErrorMessage = restResponse.ErrorMessage,
|
|
RawBytes = restResponse.RawBytes
|
|
};
|
|
}
|
|
}
|