diff options
| author | Aotrix <[email protected]> | 2026-07-30 04:31:49 +0200 |
|---|---|---|
| committer | Aotrix <[email protected]> | 2026-07-30 04:31:49 +0200 |
| commit | 99421df7033148e6abb4e9f7a4d5d43f5cbd2ab4 (patch) | |
| tree | 8d03c98500709b6f1ef03b787fbde47ec2e0efaf /battleNetApi/src/apiUrl.cpp | |
| parent | 1fbfd13f5d7220122b2a127627cc9105013b4893 (diff) | |
Fixed tests for HearthstoneApi
Diffstat (limited to 'battleNetApi/src/apiUrl.cpp')
| -rw-r--r-- | battleNetApi/src/apiUrl.cpp | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/battleNetApi/src/apiUrl.cpp b/battleNetApi/src/apiUrl.cpp index fa07372..5ef109c 100644 --- a/battleNetApi/src/apiUrl.cpp +++ b/battleNetApi/src/apiUrl.cpp @@ -2,6 +2,20 @@ #include <cstdint> #include <format> +namespace bnet { +namespace { +std::string gamemodeToString(const GameMode &iGameMode) { + switch (iGameMode) { + case GameMode::constructed: + return "constructed"; + case GameMode::battlegrounds: + return "battlegrounds"; + case GameMode::mercenaries: + return "mercenaries"; + } +} +}; // namespace + ApiUrl::ApiUrl(const std::string &iContentType, const std::string &iRegion) : mContentType{iContentType}, mRegion{iRegion} {} void ApiUrl::setRegion(const std::string &iRegion) { @@ -16,13 +30,11 @@ void ApiUrl::setLocale(const std::string &iLocale) { setValue(kLOCALE_KEY, iLocale); } } -void ApiUrl::setGameMode(const std::string &iGameMode) { - if (not 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::setGameMode(const GameMode &iGameMode) { + //!< A recognized game mode, e.g. "constructed" + //!< @see + //!< https://community.developer.battle.net/documentation/hearthstone/guides/game-modes + setValue(kGAME_MODE_KEY, gamemodeToString(iGameMode)); } void ApiUrl::setPage(const std::string &iPage) { if (not iPage.empty()) { @@ -31,14 +43,8 @@ void ApiUrl::setPage(const std::string &iPage) { } } void ApiUrl::setPage(uint64_t iPage) { setPage(std::to_string(iPage)); } -void ApiUrl::setPageSize(const std::string &iPageSize) { - if (not iPageSize.empty()) { - //!< The number of results to choose per page, e.g. "40" - setValue(kPAGE_SIZE_KEY, iPageSize); - } -} void ApiUrl::setPageSize(uint64_t iPageSize) { - return setPageSize(std::to_string(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); } @@ -47,9 +53,7 @@ bool ApiUrl::hasPageSize() const { return hasValue(kPAGE_SIZE_KEY); } void ApiUrl::setValue(const std::string &iKey, const std::string &iValue) { aParameters[iKey] = iValue; } -bool ApiUrl::hasValue(const std::string &iKey) const { - return aParameters.count(iKey) > 0; -} +bool ApiUrl::hasValue(const std::string &iKey) const { return aParameters.count(iKey) > 0; } std::string ApiUrl::text() const { std::string aFormattedParameters; for (const auto &[key, value] : aParameters) { @@ -58,8 +62,8 @@ std::string ApiUrl::text() const { if (not aFormattedParameters.empty()) { aFormattedParameters[0] = '?'; } - aFormattedParameters = - std::format("https://{}.api.blizzard.com/hearthstone/{}/{}", mRegion, - mContentType, aFormattedParameters); + aFormattedParameters = std::format("https://{}.api.blizzard.com/hearthstone/{}/{}", mRegion, + mContentType, aFormattedParameters); return aFormattedParameters; } +}; // namespace bnet |
