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:
authorAleksandr Zatsepin <alexzatsepin@users.noreply.github.com>2019-01-09 11:46:47 +0300
committerMaksim Andrianov <maksimandrianov1@gmail.com>2019-01-09 11:46:47 +0300
commit92e3469b3d151aed60a4703e3ad8d4ca754eb5bd (patch)
tree13cbd5d0f48a02968d031aedee6aa412d7024a43 /partners_api
parentae2609e2bf6301d1f0071f352dc8d2a8bdc33948 (diff)
Removed viator code (#9917)
* Removed viator code from core, android and ios. * Removed redundant viator strings * [android][ios] Generated localizations
Diffstat (limited to 'partners_api')
-rw-r--r--partners_api/CMakeLists.txt2
-rw-r--r--partners_api/partners_api_tests/CMakeLists.txt1
-rw-r--r--partners_api/partners_api_tests/viator_tests.cpp47
-rw-r--r--partners_api/viator_api.cpp247
-rw-r--r--partners_api/viator_api.hpp49
5 files changed, 0 insertions, 346 deletions
diff --git a/partners_api/CMakeLists.txt b/partners_api/CMakeLists.txt
index 35bbc0e901..97f8cccb03 100644
--- a/partners_api/CMakeLists.txt
+++ b/partners_api/CMakeLists.txt
@@ -50,8 +50,6 @@ set(
uber_api.hpp
utils.cpp
utils.hpp
- viator_api.cpp
- viator_api.hpp
yandex_api.cpp
yandex_api.hpp
)
diff --git a/partners_api/partners_api_tests/CMakeLists.txt b/partners_api/partners_api_tests/CMakeLists.txt
index ce96642991..163b0f3f2d 100644
--- a/partners_api/partners_api_tests/CMakeLists.txt
+++ b/partners_api/partners_api_tests/CMakeLists.txt
@@ -16,7 +16,6 @@ set(
taxi_engine_tests.cpp
taxi_places_tests.cpp
uber_tests.cpp
- viator_tests.cpp
yandex_tests.cpp
)
diff --git a/partners_api/partners_api_tests/viator_tests.cpp b/partners_api/partners_api_tests/viator_tests.cpp
deleted file mode 100644
index 2a68be8024..0000000000
--- a/partners_api/partners_api_tests/viator_tests.cpp
+++ /dev/null
@@ -1,47 +0,0 @@
-#include "testing/testing.hpp"
-
-#include "partners_api/viator_api.hpp"
-
-#include <algorithm>
-#include <random>
-#include <sstream>
-#include <vector>
-
-#include "3party/jansson/myjansson.hpp"
-
-namespace
-{
-UNIT_TEST(Viator_SortProducts)
-{
- std::vector<viator::Product> products =
- {
- {"1", 10.0, 10, "", 10.0, "", "", "", ""},
- {"2", 9.0, 100, "", 200.0, "", "", "", ""},
- {"3", 9.0, 100, "", 100.0, "", "", "", ""},
- {"4", 9.0, 10, "", 200.0, "", "", "", ""},
- {"5", 9.0, 9, "", 300.0, "", "", "", ""},
- {"6", 8.0, 200, "", 400.0, "", "", "", ""},
- {"7", 7.0, 20, "", 200.0, "", "", "", ""},
- {"8", 7.0, 20, "", 1.0, "", "", "", ""},
- {"9", 7.0, 0, "", 300.0, "", "", "", ""},
- {"10", 7.0, 0, "", 1.0, "", "", "", ""}
- };
-
- for (size_t i = 0; i < 1000; ++i)
- {
- std::shuffle(products.begin(), products.end(), std::minstd_rand(std::minstd_rand::default_seed));
- viator::SortProducts(products);
-
- TEST_EQUAL(products[0].m_title, "1", ());
- TEST_EQUAL(products[1].m_title, "2", ());
- TEST_EQUAL(products[2].m_title, "3", ());
- TEST_EQUAL(products[3].m_title, "4", ());
- TEST_EQUAL(products[4].m_title, "5", ());
- TEST_EQUAL(products[5].m_title, "6", ());
- TEST_EQUAL(products[6].m_title, "7", ());
- TEST_EQUAL(products[7].m_title, "8", ());
- TEST_EQUAL(products[8].m_title, "9", ());
- TEST_EQUAL(products[9].m_title, "10", ());
- }
-}
-} // namespace
diff --git a/partners_api/viator_api.cpp b/partners_api/viator_api.cpp
deleted file mode 100644
index 0169c4344a..0000000000
--- a/partners_api/viator_api.cpp
+++ /dev/null
@@ -1,247 +0,0 @@
-#include "partners_api/viator_api.hpp"
-
-#include "platform/http_client.hpp"
-#include "platform/platform.hpp"
-#include "platform/preferred_languages.hpp"
-
-#include "coding/string_utf8_multilang.hpp"
-#include "coding/url_encode.hpp"
-
-#include "base/logging.hpp"
-#include "base/thread.hpp"
-
-#include <algorithm>
-#include <set>
-#include <sstream>
-#include <unordered_map>
-#include <unordered_set>
-
-#include "3party/jansson/myjansson.hpp"
-
-#include "private.h"
-
-namespace
-{
-using namespace platform;
-using namespace viator;
-
-std::string const kApiUrl = "https://viatorapi.viator.com";
-std::string const kWebUrl = "https://www.partner.viator.com";
-
-int8_t GetLang(std::string const & lang)
-{
- return StringUtf8Multilang::GetLangIndex(lang);
-}
-
-using IdsMap = std::unordered_map<int8_t, std::string>;
-
-IdsMap const kApiKeys =
-{
- {GetLang("en"), VIATOR_API_KEY_EN},
- {GetLang("de"), VIATOR_API_KEY_DE},
- {GetLang("fr"), VIATOR_API_KEY_FR},
- {GetLang("es"), VIATOR_API_KEY_ES},
- {GetLang("pt"), VIATOR_API_KEY_PT},
- {GetLang("it"), VIATOR_API_KEY_IT},
- {GetLang("nl"), VIATOR_API_KEY_NL},
- {GetLang("sv"), VIATOR_API_KEY_SV},
- {GetLang("ja"), VIATOR_API_KEY_JA}
-};
-
-IdsMap const kAccountIds =
-{
- {GetLang("en"), VIATOR_ACCOUNT_ID_EN},
- {GetLang("de"), VIATOR_ACCOUNT_ID_DE},
- {GetLang("fr"), VIATOR_ACCOUNT_ID_FR},
- {GetLang("es"), VIATOR_ACCOUNT_ID_ES},
- {GetLang("pt"), VIATOR_ACCOUNT_ID_PT},
- {GetLang("it"), VIATOR_ACCOUNT_ID_IT},
- {GetLang("nl"), VIATOR_ACCOUNT_ID_NL},
- {GetLang("sv"), VIATOR_ACCOUNT_ID_SV},
- {GetLang("ja"), VIATOR_ACCOUNT_ID_JA}
-};
-
-std::unordered_set<std::string> const kSupportedCurrencies =
-{
- "USD", "GBP", "EUR", "AUD", "CAD", "NZD", "SGD", "HKD"
-};
-
-std::string GetId(IdsMap const & from)
-{
- int8_t const lang = GetLang(languages::GetCurrentNorm());
-
- auto const it = from.find(lang);
-
- if (it != from.cend())
- return it->second;
-
- LOG(LINFO, ("Viator key for language", lang, "is not found, English key will be used."));
- return from.at(StringUtf8Multilang::kEnglishCode);
-}
-
-std::string GetApiKey()
-{
- return GetId(kApiKeys);
-}
-
-std::string GetAccountId()
-{
- return GetId(kAccountIds);
-}
-
-bool RunSimpleHttpRequest(std::string const & url, std::string const & bodyData,
- std::string & result)
-{
- HttpClient request(url);
- request.SetHttpMethod("POST");
-
- request.SetBodyData(bodyData, "application/json");
- if (request.RunHttpRequest() && !request.WasRedirected() && request.ErrorCode() == 200)
- {
- result = request.ServerResponse();
- return true;
- }
-
- return false;
-}
-
-std::string MakeSearchProductsRequest(int destId, std::string const & currency, int count)
-{
- std::ostringstream os;
- // REVIEW_AVG_RATING_D - average traveler rating (high->low).
- os << R"({"topX":"1-)" << count << R"(","destId":)" << destId << R"(,"currencyCode":")"
- << currency << R"(","sortOrder":"REVIEW_AVG_RATING_D"})";
-
- return os.str();
-}
-
-std::string MakeUrl(std::string const & apiMethod)
-{
- std::ostringstream os;
- os << kApiUrl << apiMethod << "?apiKey=" << GetApiKey();
-
- return os.str();
-}
-
-bool CheckAnswer(base::Json const & root)
-{
- bool success;
- FromJSONObjectOptionalField(root.get(), "success", success);
-
- if (!success)
- {
- std::string errorMessage = "Unknown error.";
- auto const errorMessageArray = json_object_get(root.get(), "errorMessageText");
-
- if (json_array_size(errorMessageArray))
- FromJSON(json_array_get(errorMessageArray, 0), errorMessage);
-
- LOG(LWARNING, ("Viator retrieved unsuccessfull status, error message:", errorMessage));
- }
-
- return success;
-}
-
-void MakeProducts(std::string const & src, std::vector<Product> & products)
-{
- products.clear();
-
- base::Json root(src.c_str());
- auto const data = json_object_get(root.get(), "data");
- if (!CheckAnswer(root) || !json_array_size(data))
- return;
-
- auto const dataSize = json_array_size(data);
- for (size_t i = 0; i < dataSize; ++i)
- {
- Product product;
- auto const item = json_array_get(data, i);
- FromJSONObject(item, "shortTitle", product.m_title);
- FromJSONObject(item, "rating", product.m_rating);
- FromJSONObject(item, "reviewCount", product.m_reviewCount);
- FromJSONObject(item, "duration", product.m_duration);
- FromJSONObject(item, "price", product.m_price);
- FromJSONObject(item, "priceFormatted", product.m_priceFormatted);
- FromJSONObject(item, "currencyCode", product.m_currency);
- FromJSONObject(item, "thumbnailHiResURL", product.m_photoUrl);
- FromJSONObject(item, "webURL", product.m_pageUrl);
-
- // Rescale rating to [0.0; 10.0] range
- product.m_rating *= 2;
- products.push_back(move(product));
- }
-}
-} // namespace
-
-namespace viator
-{
-// static
-bool RawApi::GetTopProducts(std::string const & destId, std::string const & currency, int count,
- std::string & result)
-{
- int dest = 0;
- VERIFY(strings::to_int(destId, dest), ());
-
- return RunSimpleHttpRequest(MakeUrl("/service/search/products"),
- MakeSearchProductsRequest(dest, currency, count), result);
-}
-
-// static
-std::string Api::GetCityUrl(std::string const & destId)
-{
- std::ostringstream ost;
- // The final language and city name will be calculated automatically based on account id and
- // destination id.
- ost << kWebUrl << "/" << languages::GetCurrentNorm() << "/" << GetAccountId() << "/x/d" << destId
- << "-ttd?activities=all";
- return ost.str();
-}
-
-void Api::GetTop5Products(std::string const & destId, std::string const & currency,
- GetTop5ProductsCallback const & fn) const
-{
- std::string curr =
- kSupportedCurrencies.find(currency) == kSupportedCurrencies.cend() ? "USD" : currency;
-
- GetPlatform().RunTask(Platform::Thread::Network, [destId, curr, fn]()
- {
- string result;
- if (!RawApi::GetTopProducts(destId, curr, 5, result))
- return fn(destId, {});
-
- std::vector<Product> products;
- try
- {
- MakeProducts(result, products);
- }
- catch (base::Json::Exception const & e)
- {
- LOG(LERROR, (e.Msg()));
- products.clear();
- }
-
- SortProducts(products);
-
- fn(destId, products);
- });
-}
-
-bool operator<(Product const & lhs, Product const & rhs)
-{
- return lhs.m_rating < rhs.m_rating ||
- (lhs.m_rating == rhs.m_rating && lhs.m_reviewCount < rhs.m_reviewCount) ||
- (lhs.m_reviewCount == rhs.m_reviewCount && lhs.m_price < rhs.m_price);
-}
-
-// Sort by rating (from the best to the worst),
-// then by reviews (from the largest to the smallest),
-// then by price (from the biggest to the lowest)
-void SortProducts(std::vector<Product> & products)
-{
- std::multiset<Product> productsSet;
- for (auto const & p : products)
- productsSet.insert(p);
-
- std::copy(productsSet.crbegin(), productsSet.crend(), products.begin());
-}
-} // namespace viator
diff --git a/partners_api/viator_api.hpp b/partners_api/viator_api.hpp
deleted file mode 100644
index 437234f56f..0000000000
--- a/partners_api/viator_api.hpp
+++ /dev/null
@@ -1,49 +0,0 @@
-#pragma once
-
-#include "platform/safe_callback.hpp"
-
-#include <functional>
-#include <string>
-#include <vector>
-
-namespace viator
-{
-class RawApi
-{
-public:
- /// Returns top <count> products for specified city id.
- static bool GetTopProducts(std::string const & destId, std::string const & currency, int count,
- std::string & result);
-};
-
-struct Product
-{
- std::string m_title;
- double m_rating;
- int m_reviewCount;
- std::string m_duration;
- double m_price;
- std::string m_priceFormatted;
- std::string m_currency;
- std::string m_photoUrl;
- std::string m_pageUrl;
-};
-
-using GetTop5ProductsCallback =
- platform::SafeCallback<void(std::string const & destId, std::vector<Product> const & products)>;
-
-class Api
-{
-public:
- /// Returns web page address for specified city id.
- static std::string GetCityUrl(std::string const & destId);
-
- /// Returns top-5 products for specified city id.
- /// @currency - currency of the price, if empty then USD will be used.
- void GetTop5Products(std::string const & destId, std::string const & currency,
- GetTop5ProductsCallback const & fn) const;
-};
-
-bool operator<(Product const & lhs, Product const & rhs);
-void SortProducts(std::vector<Product> & products);
-} // namespace viator