forked from organicmaps/organicmaps
mopub core
This commit is contained in:
parent
0485d4a10a
commit
d5ea81c371
8 changed files with 182 additions and 19 deletions
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
78
partners_api/mopub_ads.cpp
Normal file
78
partners_api/mopub_ads.cpp
Normal file
|
@ -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
|
16
partners_api/mopub_ads.hpp
Normal file
16
partners_api/mopub_ads.hpp
Normal file
|
@ -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
|
|
@ -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 \
|
||||
|
|
|
@ -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;
|
||||
|
|
64
partners_api/partners_api_tests/mopub_tests.cpp
Normal file
64
partners_api/partners_api_tests/mopub_tests.cpp
Normal file
|
@ -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
|
|
@ -29,5 +29,6 @@ SOURCES += \
|
|||
ads_engine_tests.cpp \
|
||||
booking_tests.cpp \
|
||||
facebook_tests.cpp \
|
||||
mopub_tests.cpp
|
||||
rb_tests.cpp \
|
||||
uber_tests.cpp \
|
||||
|
|
Loading…
Add table
Reference in a new issue