1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
#include "apiUrl.hpp"
#include <cstdint>
#include <format>
namespace bnet
{
ApiUrl::ApiUrl(const std::string& iContentType,
const std::string& iRegion)
: mContentType{iContentType},
mRegion{iRegion}
{
}
void ApiUrl::setRegion(const std::string& iRegion)
{
if (!iRegion.empty())
{
mRegion = iRegion; //!< The region of the data to receive, e.g. "eu"
}
}
void ApiUrl::setLocale(const std::string& iLocale)
{
if (!iLocale.empty())
{
//!< The locale to reflect in localized data, e.g. "fr_FR" or "ko_KR"
//!< If you do !supply a value, all translations are returned.
setValue(kLOCALE_KEY, iLocale);
}
}
void ApiUrl::setGameMode(const std::string& iGameMode)
{
if (!iGameMode.empty())
{
//!< A recognized game mode, e.g. "constructed"
//!< @see
//!< https://community.developer.battle.net/documentation/hearthstone/guides/game-modes
setValue(kGAME_MODE_KEY, iGameMode);
}
}
void ApiUrl::setPage(uint64_t iPage)
{
//!< The page to retrieve, e.g. "9"
setValue(kPAGE_KEY, std::to_string(iPage));
}
void ApiUrl::setPageSize(uint64_t iPageSize)
{
setValue(kPAGE_SIZE_KEY, std::to_string(iPageSize));
}
bool ApiUrl::hasLocale() const
{
return hasValue(kLOCALE_KEY);
}
bool ApiUrl::hasGameMode() const
{
return hasValue(kGAME_MODE_KEY);
}
bool ApiUrl::hasPage() const
{
return hasValue(kPAGE_KEY);
}
bool ApiUrl::hasPageSize() const
{
return hasValue(kPAGE_SIZE_KEY);
}
void ApiUrl::setValue(std::string_view iKey,
const std::string& iValue)
{
aParameters[iKey] = std::move(iValue);
}
bool ApiUrl::hasValue(std::string_view iKey) const
{
return aParameters.count(iKey) > 0;
}
std::string ApiUrl::text() const
{
std::string aFormattedParameters;
for (const auto& [key, value] : aParameters)
{
aFormattedParameters += std::format("&{}={}", key, value);
}
if (!aFormattedParameters.empty())
{
aFormattedParameters[0] = '?';
}
aFormattedParameters = std::format("https://{}.api.blizzard.com/hearthstone/{}/{}", mRegion,
mContentType, aFormattedParameters);
return aFormattedParameters;
}
}; // namespace bnet
|