Link のご紹介

Rapid API は、いくつかの API リソースで構成されており、旅行者にとってエンドツーエンドで使いやすいサイトの作成を可能にします。 つまり、これらのリソースを順番に使用することで、検索料金のチェック予約予約の管理といった包括的なトランザクションを構築できます。

このようなマルチステップのトランザクションを効率化するために、Rapid API では Link と呼ばれる強力なツールを採用しています。

Link は、関連リソースへの参照であり、トランザクションをシームレスに進めるために必要な次の関連 API リソースへ開発者を導くガイドの役割を果たします。

Rapid SDK 内の以前のオペレーションの Link を活用することで、開発者は新しいオペレーションを迅速に作成し実行して、一般的な設定プロセスを回避するとともに、効率を大幅に向上させることができます。

Information

注意

この機能は、rapid-sdk v4.3.0 以降で利用できます。

Link は、次のオペレーションを手動で作成することなく、Rapid API オペレーションをナビゲートするのに便利な方法です。以前のオペレーションのレスポンスから Link を抽出して、次のオペレーションの作成に使うことができます。

Link には次のようなメリットがあります。

  • 時間を節約 : リクエスト パラメーターとオペレーションを設定することで、次のオペレーションを手動で作成する必要がありません。
  • プロセスを簡素化 : 必要な情報を手動で抽出することなく、以前のオペレーションの Link を使用して、Rapid API オペレーションを簡単にナビゲートすることができます。
  • エラーを削減 :Link を使用することで、次のオペレーションを手動で作成する際に発生する可能性のあるエラーを回避することができます。

Link を取得するには、以前の Operation レスポンスから抽出する必要があります。 次に、Operation から次の Link を作成し、RapidClient で実行します。

たとえば、Link のレスポンスから GetAvailabilityOperation を作成して、以下のように 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 priceCheck link from PropertyAvailability operation (Here, we select the first rate for the first room, then get the priceCheck link)
Link 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);
// ...

別の例としては、PriceCheckOperation のレスポンスから Link を作成し、予約の作成に使用することもできます。

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

// 2a. Extract the Link from the RoomPriceCheck
Link 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();

Link の使い方の例については、「使用例」セクションを参照してください。

このページは役に立ちましたか ?
このコンテンツに改善が必要な点があれば、
サービス向上にご協力いただきありがとうございます。