From 7cdfeb6628f12e0b8a4d161e86639c30f549de0b Mon Sep 17 00:00:00 2001 From: Sergey Magidovich Date: Thu, 15 Sep 2016 17:17:30 +0300 Subject: [PATCH] Booking GetHotelInfo dummy method. --- map/booking_api.cpp | 84 ++++++++++++++++++++++++++++++++- map/booking_api.hpp | 62 ++++++++++++++++++++++++ map/map_tests/booking_tests.cpp | 16 +++++++ 3 files changed, 161 insertions(+), 1 deletion(-) diff --git a/map/booking_api.cpp b/map/booking_api.cpp index d852fc860c..78fe0c0152 100644 --- a/map/booking_api.cpp +++ b/map/booking_api.cpp @@ -19,6 +19,7 @@ BookingApi::BookingApi() : m_affiliateId(BOOKING_AFFILIATE_ID) ss << BOOKING_KEY << ":" << BOOKING_SECRET; m_apiUrl = "https://" + ss.str() + "@distribution-xml.booking.com/json/bookings."; } + string BookingApi::GetBookingUrl(string const & baseUrl, string const & /* lang */) const { return GetDescriptionUrl(baseUrl) + "#availability"; @@ -100,6 +101,87 @@ void BookingApi::GetMinPrice(string const & hotelId, string const & currency, m_request.reset(downloader::HttpRequest::Get(url, callback)); } +// TODO(mgsergio): This is just a mockup, make it a real function. +void BookingApi::GetHotelInfo(string const & hotelId, string const & /* lang */, + function const & fn) +{ + HotelInfo info; + + info.m_hotelId = "000"; + info.m_description = "Interesting place among SoHo, Little " + "Italy and China town. Modern design. " + "Great view from roof. Near subway. " + "Free refreshment every afternoon. " + "The staff was very friendly."; + + info.m_photos.push_back({ + "http://storage9.static.itmages.ru/i/16/0915/h_1473944906_4427771_63a7c2282b.jpg", + "http://storage7.static.itmages.ru/i/16/0915/h_1473945189_5545647_db54564f06.jpg"}); + + info.m_photos.push_back({ + "http://storage9.static.itmages.ru/i/16/0915/h_1473944906_1573275_450fcd78b0.jpg", + "http://storage8.static.itmages.ru/i/16/0915/h_1473945194_6402871_b68c63c705.jpg"}); + + info.m_photos.push_back({ + "http://storage1.static.itmages.ru/i/16/0915/h_1473944906_6998375_f1ba6024a5.jpg", + "http://storage7.static.itmages.ru/i/16/0915/h_1473945188_9401486_7185c713bc.jpg"}); + + info.m_photos.push_back({ + "http://storage7.static.itmages.ru/i/16/0915/h_1473944904_8294064_035b4328ee.jpg", + "http://storage9.static.itmages.ru/i/16/0915/h_1473945189_8999398_d9bfe0d56d.jpg"}); + + info.m_photos.push_back({ + "http://storage6.static.itmages.ru/i/16/0915/h_1473944904_2231876_680171f67f.jpg", + "http://storage1.static.itmages.ru/i/16/0915/h_1473945190_2042562_c6cfcccd18.jpg"}); + + info.m_photos.push_back({ + "http://storage7.static.itmages.ru/i/16/0915/h_1473944904_2871576_660e0aad58.jpg", + "http://storage1.static.itmages.ru/i/16/0915/h_1473945190_9605355_94164142b7.jpg"}); + + info.m_photos.push_back({ + "http://storage8.static.itmages.ru/i/16/0915/h_1473944905_3578559_d4e95070e9.jpg", + "http://storage3.static.itmages.ru/i/16/0915/h_1473945190_3367031_145793d530.jpg"}); + + info.m_photos.push_back({ + "http://storage8.static.itmages.ru/i/16/0915/h_1473944905_5596402_9bdce96ace.jpg", + "http://storage4.static.itmages.ru/i/16/0915/h_1473945191_2783367_2440027ece.jpg"}); + + info.m_photos.push_back({ + "http://storage8.static.itmages.ru/i/16/0915/h_1473944905_4312757_433c687f4d.jpg", + "http://storage6.static.itmages.ru/i/16/0915/h_1473945191_1817571_b945aa1f3e.jpg"}); + + info.m_facilities = {"Non smoking rooms", "Gym", "Pets are allowed"}; + + info.m_reviews = { + { + "Interesting place among SoHo, Little Italy and China town. Modern design. Great view from roof. Near subway. Free refreshment every afternoon. The staff was very friendly.", + "Little bit noise from outside", + "Anonymous1", + "http://storage2.static.itmages.ru/i/16/0915/h_1473945375_5332083_b44af613bd.jpg", + 9.2, + system_clock::now() + }, + { + "Interesting place among SoHo, Little Italy and China town. Modern design. Great view from roof. Near subway. Free refreshment every afternoon. The staff was very friendly.", + "Little bit noise from outside", + "Anonymous2", + "http://storage2.static.itmages.ru/i/16/0915/h_1473945375_7504873_be0fe246e3.jpg", + 9.2, + system_clock::now() + }, + { + "Interesting place among SoHo, Little Italy and China town. Modern design. Great view from roof. Near subway. Free refreshment every afternoon. The staff was very friendly.", + "Little bit noise from outside", + "Anonymous2", + "http://storage1.static.itmages.ru/i/16/0915/h_1473945374_9397526_996bbca0d7.jpg", + 9.2, + system_clock::now() + } + }; + + fn(info); +} + string BookingApi::MakeApiUrl(string const & func, initializer_list> const & params) { @@ -110,4 +192,4 @@ string BookingApi::MakeApiUrl(string const & func, ss << (firstRun ? firstRun = false, "" : "&") << param.first << "=" << param.second; return ss.str(); -} \ No newline at end of file +} diff --git a/map/booking_api.hpp b/map/booking_api.hpp index 76fef16c7c..2c41789c1d 100644 --- a/map/booking_api.hpp +++ b/map/booking_api.hpp @@ -2,8 +2,10 @@ #include "platform/http_request.hpp" +#include "std/chrono.hpp" #include "std/function.hpp" #include "std/initializer_list.hpp" +#include "std/limits.hpp" #include "std/string.hpp" #include "std/unique_ptr.hpp" #include "std/utility.hpp" @@ -14,14 +16,74 @@ class BookingApi string m_apiUrl; public: + struct HotelPhotoUrls + { + string m_small; + string m_original; + }; + + struct HotelReview + { + HotelReview() = default; + // C++11 doesn't allow aggragate initialization for structs with default member initializer. + // But C++14 does. + HotelReview(string const & reviewPositive, + string const & reviewNegative, + string const & author, + string const & authorPictUrl, + float const rating, + time_point const date) + : m_reviewPositive(reviewPositive) + , m_reviewNegative(reviewNegative) + , m_author(author) + , m_authorPictUrl(authorPictUrl) + , m_rating(rating) + , m_date(date) + { + } + + static auto constexpr kInvalidRating = numeric_limits::max(); + + /// Review text. + string m_reviewPositive; + string m_reviewNegative; + /// Review author name. + string m_author; + /// Url to a author's picture. + string m_authorPictUrl; + /// Author's hotel evaluation. + float m_rating = kInvalidRating; + /// An issue date. + time_point m_date; + }; + + struct HotelInfo + { + string m_hotelId; + + string m_description; + vector m_photos; + vector m_facilities; + vector m_reviews; + }; + static constexpr const char kDefaultCurrency[1] = {0}; BookingApi(); string GetBookingUrl(string const & baseUrl, string const & lang = string()) const; string GetDescriptionUrl(string const & baseUrl, string const & lang = string()) const; + + // Real-time information methods (used for retriving rapidly changing information). + // These methods send requests directly to Booking. void GetMinPrice(string const & hotelId, string const & currency, function const & fn); + + // Static information methods (use for information that can be cached). + // These methods use caching server to prevent Booking from being ddossed. + void GetHotelInfo(string const & hotelId, string const & lang, + function const & fn); + protected: unique_ptr m_request; string MakeApiUrl(string const & func, initializer_list> const & params); diff --git a/map/map_tests/booking_tests.cpp b/map/map_tests/booking_tests.cpp index ccbf44090e..5518288db7 100644 --- a/map/map_tests/booking_tests.cpp +++ b/map/map_tests/booking_tests.cpp @@ -63,3 +63,19 @@ UNIT_TEST(Booking_GetMinPrice) TEST_EQUAL(currency, "ISK", ()); } } + +UNIT_TEST(GetHotelInfo) // GetHotelInfo is a mockup now. +{ + BookingApi api; + BookingApi::HotelInfo info; + + api.GetHotelInfo("000", "en", [&info](BookingApi::HotelInfo const & i) + { + info = i; + }); + + TEST(!info.m_description.empty(), ()); + TEST_EQUAL(info.m_photos.size(), 9, ()); + TEST_EQUAL(info.m_facilities.size(), 3, ()); + TEST_EQUAL(info.m_reviews.size(), 3, ()); +}