HTTPWrapper 24
HTTPWrapper 24
(sin asunto)
Enric Jimenez <[email protected]> 24 de octubre de 2024, 8:18
Borrador
using System;
using System.Globalization;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using HappyTren.Train.IryoConnector.IryoObjects;
using HappyTren.Train.IryoConnector.Internals.Model.Response;
using HappyTren.Train.IryoConnector.Internals.Model.Request;
using HappyTren.Train.IryoConnector.Internals.Model.Entitys;
using HappyTren.Train.IryoConnector.Internals.Helpers;
using HappyTren.Train.IryoConnector.Internals.Builders.CustomCache.Actions;
namespace HappyTren.Train.IryoConnector.Internals.Connector.HTTPWrapper
{
public class HttpWrapper
{
private static readonly HttpClient _client = new HttpClient
{
Timeout = TimeSpan.FromMinutes(5) // Configuro un timeout de 5 minutos
};
if (response.IsSuccessStatusCode)
{
var resp = SerializeExtension.DeserializeJson<JourneySearchRS>(strResponse);
return resp;
}
else
{
throw new Exception($"Error HTTP - Code: {response.StatusCode}, Message: {strResponse}");
}
}
}
catch (Exception ex)
{
https://mail.google.com/mail/u/0/?ik=008608e040&view=pt&search=drafts&permmsgid=msg-a:r-2855211054788120985&dsqt=1&simpl=%23ms… 1/13
24/10/24, 8:18 Correo de EMOVEERE CONSULTING - (sin asunto)
throw new Exception($"Error in SearchAsync: {ex.Message}", ex);
}
}
if (response.IsSuccessStatusCode)
{
var resp = SerializeExtension.DeserializeJson<CreateBookingRS>(strResponse);
return resp;
}
else
{
throw new Exception($"Error HTTP - Code: {response.StatusCode}, Message: {strResponse}");
}
}
}
catch (Exception ex)
{
throw new Exception($"Error in CreateBookingAsync: {ex.Message}", ex);
}
}
if (response.IsSuccessStatusCode)
{
var resp = SerializeExtension.DeserializeJson<SearchBookingsRS>(strResponse);
return resp;
https://mail.google.com/mail/u/0/?ik=008608e040&view=pt&search=drafts&permmsgid=msg-a:r-2855211054788120985&dsqt=1&simpl=%23ms… 2/13
24/10/24, 8:18 Correo de EMOVEERE CONSULTING - (sin asunto)
}
else
{
throw new Exception($"Error HTTP - Code: {response.StatusCode}, Message: {strResponse}");
}
}
}
catch (Exception ex)
{
throw new Exception($"Error in SearchBookingsAsync: {ex.Message}", ex);
}
}
if (response.IsSuccessStatusCode)
{
var resp = SerializeExtension.DeserializeJson<ConfirmBookingRS>(strResponse);
return resp;
}
else
{
throw new Exception($"Error HTTP - Code: {response.StatusCode}, Message: {strResponse}");
}
}
}
catch (Exception ex)
{
throw new Exception($"Error in ConfirmBookingAsync: {ex.Message}", ex);
}
}
https://mail.google.com/mail/u/0/?ik=008608e040&view=pt&search=drafts&permmsgid=msg-a:r-2855211054788120985&dsqt=1&simpl=%23ms… 3/13
24/10/24, 8:18 Correo de EMOVEERE CONSULTING - (sin asunto)
var strResponse = await response.Content.ReadAsStringAsync();
LogHelper.LogMessageToFile(LogHelper.MsgResponse, "UpdatePassenger", "", strResponse);
if (response.IsSuccessStatusCode)
{
var resp = SerializeExtension.DeserializeJson<UpdatePassengerRS>(strResponse);
result = resp;
}
else
{
throw new Exception($"Error HTTP - Code: {response.StatusCode}, Message: {strResponse}");
}
}
}
return result;
}
catch (Exception ex)
{
throw new Exception($"Error in UpdatePassengerAsync: {ex.Message}", ex);
}
}
if (response.IsSuccessStatusCode)
{
var resp = SerializeExtension.DeserializeJson<ProcessPaymentRS>(strResponse);
return resp;
}
else
{
throw new Exception($"Error HTTP - Code: {response.StatusCode}, Message: {strResponse}");
}
}
}
catch (Exception ex)
{
throw new Exception($"Error in ProcessPaymentAsync: {ex.Message}", ex);
}
}
https://mail.google.com/mail/u/0/?ik=008608e040&view=pt&search=drafts&permmsgid=msg-a:r-2855211054788120985&dsqt=1&simpl=%23ms… 4/13
24/10/24, 8:18 Correo de EMOVEERE CONSULTING - (sin asunto)
if (response.IsSuccessStatusCode)
{
var resp = SerializeExtension.DeserializeJson<RetrieveBookingRS>(strResponse);
return resp;
}
else
{
throw new Exception($"Error HTTP - Code: {response.StatusCode}, Message: {strResponse}");
}
}
}
catch (Exception ex)
{
throw new Exception($"Error in RetrieveBookingAsync: {ex.Message}", ex);
}
}
if (response.IsSuccessStatusCode)
{
var resp = SerializeExtension.DeserializeJson<CancelBookingRS>(strResponse);
return resp;
}
else
{
throw new Exception($"Error HTTP - Code: {response.StatusCode}, Message: {strResponse}");
}
}
}
catch (Exception ex)
{
throw new Exception($"Error in CancelBookingAsync: {ex.Message}", ex);
}
https://mail.google.com/mail/u/0/?ik=008608e040&view=pt&search=drafts&permmsgid=msg-a:r-2855211054788120985&dsqt=1&simpl=%23ms… 5/13
24/10/24, 8:18 Correo de EMOVEERE CONSULTING - (sin asunto)
}
if (response.IsSuccessStatusCode)
{
var methodsArray = SerializeExtension.DeserializeJson<RefundMethod[]>(strResponse);
var resp = new RefundMethodsRS { RefundMethods = methodsArray };
return resp;
}
else
{
throw new Exception($"Error HTTP - Code: {response.StatusCode}, Message: {strResponse}");
}
}
}
catch (Exception ex)
{
throw new Exception($"Error in RefundMethodsAsync: {ex.Message}", ex);
}
}
https://mail.google.com/mail/u/0/?ik=008608e040&view=pt&search=drafts&permmsgid=msg-a:r-2855211054788120985&dsqt=1&simpl=%23ms… 6/13
24/10/24, 8:18 Correo de EMOVEERE CONSULTING - (sin asunto)
}
}
public async Task<List<Products>> GetProductsAsync()
{
try
{
ConfigureHeaders();
_client.DefaultRequestHeaders.TryAddWithoutValidation("Accept-Language", "es-ES");
https://mail.google.com/mail/u/0/?ik=008608e040&view=pt&search=drafts&permmsgid=msg-a:r-2855211054788120985&dsqt=1&simpl=%23ms… 7/13
24/10/24, 8:18 Correo de EMOVEERE CONSULTING - (sin asunto)
// Configurar los encabezados de la solicitud, agregando lo necesario para autenticación
ConfigureHeaders();
_client.DefaultRequestHeaders.TryAddWithoutValidation("Accept-Language", "es-ES");
https://mail.google.com/mail/u/0/?ik=008608e040&view=pt&search=drafts&permmsgid=msg-a:r-2855211054788120985&dsqt=1&simpl=%23ms… 8/13
24/10/24, 8:18 Correo de EMOVEERE CONSULTING - (sin asunto)
https://mail.google.com/mail/u/0/?ik=008608e040&view=pt&search=drafts&permmsgid=msg-a:r-2855211054788120985&dsqt=1&simpl=%23ms… 9/13
24/10/24, 8:18 Correo de EMOVEERE CONSULTING - (sin asunto)
return resp;
}
else
{
throw new Exception($"Error HTTP - Code: {response.StatusCode}, Message: {await
response.Content.ReadAsStringAsync()}");
}
}
}
catch (Exception ex)
{
throw new Exception($"Error in GetAuthorisationTokenAsync: {ex.Message}", ex);
}
}
https://mail.google.com/mail/u/0/?ik=008608e040&view=pt&search=drafts&permmsgid=msg-a:r-2855211054788120985&dsqt=1&simpl=%23m… 10/13
24/10/24, 8:18 Correo de EMOVEERE CONSULTING - (sin asunto)
Content = new StringContent(strContent, Encoding.UTF8, "application/json"),
};
if (response.IsSuccessStatusCode)
{
var resp = SerializeExtension.DeserializeJson<VoucherPaymentRS>(strResponse);
return resp;
}
else
{
throw new Exception($"Error HTTP - Code: {response.StatusCode}, Message: {strResponse}");
}
}
}
catch (Exception ex)
{
throw new Exception($"Error in VoucherPaymentAsync: {ex.Message}", ex);
}
}
if (response.IsSuccessStatusCode)
{
var resp = SerializeExtension.DeserializeJson<Card3DsPaymentRS>(strResponse);
return resp;
}
else
{
throw new Exception($"Error HTTP - Code: {response.StatusCode}, Message: {strResponse}");
}
}
}
catch (Exception ex)
{
throw new Exception($"Error in Card3DsPaymentAsync: {ex.Message}", ex);
}
}
https://mail.google.com/mail/u/0/?ik=008608e040&view=pt&search=drafts&permmsgid=msg-a:r-2855211054788120985&dsqt=1&simpl=%23m… 11/13
24/10/24, 8:18 Correo de EMOVEERE CONSULTING - (sin asunto)
ConfigureHeaders();
if (response.IsSuccessStatusCode)
{
var methodsArray = SerializeExtension.DeserializeJson<PaymenMethod[]>(strResponse);
var resp = new PaymentMethodsRS
{
Methods = methodsArray
};
return resp;
}
else
{
throw new Exception($"Error HTTP - Code: {response.StatusCode}, Message: {strResponse}");
}
}
}
catch (Exception ex)
{
throw new Exception($"Error in PaymentMethodsAsync: {ex.Message}", ex);
}
}
if (response.IsSuccessStatusCode)
{
var resp = SerializeExtension.DeserializeJson<PaymentAccountRS>(strResponse);
return resp;
}
else
{
throw new Exception($"Error HTTP - Code: {response.StatusCode}, Message: {strResponse}");
}
}
}
catch (Exception ex)
https://mail.google.com/mail/u/0/?ik=008608e040&view=pt&search=drafts&permmsgid=msg-a:r-2855211054788120985&dsqt=1&simpl=%23m… 12/13
24/10/24, 8:18 Correo de EMOVEERE CONSULTING - (sin asunto)
{
throw new Exception($"Error in PaymentAccountAsync: {ex.Message}", ex);
}
}
https://mail.google.com/mail/u/0/?ik=008608e040&view=pt&search=drafts&permmsgid=msg-a:r-2855211054788120985&dsqt=1&simpl=%23m… 13/13