blob: e08c8c72c4e0b339f9940a7a9b3fd92dfd882421 (
plain)
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
|
#include "apiUrl.hpp"
#include <format>
ApiUrl::ApiUrl(const std::string &iContentType, const std::string &iRegion)
: mContentType{iContentType}, mRegion{iRegion} {}
void ApiUrl::setRegion(const std::string &iRegion) {
mRegion = iRegion; //<! eu
}
void ApiUrl::setLocale(const std::string &iLocale) {
aParameters["locale"] = iLocale; //<! fr_FR, ko_KR
}
void ApiUrl::setGameMode(const std::string &iGameMode) {
aParameters["gameMode"] = iGameMode; //<! constructed
}
std::string ApiUrl::operator()() {
std::string aFormattedParameters;
for (const auto &[key, value] : aParameters) {
aFormattedParameters += std::format("&{}={}", key, value);
}
if (not aFormattedParameters.empty()) {
aFormattedParameters[0] = '?';
}
aFormattedParameters =
std::format("https://{}.api.blizzard.com/hearthstone/{}/{}", mRegion, mContentType, aFormattedParameters);
return aFormattedParameters;
}
|