This is an auto-generated translation

Utilizar enlaces

Información general

Rapid consta de varios recursos API que se utilizan conjuntamente para crear una experiencia de reserva de extremo a extremo para viajeros. Utilizas estos recursos en secuencia para construir transacciones completas, como comprar, comprobación de precios, reserva, y, por último, gestión de reservas.

Para agilizar estas transacciones de varios pasos, Rapid utiliza una potente herramienta llamada enlaces.

Un enlace es una referencia a un recurso relacionado, que actúa como una guía que dirige a los desarrolladores al siguiente recurso API relevante necesario para progresar sin problemas en la transacción.

Aprovechando los enlaces, los desarrolladores pueden crear y ejecutar rápidamente nuevas operaciones, evitando el típico proceso de configuración y mejorando significativamente la eficiencia.

Information

Nota

Esta función está disponible en rapid-sdk v5.1.0 y posteriores.

Ventajas de utilizar enlaces

Un enlace es una forma cómoda de navegar por las operaciones de la Rapid API sin tener que crear manualmente la siguiente operación. Los enlaces se definen en la sección links de cada respuesta. Puedes extraer un enlace de la respuesta de la operación anterior y utilizarlo para crear la siguiente operación.

Utilizar un enlace ofrece las siguientes ventajas:

  • Ahorra tiempo: puedes configurar los parámetros de la solicitud y la operación para no tener que crear manualmente la operación siguiente.
  • Simplifica el proceso: Navega fácilmente por las operaciones de la API Rápida utilizando el enlace de la operación anterior, sin tener que extraer manualmente la información necesaria.
  • Reduce los errores: Al utilizar un enlace, puedes evitar errores que podrían producirse al crear manualmente la siguiente operación.

¿Cómo utilizar un enlace?

En la respuesta de una operación, busca la sección links devuelta y utiliza el enlace para construir la siguiente operación adecuada. A continuación, puedes crear el siguiente operation a partir del link y ejecutarlo con el RapidClient.

Por ejemplo, puedes crear un PriceCheckOperationLink a partir de la respuesta de GetAvailabilityOperation y utilizarlo para crear PriceCheckOperation:

// 1. Create and execute the GetAvailabilityOperation (The first operation)
GetAvailabilityOperation getAvailabilityOperation = new GetAvailabilityOperation(getAvailabilityOperationParams);
Response<List<Property>> propertiesResponse = rapidClient.execute(getAvailabilityOperation);

// 2a. Select the needed property from the response (Here, we select the first property)
Property property = propertiesResponse.getData().get(0);

// 2b. Make sure the property is an instance of PropertyAvailability
if (!(property instanceof PropertyAvailability)) {
    return;
}

PropertyAvailability propertyAvailability = (PropertyAvailability) property;

// 3a. Extract the PriceCheckOperationLink from PropertyAvailability operation (Here, we select the first rate for the first room, then get the PriceCheckOperationLink)
PriceCheckOperationLink priceCheckLink = propertyAvailability.getRooms().get(0).getRates().get(0).getBedGroups().entrySet().stream().findFirst().get().getValue().getLinks().getPriceCheck();

// 3b. Create the needed context for the PriceCheckOperation
PriceCheckOperationContext priceCheckOperationContext = PriceCheckOperationContext.builder().customerIp("1.2.3.4").build(); // fill the context as needed

// 4. Create and execute the PriceCheckOperation using the Link
PriceCheckOperation priceCheckOperation = new PriceCheckOperation(priceCheckLink, priceCheckOperationContext);
Response<RoomPriceCheck> roomPriceCheckResponse = rapidClient.execute(priceCheckOperation);
// ...

Otro ejemplo sería crear un PostItineraryOperationLink a partir de la respuesta de PriceCheckOperation y utilizarlo para crear una reserva.

// 1. Get the RoomPriceCheck from the previous step
RoomPriceCheck roomPriceCheck = roomPriceCheckResponse.getData(); // from the previous step

// 2a. Extract the Link from the RoomPriceCheck
PostItineraryOperationLink postItineraryLink = roomPriceCheck.getLinks().getBook();

// 2b. Create the needed context for the PostItineraryOperation
PostItineraryOperationContext postItineraryOperationContext = PostItineraryOperationContext.builder().customerIp("1.2.3.4").build(); // fill the context as needed

// 2c. Create the CreateItineraryRequest
CreateItineraryRequest createItineraryRequest = CreateItineraryRequest.builder().build(); // fill the request as needed

// 3. Create and execute the PostItineraryOperation using the Link
PostItineraryOperation postItineraryOperation = new PostItineraryOperation(postItineraryLink, postItineraryOperationContext, createItineraryRequest);

// 4. Execute the PostItineraryOperation
Response<ItineraryCreation> itineraryCreationResponse = rapidClient.execute(postItineraryOperation);
ItineraryCreation itineraryCreation = itineraryCreationResponse.getData();

Para más ejemplos sobre cómo utilizar los enlaces, consulta la sección Ejemplos de uso.

¿Te ha resultado útil esta página?
¿Cómo podemos mejorar este contenido?
¡Gracias por ayudarnos a mejorar!