summaryrefslogtreecommitdiff
path: root/battleNetApi/src/apiUrl.cpp
diff options
context:
space:
mode:
authorAotrix <[email protected]>2026-10-10 16:09:48 +0200
committerAotrix <[email protected]>2026-10-10 16:09:48 +0200
commitc777502a1c22b240f66069831e6f0cb1e7e41b64 (patch)
tree6201b076b88ba6c50c4654b6da7abf8b5cda8267 /battleNetApi/src/apiUrl.cpp
parent326f6cb61773c82182d91142749072aa3ca4c450 (diff)
Use string_view and delete gameViewHEADmaster
Diffstat (limited to 'battleNetApi/src/apiUrl.cpp')
-rw-r--r--battleNetApi/src/apiUrl.cpp94
1 files changed, 68 insertions, 26 deletions
diff --git a/battleNetApi/src/apiUrl.cpp b/battleNetApi/src/apiUrl.cpp
index 8775943..bc54330 100644
--- a/battleNetApi/src/apiUrl.cpp
+++ b/battleNetApi/src/apiUrl.cpp
@@ -2,54 +2,96 @@
#include <cstdint>
#include <format>
-namespace bnet {
+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()) {
+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()) {
+
+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()) {
+
+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(const std::string &iPage) {
- if (!iPage.empty()) {
- //!< The page to retrieve, e.g. "9"
- setValue(kPAGE_KEY, iPage);
- }
+
+void ApiUrl::setPage(uint64_t iPage)
+{
+ //!< The page to retrieve, e.g. "9"
+ setValue(kPAGE_KEY, std::to_string(iPage));
}
-void ApiUrl::setPage(uint64_t iPage) { setPage(std::to_string(iPage)); }
-void ApiUrl::setPageSize(uint64_t iPageSize) {
+
+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(const std::string &iKey, const std::string &iValue) {
- aParameters[iKey] = iValue;
+
+bool ApiUrl::hasLocale() const
+{
+ return hasValue(kLOCALE_KEY);
+}
+
+bool ApiUrl::hasGameMode() const
+{
+ return hasValue(kGAME_MODE_KEY);
}
-bool ApiUrl::hasValue(const std::string &iKey) const { return aParameters.count(iKey) > 0; }
-std::string ApiUrl::text() const {
+
+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) {
+ for (const auto& [key, value] : aParameters)
+ {
aFormattedParameters += std::format("&{}={}", key, value);
}
- if (!aFormattedParameters.empty()) {
+ if (!aFormattedParameters.empty())
+ {
aFormattedParameters[0] = '?';
}
aFormattedParameters = std::format("https://{}.api.blizzard.com/hearthstone/{}/{}", mRegion,