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
diff options
context:
space:
mode:
authorArsentiy Milchakov <milcars@mapswithme.com>2019-06-05 19:57:04 +0300
committerAleksandr Zatsepin <alexzatsepin@users.noreply.github.com>2019-06-06 14:39:37 +0300
commit71182322c10ce984ec3b55983251c9ccabdd1cdf (patch)
treed53ec6b330fc8128f4c5aa53d59564fc3a8e6b1c /partners_api
parent1e7797a6ef956c31176b92952a7ec09713283316 (diff)
[promo api] error callback is added into promo api
Diffstat (limited to 'partners_api')
-rw-r--r--partners_api/partners_api_tests/promo_tests.cpp8
-rw-r--r--partners_api/promo_api.cpp52
-rw-r--r--partners_api/promo_api.hpp31
3 files changed, 58 insertions, 33 deletions
diff --git a/partners_api/partners_api_tests/promo_tests.cpp b/partners_api/partners_api_tests/promo_tests.cpp
index 3ae44ac350..06e52f0c27 100644
--- a/partners_api/partners_api_tests/promo_tests.cpp
+++ b/partners_api/partners_api_tests/promo_tests.cpp
@@ -145,6 +145,10 @@ UNIT_CLASS_TEST(ScopedEyeWithAsyncGuiThread, Promo_GetCityGallery)
{
result = gallery;
testing::Notify();
+ },
+ []
+ {
+ testing::Notify();
});
testing::Wait();
@@ -157,6 +161,10 @@ UNIT_CLASS_TEST(ScopedEyeWithAsyncGuiThread, Promo_GetCityGallery)
{
result = gallery;
testing::Notify();
+ },
+ []
+ {
+ testing::Notify();
});
testing::Wait();
diff --git a/partners_api/promo_api.cpp b/partners_api/promo_api.cpp
index 859bdd4032..18c6eb94ab 100644
--- a/partners_api/promo_api.cpp
+++ b/partners_api/promo_api.cpp
@@ -53,7 +53,7 @@ void ParseCityGallery(std::string const & src, promo::CityGallery & result)
result.m_items.reserve(size);
for (size_t i = 0; i < size; ++i)
{
- promo::CityGalleryItem item;
+ promo::CityGallery::Item item;
auto const obj = json_array_get(dataArray, i);
FromJSONObject(obj, "name", item.m_name);
FromJSONObject(obj, "url", item.m_url);
@@ -96,30 +96,42 @@ std::string MakeCityGalleryUrl(std::string const & baseUrl, std::string const &
}
void GetPromoCityGalleryImpl(std::string const & baseUrl, std::string const & id,
- CityGalleryCallback const & cb)
+ CityGalleryCallback const & onSuccess, OnError const & onError)
{
ASSERT(!baseUrl.empty(), ());
ASSERT_EQUAL(baseUrl.back(), '/', ());
- CityGallery result;
- std::string httpResult;
- if (id.empty() || !WebApi::GetCityGalleryById(baseUrl, id, languages::GetCurrentNorm(), httpResult))
+ if (id.empty())
{
- cb({});
+ onSuccess({});
return;
}
- try
+ GetPlatform().RunTask(Platform::Thread::Network, [baseUrl, id, onSuccess, onError]()
{
- ParseCityGallery(httpResult, result);
- }
- catch (base::Json::Exception const & e)
- {
- LOG(LERROR, (e.Msg()));
- result.m_items.clear();
- }
+ ASSERT(!id.empty(), ());
+
+ CityGallery result;
+ std::string httpResult;
+ if (!WebApi::GetCityGalleryById(baseUrl, id, languages::GetCurrentNorm(), httpResult))
+ {
+ onError();
+ return;
+ }
+
+ try
+ {
+ ParseCityGallery(httpResult, result);
+ }
+ catch (base::Json::Exception const & e)
+ {
+ LOG(LERROR, (e.Msg()));
+ onError();
+ return;
+ }
- cb(std::move(result));
+ onSuccess(std::move(result));
+ });
}
} // namespace
@@ -176,16 +188,18 @@ std::string Api::GetPromoLinkAfterBooking() const
return MakeCityGalleryUrl(m_baseUrl, m_bookingPromoAwaitingForId, languages::GetCurrentNorm());
}
-void Api::GetCityGallery(std::string const & id, CityGalleryCallback const & cb) const
+void Api::GetCityGallery(std::string const & id, CityGalleryCallback const & onSuccess,
+ OnError const & onError) const
{
- GetPromoCityGalleryImpl(m_baseUrl, id, cb);
+ GetPromoCityGalleryImpl(m_baseUrl, id, onSuccess, onError);
}
-void Api::GetCityGallery(m2::PointD const & point, CityGalleryCallback const & cb) const
+void Api::GetCityGallery(m2::PointD const & point, CityGalleryCallback const & onSuccess,
+ OnError const & onError) const
{
CHECK(m_delegate, ());
- GetPromoCityGalleryImpl(m_baseUrl, m_delegate->GetCityId(point), cb);
+ GetPromoCityGalleryImpl(m_baseUrl, m_delegate->GetCityId(point), onSuccess, onError);
}
void Api::OnMapObjectEvent(eye::MapObject const & mapObject)
diff --git a/partners_api/promo_api.hpp b/partners_api/promo_api.hpp
index f79c390296..d106f6b9e5 100644
--- a/partners_api/promo_api.hpp
+++ b/partners_api/promo_api.hpp
@@ -23,21 +23,21 @@ struct LuxCategory
std::string m_color;
};
-struct CityGalleryItem
-{
- std::string m_name;
- std::string m_url;
- std::string m_imageUrl;
- std::string m_access;
- std::string m_tier;
- Author m_author;
- LuxCategory m_luxCategory;
-};
-
struct CityGallery
{
+ struct Item
+ {
+ std::string m_name;
+ std::string m_url;
+ std::string m_imageUrl;
+ std::string m_access;
+ std::string m_tier;
+ Author m_author;
+ LuxCategory m_luxCategory;
+ };
+
std::string m_moreUrl;
- std::vector<CityGalleryItem> m_items;
+ std::vector<Item> m_items;
};
class WebApi
@@ -48,6 +48,7 @@ public:
};
using CityGalleryCallback = platform::SafeCallback<void(CityGallery const & gallery)>;
+using OnError = platform::SafeCallback<void()>;
class Api : public eye::Subscriber
{
@@ -66,8 +67,10 @@ public:
void OnEnterForeground();
bool NeedToShowAfterBooking() const;
std::string GetPromoLinkAfterBooking() const;
- void GetCityGallery(std::string const & id, CityGalleryCallback const & cb) const;
- void GetCityGallery(m2::PointD const & point, CityGalleryCallback const & cb) const;
+ void GetCityGallery(std::string const & id, CityGalleryCallback const & onSuccess,
+ OnError const & onError) const;
+ void GetCityGallery(m2::PointD const & point, CityGalleryCallback const & onSuccess,
+ OnError const & onError) const;
// eye::Subscriber overrides:
void OnMapObjectEvent(eye::MapObject const & poi) override;