[booking] Availability params are injected into sponsored URL

This commit is contained in:
Arsentiy Milchakov 2018-01-26 11:23:53 +03:00 committed by mpimenov
parent a54d328734
commit 8cc825c417
6 changed files with 43 additions and 1 deletions

View file

@ -13,7 +13,7 @@ string Make(string const & baseUrl, Params const & params)
ostringstream os;
os << baseUrl;
bool firstParam = true;
bool firstParam = baseUrl.find('?') == string::npos;
for (auto const & param : params)
{
if (firstParam)

View file

@ -862,6 +862,13 @@ void Framework::FillInfoFromFeatureType(FeatureType const & ft, place_page::Info
info.SetSponsoredUrl(m_bookingApi->GetBookHotelUrl(baseUrl));
info.SetSponsoredDescriptionUrl(m_bookingApi->GetDescriptionUrl(baseUrl));
info.SetSponsoredReviewUrl(m_bookingApi->GetHotelReviewsUrl(hotelId, baseUrl));
if (!m_currentBookingAvailabilityParams.IsEmpty())
{
auto const & url = info.GetSponsoredUrl();
auto const & urlWithParams =
m_bookingApi->ApplyAvailabilityParams(url, m_currentBookingAvailabilityParams);
info.SetSponsoredUrl(urlWithParams);
}
}
else if (ftypes::IsOpentableChecker::Instance()(ft))
{
@ -3483,5 +3490,6 @@ void Framework::FilterSearchResultsOnBooking(booking::filter::availability::Para
void Framework::OnBookingFilterParamsUpdate(booking::AvailabilityParams const & params)
{
m_currentBookingAvailabilityParams = params;
m_bookingFilter.OnParamsUpdated(params);
}

View file

@ -206,6 +206,7 @@ protected:
User m_user;
booking::filter::Filter m_bookingFilter;
booking::AvailabilityParams m_currentBookingAvailabilityParams;
/// This function will be called by m_storage when latest local files
/// is downloaded.

View file

@ -181,6 +181,9 @@ bool SearchAPI::SearchEverywhere(EverywhereSearchParams const & params)
}
});
if (m_sponsoredMode == SponsoredMode::Booking)
m_delegate.OnBookingFilterParamsUpdate(params.m_bookingFilterParams.m_params);
return Search(p, true /* forceSearch */);
}

View file

@ -36,6 +36,8 @@ string const kPhotoSmallUrl = "http://aff.bstatic.com/images/hotel/max300/";
string const kSearchBaseUrl = "https://www.booking.com/search.html";
string g_BookingUrlForTesting = "";
vector<string> const kAvailabilityParamsForUrl = {"checkin", "checkout", "room"};
bool RunSimpleHttpRequest(bool const needAuth, string const & url, string & result)
{
HttpClient request(url);
@ -319,6 +321,33 @@ string Api::GetSearchUrl(string const & city, string const & name) const
return resultStream.str();
}
string Api::ApplyAvailabilityParams(string const & url, AvailabilityParams const & params)
{
if (params.IsEmpty())
return url;
auto p = params.Get();
p.erase(remove_if(p.begin(), p.end(), [](url::Param const & param)
{
for (auto const & paramForUrl : kAvailabilityParamsForUrl)
{
// We need to use all numbered rooms, because of this we use find instead of ==.
if (param.m_name.find(paramForUrl) == 0)
return false;
}
return true;
}), p.end());
auto const pos = url.find('#');
if (pos == string::npos)
return url::Make(url, p);
string result = url::Make(url.substr(0, pos), p);
result.append(url.substr(pos, url.size() - pos));
return result;
}
void Api::GetMinPrice(string const & hotelId, string const & currency,
GetMinPriceCallback const & fn) const
{

View file

@ -71,6 +71,7 @@ public:
std::string GetDescriptionUrl(std::string const & baseUrl) const;
std::string GetHotelReviewsUrl(std::string const & hotelId, std::string const & baseUrl) const;
std::string GetSearchUrl(std::string const & city, std::string const & name) const;
std::string ApplyAvailabilityParams(std::string const & url, AvailabilityParams const & params);
/// Real-time information methods (used for retrieving rapidly changing information).
/// These methods send requests directly to Booking.