forked from organicmaps/organicmaps
[partners_api] supported currencies + web url fix
This commit is contained in:
parent
85180ad797
commit
ae4c3f1db0
2 changed files with 57 additions and 7 deletions
|
@ -44,6 +44,49 @@ UNIT_TEST(Viator_GetTop5Products)
|
|||
|
||||
TEST_EQUAL(resultId, kSofia, ());
|
||||
TEST(!resultProducts.empty(), ());
|
||||
|
||||
for (auto const & p : resultProducts)
|
||||
TEST_EQUAL(p.m_currency, "USD", ());
|
||||
|
||||
resultId.clear();
|
||||
resultProducts.clear();
|
||||
|
||||
api.GetTop5Products(kSofia, "RUB",
|
||||
[&resultId, &resultProducts](std::string const & destId,
|
||||
std::vector<viator::Product> const & products) {
|
||||
resultId = destId;
|
||||
resultProducts = products;
|
||||
|
||||
testing::StopEventLoop();
|
||||
});
|
||||
|
||||
testing::RunEventLoop();
|
||||
|
||||
TEST_EQUAL(resultId, kSofia, ());
|
||||
TEST(!resultProducts.empty(), ());
|
||||
|
||||
for (auto const & p : resultProducts)
|
||||
TEST_EQUAL(p.m_currency, "USD", ());
|
||||
|
||||
resultId.clear();
|
||||
resultProducts.clear();
|
||||
|
||||
api.GetTop5Products(kSofia, "GBP",
|
||||
[&resultId, &resultProducts](std::string const & destId,
|
||||
std::vector<viator::Product> const & products) {
|
||||
resultId = destId;
|
||||
resultProducts = products;
|
||||
|
||||
testing::StopEventLoop();
|
||||
});
|
||||
|
||||
testing::RunEventLoop();
|
||||
|
||||
TEST_EQUAL(resultId, kSofia, ());
|
||||
TEST(!resultProducts.empty(), ());
|
||||
|
||||
for (auto const & p : resultProducts)
|
||||
TEST_EQUAL(p.m_currency, "GBP", ());
|
||||
}
|
||||
|
||||
UNIT_TEST(Viator_SortProducts)
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <set>
|
||||
#include <sstream>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "3party/jansson/myjansson.hpp"
|
||||
|
||||
|
@ -33,7 +34,7 @@ int8_t GetLang(std::string const & lang)
|
|||
|
||||
using IdsMap = std::unordered_map<int8_t, std::string>;
|
||||
|
||||
IdsMap kApiKeys =
|
||||
IdsMap const kApiKeys =
|
||||
{
|
||||
{GetLang("en"), VIATOR_API_KEY_EN},
|
||||
{GetLang("de"), VIATOR_API_KEY_DE},
|
||||
|
@ -46,7 +47,7 @@ IdsMap kApiKeys =
|
|||
{GetLang("ja"), VIATOR_API_KEY_JA}
|
||||
};
|
||||
|
||||
IdsMap kAccountIds =
|
||||
IdsMap const kAccountIds =
|
||||
{
|
||||
{GetLang("en"), VIATOR_ACCOUNT_ID_EN},
|
||||
{GetLang("de"), VIATOR_ACCOUNT_ID_DE},
|
||||
|
@ -59,6 +60,11 @@ IdsMap kAccountIds =
|
|||
{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());
|
||||
|
@ -184,7 +190,7 @@ bool RawApi::GetTopProducts(std::string const & destId, std::string const & curr
|
|||
std::string & result)
|
||||
{
|
||||
int dest = 0;
|
||||
CHECK(strings::to_int(destId, dest), ());
|
||||
VERIFY(strings::to_int(destId, dest), ());
|
||||
|
||||
return RunSimpleHttpRequest(MakeUrl("/service/search/products"),
|
||||
MakeSearchProductsRequest(dest, currency, count), result);
|
||||
|
@ -196,15 +202,16 @@ std::string Api::GetCityUrl(std::string const & destId, std::string const & name
|
|||
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() << "/" << name
|
||||
<< "/d" << destId << "-ttd?activities=all";
|
||||
return UrlEncode(ost.str());
|
||||
ost << kWebUrl << "/" << languages::GetCurrentNorm() << "/" << GetAccountId() << "/"
|
||||
<< UrlEncode(name) << "/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 = currency.empty() ? "USD" : currency;
|
||||
std::string curr =
|
||||
kSupportedCurrencies.find(currency) == kSupportedCurrencies.cend() ? "USD" : currency;
|
||||
|
||||
threads::SimpleThread([destId, curr, fn]()
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue