diff options
author | Arsentiy Milchakov <milcars@mapswithme.com> | 2017-04-13 13:52:32 +0300 |
---|---|---|
committer | Ilya Grechuhin <i.grechuhin@gmail.com> | 2017-04-13 15:48:12 +0300 |
commit | d5ea81c371213ad762aa2e1f751c5f5ce5f6d3b0 (patch) | |
tree | f753a2ab7118c23b1a8ad586423f4a5a756607d9 /partners_api | |
parent | 0485d4a10aecc3ba78a36bb566acc058719d57f8 (diff) |
mopub core
Diffstat (limited to 'partners_api')
-rw-r--r-- | partners_api/ads_engine.cpp | 4 | ||||
-rw-r--r-- | partners_api/banner.hpp | 4 | ||||
-rw-r--r-- | partners_api/mopub_ads.cpp | 78 | ||||
-rw-r--r-- | partners_api/mopub_ads.hpp | 16 | ||||
-rw-r--r-- | partners_api/partners_api.pro | 2 | ||||
-rw-r--r-- | partners_api/partners_api_tests/ads_engine_tests.cpp | 32 | ||||
-rw-r--r-- | partners_api/partners_api_tests/mopub_tests.cpp | 64 | ||||
-rw-r--r-- | partners_api/partners_api_tests/partners_api_tests.pro | 1 |
8 files changed, 182 insertions, 19 deletions
diff --git a/partners_api/ads_engine.cpp b/partners_api/ads_engine.cpp index a5b114c5ba..e66eb234d5 100644 --- a/partners_api/ads_engine.cpp +++ b/partners_api/ads_engine.cpp @@ -1,5 +1,5 @@ #include "partners_api/ads_engine.hpp" -#include "partners_api/facebook_ads.hpp" +#include "partners_api/mopub_ads.hpp" #include "partners_api/rb_ads.hpp" #include "indexer/feature_data.hpp" @@ -14,7 +14,7 @@ Engine::Engine() { // The banner systems are placed by priority. First has a top priority. m_containers.emplace_back(Banner::Type::RB, my::make_unique<Rb>()); - m_containers.emplace_back(Banner::Type::Facebook, my::make_unique<Facebook>()); + m_containers.emplace_back(Banner::Type::Mopub, my::make_unique<Mopub>()); } bool Engine::HasBanner(feature::TypesHolder const & types, diff --git a/partners_api/banner.hpp b/partners_api/banner.hpp index fe6f494a02..cbf70789d4 100644 --- a/partners_api/banner.hpp +++ b/partners_api/banner.hpp @@ -10,7 +10,8 @@ struct Banner { None = 0, Facebook = 1, - RB = 2 + RB = 2, + Mopub = 3 }; Banner() = default; @@ -27,6 +28,7 @@ inline std::string DebugPrint(Banner::Type type) case Banner::Type::None: return "None"; case Banner::Type::Facebook: return "Facebook"; case Banner::Type::RB: return "RB"; + case Banner::Type::Mopub: return "Mopub"; } } } // namespace ads diff --git a/partners_api/mopub_ads.cpp b/partners_api/mopub_ads.cpp new file mode 100644 index 0000000000..e7162b6d03 --- /dev/null +++ b/partners_api/mopub_ads.cpp @@ -0,0 +1,78 @@ +#include "partners_api/mopub_ads.hpp" + +namespace +{ +#if defined(OMIM_OS_IPHONE) + auto const kTourismPlacementId = "29c1bc85b46442b5a370552916aa6822"; + auto const kNavigationPlacementId = "00af522ea7f94b77b6c671c7e1b13c3f"; + auto const kNonTourismPlacementId = "67ebcbd0af8345f18cccfb230ca08a17"; +#else + auto const kTourismPlacementId = "d298f205fb8a47aaafb514d2b5b8cf55"; + auto const kNavigationPlacementId = "fbd54c31a20347a6b5d6654510c542a4"; + auto const kNonTourismPlacementId = "94b8d70370a643929aa4c8c764d25e5b"; +#endif +} // namespace + +namespace ads +{ +Mopub::Mopub() +{ + AppendEntry({{"amenity", "cafe"}, // food + {"amenity", "fast_food"}, + {"amenity", "restaurant"}, + {"amenity", "bar"}, + {"amenity", "pub"}, + {"shop"}, // shops + {"amenity", "marketplace"}, + {"tourism", "hotel"}, // hotels + {"tourism", "hostel"}, + {"tourism", "motel"}, + {"tourism", "apartment"}, + {"tourism", "resort"}, + {"tourism", "chalet"}, + {"tourism", "zoo"}, // sights + {"tourism", "artwork"}, + {"tourism", "information"}, + {"tourism", "attraction"}, + {"tourism", "viewpoint"}, + {"tourism", "museum"}, + {"amenity", "fountain"}, + {"amenity", "townhall"}, + {"historic"}, + {"amenity", "cinema"}, // entertainment + {"amenity", "brothel"}, + {"amenity", "casino"}, + {"amenity", "nightclub"}, + {"amenity", "theatre"}, + {"boundary", "national_park"}, + {"leisure"}}, + kTourismPlacementId); + + AppendEntry({{"building"}, // building + {"place"}, // large toponyms + {"aerialway"}, // city transport + {"highway", "bus_stop"}, + {"highway", "speed_camera"}, + {"public_transport"}, + {"aeroway"}, // global transport + {"railway"}, + {"man_made", "pier"}}, + kNavigationPlacementId); + + AppendEntry({{"amenity", "dentist"}, // health + {"amenity", "doctors"}, + {"amenity", "clinic"}, + {"amenity", "hospital"}, + {"amenity", "pharmacy"}, + {"amenity", "veterinary"}, + {"amenity", "bank"}, // finansial + {"amenity", "atm"}, + {"amenity", "bureau_de_change"}}, + kNonTourismPlacementId); +} + +std::string Mopub::GetBannerIdForOtherTypes() const +{ + return kNonTourismPlacementId; +} +} // namespace ads diff --git a/partners_api/mopub_ads.hpp b/partners_api/mopub_ads.hpp new file mode 100644 index 0000000000..97815de629 --- /dev/null +++ b/partners_api/mopub_ads.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include "partners_api/ads_base.hpp" + +namespace ads +{ +// Class which matches feature types and mopub banner ids. +class Mopub : public Container +{ +public: + Mopub(); + + // ContainerBase overrides: + std::string GetBannerIdForOtherTypes() const override; +}; +} // namespace ads diff --git a/partners_api/partners_api.pro b/partners_api/partners_api.pro index 47e4b9200a..61e2fe682a 100644 --- a/partners_api/partners_api.pro +++ b/partners_api/partners_api.pro @@ -13,6 +13,7 @@ SOURCES += \ ads_engine.cpp \ booking_api.cpp \ facebook_ads.cpp \ + mopub_ads.cpp \ opentable_api.cpp \ rb_ads.cpp \ uber_api.cpp \ @@ -23,6 +24,7 @@ HEADERS += \ banner.hpp \ booking_api.hpp \ facebook_ads.hpp \ + mopub_ads.hpp \ opentable_api.hpp \ rb_ads.hpp \ uber_api.hpp \ diff --git a/partners_api/partners_api_tests/ads_engine_tests.cpp b/partners_api/partners_api_tests/ads_engine_tests.cpp index 26b102307a..7024c200bd 100644 --- a/partners_api/partners_api_tests/ads_engine_tests.cpp +++ b/partners_api/partners_api_tests/ads_engine_tests.cpp @@ -5,7 +5,7 @@ #include "indexer/feature_data.hpp" #include "partners_api/ads_engine.hpp" -#include "partners_api/facebook_ads.hpp" +#include "partners_api/mopub_ads.hpp" #include "partners_api/rb_ads.hpp" namespace @@ -14,7 +14,7 @@ void CheckCountAndTypes(std::vector<ads::Banner> const & banners) { TEST_EQUAL(banners.size(), 2, ()); TEST_EQUAL(banners[0].m_type, ads::Banner::Type::RB, ()); - TEST_EQUAL(banners[1].m_type, ads::Banner::Type::Facebook, ()); + TEST_EQUAL(banners[1].m_type, ads::Banner::Type::Mopub, ()); } void CheckIds(std::vector<ads::Banner> const & banners, std::vector<std::string> const & ids) @@ -31,20 +31,20 @@ UNIT_TEST(AdsEngine_Smoke) classificator::Load(); Classificator const & c = classif(); ads::Engine engine; - ads::Facebook facebook; + ads::Mopub mopub; { feature::TypesHolder holder; holder.Assign(c.GetTypeByPath({"amenity", "dentist"})); TEST(engine.HasBanner(holder, {"Ukraine"}), ()); auto result = engine.GetBanners(holder, {"Ukraine"}); CheckCountAndTypes(result); - CheckIds(result, {"7", facebook.GetBannerIdForOtherTypes()}); + CheckIds(result, {"7", mopub.GetBannerIdForOtherTypes()}); holder.Add(c.GetTypeByPath({"amenity", "pub"})); TEST(engine.HasBanner(holder, {"Ukraine"}), ()); result = engine.GetBanners(holder, {"Ukraine"}); CheckCountAndTypes(result); - CheckIds(result, {"7", facebook.GetBannerIdForOtherTypes()}); + CheckIds(result, {"7", mopub.GetBannerIdForOtherTypes()}); } { feature::TypesHolder holder; @@ -52,7 +52,7 @@ UNIT_TEST(AdsEngine_Smoke) TEST(engine.HasBanner(holder, {"Moldova"}), ()); auto result = engine.GetBanners(holder, {"Moldova"}); CheckCountAndTypes(result); - CheckIds(result, {"5", facebook.GetBannerIdForOtherTypes()}); + CheckIds(result, {"5", "d298f205fb8a47aaafb514d2b5b8cf55"}); } { feature::TypesHolder holder; @@ -60,7 +60,7 @@ UNIT_TEST(AdsEngine_Smoke) TEST(engine.HasBanner(holder, {"Russian Federation"}), ()); auto result = engine.GetBanners(holder, {"Russian Federation"}); CheckCountAndTypes(result); - CheckIds(result, {"2", facebook.GetBannerIdForOtherTypes()}); + CheckIds(result, {"2", "d298f205fb8a47aaafb514d2b5b8cf55"}); } { feature::TypesHolder holder; @@ -68,7 +68,7 @@ UNIT_TEST(AdsEngine_Smoke) TEST(engine.HasBanner(holder, {"Belarus"}), ()); auto result = engine.GetBanners(holder, {"Belarus"}); CheckCountAndTypes(result); - CheckIds(result, {"8", facebook.GetBannerIdForOtherTypes()}); + CheckIds(result, {"8", mopub.GetBannerIdForOtherTypes()}); } { feature::TypesHolder holder; @@ -76,7 +76,7 @@ UNIT_TEST(AdsEngine_Smoke) TEST(engine.HasBanner(holder, {"Spain", "Ukraine"}), ()); auto result = engine.GetBanners(holder, {"Spain", "Ukraine"}); CheckCountAndTypes(result); - CheckIds(result, {"1", facebook.GetBannerIdForOtherTypes()}); + CheckIds(result, {"1", "d298f205fb8a47aaafb514d2b5b8cf55"}); } { feature::TypesHolder holder; @@ -84,15 +84,15 @@ UNIT_TEST(AdsEngine_Smoke) TEST(engine.HasBanner(holder, {"Ukraine", "Spain"}), ()); auto result = engine.GetBanners(holder, {"Ukraine", "Spain"}); CheckCountAndTypes(result); - CheckIds(result, {"1", facebook.GetBannerIdForOtherTypes()}); + CheckIds(result, {"1", "d298f205fb8a47aaafb514d2b5b8cf55"}); } { feature::TypesHolder holder; holder.Assign(c.GetTypeByPath({"amenity", "pub"})); TEST(engine.HasBanner(holder, {"Spain"}), ()); auto result = engine.GetBanners(holder, {"Spain"}); - CheckIds(result, {facebook.GetBannerIdForOtherTypes()}); - TEST_EQUAL(result[0].m_type, ads::Banner::Type::Facebook, ()); + CheckIds(result, {"d298f205fb8a47aaafb514d2b5b8cf55"}); + TEST_EQUAL(result[0].m_type, ads::Banner::Type::Mopub, ()); } ads::Rb rb; { @@ -101,7 +101,7 @@ UNIT_TEST(AdsEngine_Smoke) TEST(engine.HasBanner(holder, {"Armenia"}), ()); auto result = engine.GetBanners(holder, {"Armenia"}); CheckCountAndTypes(result); - CheckIds(result, {rb.GetBannerIdForOtherTypes(), facebook.GetBannerIdForOtherTypes()}); + CheckIds(result, {rb.GetBannerIdForOtherTypes(), mopub.GetBannerIdForOtherTypes()}); } { feature::TypesHolder holder; @@ -109,15 +109,15 @@ UNIT_TEST(AdsEngine_Smoke) TEST(engine.HasBanner(holder, {"Armenia", "Azerbaijan Region"}), ()); auto result = engine.GetBanners(holder, {"Armenia", "Azerbaijan Region"}); CheckCountAndTypes(result); - CheckIds(result, {rb.GetBannerIdForOtherTypes(), facebook.GetBannerIdForOtherTypes()}); + CheckIds(result, {rb.GetBannerIdForOtherTypes(), mopub.GetBannerIdForOtherTypes()}); } { feature::TypesHolder holder; holder.Assign(c.GetTypeByPath({"sponsored", "opentable"})); TEST(engine.HasBanner(holder, {"Brazil"}), ()); auto result = engine.GetBanners(holder, {"Brazil"}); - CheckIds(result, {facebook.GetBannerIdForOtherTypes()}); - TEST_EQUAL(result[0].m_type, ads::Banner::Type::Facebook, ()); + CheckIds(result, {mopub.GetBannerIdForOtherTypes()}); + TEST_EQUAL(result[0].m_type, ads::Banner::Type::Mopub, ()); } { feature::TypesHolder holder; diff --git a/partners_api/partners_api_tests/mopub_tests.cpp b/partners_api/partners_api_tests/mopub_tests.cpp new file mode 100644 index 0000000000..0331fa40ad --- /dev/null +++ b/partners_api/partners_api_tests/mopub_tests.cpp @@ -0,0 +1,64 @@ +#include "testing/testing.hpp" + +#include "indexer/classificator.hpp" +#include "indexer/classificator_loader.hpp" +#include "indexer/feature_data.hpp" + +#include "partners_api/mopub_ads.hpp" + +namespace +{ +UNIT_TEST(Mopub_GetBanner) +{ + classificator::Load(); + Classificator const & c = classif(); + ads::Mopub const mopub; + { + feature::TypesHolder holder; + holder.Assign(c.GetTypeByPath({"amenity", "dentist"})); + TEST_EQUAL(mopub.GetBannerId(holder, "Brazil"), mopub.GetBannerIdForOtherTypes(), ()); + holder.Add(c.GetTypeByPath({"amenity", "pub"})); + TEST_EQUAL(mopub.GetBannerId(holder, "Cuba"), mopub.GetBannerIdForOtherTypes(), ()); + } + { + feature::TypesHolder holder; + holder.Add(c.GetTypeByPath({"amenity", "restaurant"})); + TEST_EQUAL(mopub.GetBannerId(holder, "Any country"), "d298f205fb8a47aaafb514d2b5b8cf55", ()); + } + { + feature::TypesHolder holder; + holder.Assign(c.GetTypeByPath({"tourism", "information", "map"})); + TEST_EQUAL(mopub.GetBannerId(holder, "Russia"), "d298f205fb8a47aaafb514d2b5b8cf55", ()); + } + { + feature::TypesHolder holder; + holder.Assign(c.GetTypeByPath({"highway", "speed_camera"})); + TEST_EQUAL(mopub.GetBannerId(holder, "Egypt"), "fbd54c31a20347a6b5d6654510c542a4", ()); + } + { + feature::TypesHolder holder; + holder.Assign(c.GetTypeByPath({"building"})); + TEST_EQUAL(mopub.GetBannerId(holder, "Russia"), "fbd54c31a20347a6b5d6654510c542a4", ()); + } + { + feature::TypesHolder holder; + holder.Assign(c.GetTypeByPath({"shop", "ticket"})); + TEST_EQUAL(mopub.GetBannerId(holder, "USA"), "d298f205fb8a47aaafb514d2b5b8cf55", ()); + } + { + feature::TypesHolder holder; + holder.Assign(c.GetTypeByPath({"amenity", "toilets"})); + TEST_EQUAL(mopub.GetBannerId(holder, "Spain"), mopub.GetBannerIdForOtherTypes(), ()); + } + { + feature::TypesHolder holder; + holder.Assign(c.GetTypeByPath({"sponsored", "opentable"})); + TEST_EQUAL(mopub.GetBannerId(holder, "Denmark"), mopub.GetBannerIdForOtherTypes(), ()); + } + { + feature::TypesHolder holder; + holder.Assign(c.GetTypeByPath({"sponsored", "booking"})); + TEST_EQUAL(mopub.GetBannerId(holder, "India"), "", ()); + } +} +} // namespace diff --git a/partners_api/partners_api_tests/partners_api_tests.pro b/partners_api/partners_api_tests/partners_api_tests.pro index 795792d9cd..d452b292cc 100644 --- a/partners_api/partners_api_tests/partners_api_tests.pro +++ b/partners_api/partners_api_tests/partners_api_tests.pro @@ -29,5 +29,6 @@ SOURCES += \ ads_engine_tests.cpp \ booking_tests.cpp \ facebook_tests.cpp \ + mopub_tests.cpp rb_tests.cpp \ uber_tests.cpp \ |