如何使用Amadeus Ruby gem进行多城市航班的POST查询



我正在尝试测试该航班为多城市航班搜索提供搜索API。

我正在使用阿玛迪斯宝石。请参阅:https://github.com/amadeus4dev/amadeus-ruby我使用的是Rails6。

我在控制器动作中有以下内容

def flight_offer_results
destinations = {
"originDestinations" => [
{
"id" => 1,
"originLocationCode" => "LON",
"destinationLocationCode" => "NYC",
"departureDateTimeRange" => {
"date" => "2020-12-30"
}
},
{
"id" => 2,
"originLocationCode" => "IAH",
"destinationLocationCode" => "SFO",
"departureDateTimeRange" => {
"date" => "2021-01-15"
}
}
],
"travelers" => [
{
"id" => 1,
"travelerType" => "ADULT"
}
],
"sources" => [ 
"GDS"
],
"searchCriteria" => {
"maxFlightOffers" => 1
}
}
begin
amadeus = Amadeus::Client.new
response = amadeus.shopping.flight_offers_search.post(destinations)
@flight_offers = response.data
puts "@flight_offers =========>>>>>>>> #{@flight_offers}"
rescue Amadeus::ResponseError => e
raise e
end
end

当我运行此代码时,我在控制台中得到以下错误:

Amadeus::NetworkError ([---]):

我可以针对一个来源和目的地发出get请求并返回结果。

如何进行POST请求以查询多城市航班搜索?

问题是上面的代码不是支持json的。因此,我将.to_json添加到执行post请求的行中的目的地中,并且成功了。

response = amadeus.shopping.flight_offers_search.post(destinations.to_json)

最新更新