Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/map
diff options
context:
space:
mode:
authorArsentiy Milchakov <milcars@mapswithme.com>2016-10-03 15:22:46 +0300
committerArsentiy Milchakov <milcars@mapswithme.com>2016-10-10 18:14:45 +0300
commit5e716d70d81926305c53e88f68afba31ecde9224 (patch)
tree711b1d1cf976012352e001ffa5d5e4d31928a408 /map
parentecc59be84ff4b13c768f41422964d69a90c3fa2c (diff)
dummy implementation and smoke test
Diffstat (limited to 'map')
-rw-r--r--map/booking_api.cpp271
-rw-r--r--map/booking_api.hpp136
-rw-r--r--map/framework.hpp8
-rw-r--r--map/map.pro2
-rw-r--r--map/map_tests/booking_tests.cpp81
-rw-r--r--map/map_tests/map_tests.pro3
6 files changed, 8 insertions, 493 deletions
diff --git a/map/booking_api.cpp b/map/booking_api.cpp
deleted file mode 100644
index 1e3aef6e73..0000000000
--- a/map/booking_api.cpp
+++ /dev/null
@@ -1,271 +0,0 @@
-#include "map/booking_api.hpp"
-
-#include "base/gmtime.hpp"
-#include "base/logging.hpp"
-
-#include "std/chrono.hpp"
-#include "std/iostream.hpp"
-#include "std/sstream.hpp"
-
-#include "3party/jansson/myjansson.hpp"
-
-#include "private.h"
-
-char const BookingApi::kDefaultCurrency[1];
-
-BookingApi::BookingApi() : m_affiliateId(BOOKING_AFFILIATE_ID)
-{
- stringstream ss;
- 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";
-}
-
-string BookingApi::GetDescriptionUrl(string const & baseUrl, string const & /* lang */) const
-{
- return baseUrl + "?aid=" + m_affiliateId;
-}
-
-void BookingApi::GetMinPrice(string const & hotelId, string const & currency,
- function<void(string const &, string const &)> const & fn)
-{
- char dateArrival[12]{};
- char dateDeparture[12]{};
-
- system_clock::time_point p = system_clock::from_time_t(time(nullptr));
- tm arrival = my::GmTime(system_clock::to_time_t(p));
- tm departure = my::GmTime(system_clock::to_time_t(p + hours(24)));
- strftime(dateArrival, sizeof(dateArrival), "%Y-%m-%d", &arrival);
- strftime(dateDeparture, sizeof(dateDeparture), "%Y-%m-%d", &departure);
-
- string url = MakeApiUrl("getHotelAvailability", {{"hotel_ids", hotelId},
- {"currency_code", currency},
- {"arrival_date", dateArrival},
- {"departure_date", dateDeparture}});
- auto const callback = [this, fn, currency](downloader::HttpRequest & answer)
- {
-
- string minPrice;
- string priceCurrency;
- try
- {
- my::Json root(answer.Data().c_str());
- if (!json_is_array(root.get()))
- MYTHROW(my::Json::Exception, ("The answer must contain a json array."));
- size_t const sz = json_array_size(root.get());
-
- if (sz > 0)
- {
- // Read default hotel price and currency.
- auto obj = json_array_get(root.get(), 0);
- my::FromJSONObject(obj, "min_price", minPrice);
- my::FromJSONObject(obj, "currency_code", priceCurrency);
-
- // Try to get price in requested currency.
- if (!currency.empty() && priceCurrency != currency)
- {
- json_t * arr = json_object_get(obj, "other_currency");
- if (arr && json_is_array(arr))
- {
- size_t sz = json_array_size(arr);
- for (size_t i = 0; i < sz; ++i)
- {
- auto el = json_array_get(arr, i);
- string code;
- my::FromJSONObject(el, "currency_code", code);
- if (code == currency)
- {
- priceCurrency = code;
- my::FromJSONObject(el, "min_price", minPrice);
- break;
- }
- }
- }
- }
- }
- }
- catch (my::Json::Exception const & e)
- {
- LOG(LERROR, (e.Msg()));
- minPrice.clear();
- priceCurrency.clear();
- }
- fn(minPrice, priceCurrency);
- m_request.reset();
- };
-
- 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<void(HotelInfo const & hotelInfo)> 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", "Non smoking rooms"},
- {"gym", "Training gym"},
- {"pets_are_allowed", "Pets are allowed"}
- };
-
- info.m_reviews = {
- HotelReview::CriticReview(
- "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()
- ),
- HotelReview::CriticReview(
- "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()
- ),
- HotelReview::CriticReview(
- "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()
- ),
- HotelReview::CriticReview(
- "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()
- ),
- HotelReview::CriticReview(
- "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()
- ),
- HotelReview::CriticReview(
- "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()
- ),
- HotelReview::CriticReview(
- "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()
- ),
- HotelReview::CriticReview(
- "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()
- ),
- HotelReview::CriticReview(
- "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()
- ),
- HotelReview::CriticReview(
- "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()
- ),
- HotelReview::CriticReview(
- "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()
- ),
- HotelReview::CriticReview(
- "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<pair<string, string>> const & params)
-{
- stringstream ss;
- ss << m_apiUrl << func << "?";
- bool firstRun = true;
- for (auto const & param : params)
- ss << (firstRun ? firstRun = false, "" : "&") << param.first << "=" << param.second;
-
- return ss.str();
-}
diff --git a/map/booking_api.hpp b/map/booking_api.hpp
deleted file mode 100644
index db9b9c41c4..0000000000
--- a/map/booking_api.hpp
+++ /dev/null
@@ -1,136 +0,0 @@
-#pragma once
-
-#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"
-
-class BookingApi
-{
- string m_affiliateId;
- 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 & reviewNeutral,
- string const & author,
- string const & authorPictUrl,
- float const rating,
- time_point<system_clock> const date)
- : m_reviewPositive(reviewPositive)
- , m_reviewNegative(reviewNegative)
- , m_reviewNeutral(reviewNeutral)
- , m_author(author)
- , m_authorPictUrl(authorPictUrl)
- , m_rating(rating)
- , m_date(date)
- {
- }
-
-
- static HotelReview CriticReview(string const & reviewPositive,
- string const & reviewNegative,
- string const & author,
- string const & authorPictUrl,
- float const rating,
- time_point<system_clock> const date)
- {
- return {
- reviewPositive,
- reviewNegative,
- "",
- author,
- authorPictUrl,
- rating,
- date
- };
- }
-
- static HotelReview NeutralReview(string const & reviewNeutral,
- string const & author,
- string const & authorPictUrl,
- float const rating,
- time_point<system_clock> const date)
- {
- return {
- "",
- "",
- reviewNeutral,
- author,
- authorPictUrl,
- rating,
- date
- };
- }
-
- static auto constexpr kInvalidRating = numeric_limits<float>::max();
-
- /// Review text. There can be either one or both positive/negative review or
- /// a neutral one.
- string m_reviewPositive;
- string m_reviewNegative;
- string m_reviewNeutral;
- /// 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<system_clock> m_date;
- };
-
- struct Facility
- {
- string m_id;
- string m_localizedName;
- };
-
- struct HotelInfo
- {
- string m_hotelId;
-
- string m_description;
- vector<HotelPhotoUrls> m_photos;
- vector<Facility> m_facilities;
- vector<HotelReview> 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<void(string const &, string const &)> 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<void(HotelInfo const & hotelInfo)> const & fn);
-
-protected:
- unique_ptr<downloader::HttpRequest> m_request;
- string MakeApiUrl(string const & func, initializer_list<pair<string, string>> const & params);
-};
diff --git a/map/framework.hpp b/map/framework.hpp
index 7c5e46a9c6..4ce8263666 100644
--- a/map/framework.hpp
+++ b/map/framework.hpp
@@ -1,7 +1,6 @@
#pragma once
#include "map/api_mark_point.hpp"
-#include "map/booking_api.hpp"
#include "map/bookmark.hpp"
#include "map/bookmark_manager.hpp"
#include "map/displacement_mode_manager.hpp"
@@ -34,6 +33,9 @@
#include "storage/downloading_policy.hpp"
#include "storage/storage.hpp"
+#include "partners_api/booking_api.hpp"
+#include "partners_api/uber_api.hpp"
+
#include "platform/country_defines.hpp"
#include "platform/location.hpp"
#include "platform/platform.hpp"
@@ -156,6 +158,8 @@ protected:
BookingApi m_bookingApi;
+ uber::Api m_uberApi;
+
bool m_isRenderingEnabled;
/// This function will be called by m_storage when latest local files
@@ -185,6 +189,8 @@ public:
BookingApi & GetBookingApi() { return m_bookingApi; }
BookingApi const & GetBookingApi() const { return m_bookingApi; }
+ uber::Api & GetUberApi() { return m_uberApi;}
+
/// Migrate to new version of very different data.
bool IsEnoughSpaceForMigrate() const;
storage::TCountryId PreMigrate(ms::LatLon const & position, storage::Storage::TChangeCountryFunction const & change,
diff --git a/map/map.pro b/map/map.pro
index 4aabaf916c..264f744590 100644
--- a/map/map.pro
+++ b/map/map.pro
@@ -12,7 +12,6 @@ include($$ROOT_DIR/common.pri)
HEADERS += \
api_mark_point.hpp \
- booking_api.hpp \
bookmark.hpp \
bookmark_manager.hpp \
chart_generator.hpp \
@@ -36,7 +35,6 @@ SOURCES += \
../api/src/c/api-client.c \
address_finder.cpp \
api_mark_point.cpp \
- booking_api.cpp \
bookmark.cpp \
bookmark_manager.cpp \
chart_generator.cpp \
diff --git a/map/map_tests/booking_tests.cpp b/map/map_tests/booking_tests.cpp
deleted file mode 100644
index b92279a6bb..0000000000
--- a/map/map_tests/booking_tests.cpp
+++ /dev/null
@@ -1,81 +0,0 @@
-#include "testing/testing.hpp"
-
-#include "map/booking_api.hpp"
-
-UNIT_TEST(Booking_SmokeTest)
-{
- BookingApi api;
-
- string url = api.GetBookingUrl("http://someurl.com");
- TEST(!url.empty(), ());
-}
-
-UNIT_TEST(Booking_GetMinPrice)
-{
- BookingApi api;
-
- {
- string price;
- string currency;
- api.GetMinPrice("10340", BookingApi::kDefaultCurrency,
- [&price, &currency](string const & val, string const & curr)
- {
- price = val;
- currency = curr;
- testing::StopEventLoop();
- });
- testing::RunEventLoop();
-
- TEST(!price.empty(), ());
- TEST(!currency.empty(), ());
- TEST_EQUAL(currency, "EUR", ());
- }
-
- {
- string price;
- string currency;
- api.GetMinPrice("10340", "RUB", [&price, &currency](string const & val, string const & curr)
- {
- price = val;
- currency = curr;
- testing::StopEventLoop();
- });
- testing::RunEventLoop();
-
- TEST(!price.empty(), ());
- TEST(!currency.empty(), ());
- TEST_EQUAL(currency, "RUB", ());
- }
-
- {
- string price;
- string currency;
- api.GetMinPrice("10340", "ISK", [&price, &currency](string const & val, string const & curr)
- {
- price = val;
- currency = curr;
- testing::StopEventLoop();
- });
- testing::RunEventLoop();
-
- TEST(!price.empty(), ());
- TEST(!currency.empty(), ());
- 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(), 12, ());
-}
diff --git a/map/map_tests/map_tests.pro b/map/map_tests/map_tests.pro
index 3a46cddf32..e44ce96790 100644
--- a/map/map_tests/map_tests.pro
+++ b/map/map_tests/map_tests.pro
@@ -6,7 +6,7 @@ CONFIG -= app_bundle
TEMPLATE = app
ROOT_DIR = ../..
-DEPENDENCIES = map drape_frontend routing search storage drape indexer platform editor geometry coding base \
+DEPENDENCIES = map drape_frontend routing search storage drape indexer partners_api platform editor geometry coding base \
freetype fribidi expat protobuf tomcrypt jansson osrm stats_client minizip succinct pugixml stats_client
DEPENDENCIES *= opening_hours
@@ -36,7 +36,6 @@ macx-*: LIBS *= "-framework IOKit" "-framework SystemConfiguration"
SOURCES += \
../../testing/testingmain.cpp \
address_tests.cpp \
- booking_tests.cpp \
bookmarks_test.cpp \
chart_generator_tests.cpp \
feature_getters_tests.cpp \