#include "apiUrl.hpp" #include ApiUrl::ApiUrl(const std::string &iContentType, const std::string &iRegion) : mContentType{iContentType}, mRegion{iRegion} {} void ApiUrl::setRegion(const std::string &iRegion) { if (not iRegion.empty()) { mRegion = iRegion; //!< The region of the data to receive, e.g. "eu" } } void ApiUrl::setLocale(const std::string &iLocale) { if (not iLocale.empty()) { aParameters["locale"] = iLocale; //!< The locale to reflect in localized data, e.g. "fr_FR" or "ko_KR" //!< If you do not supply a value, all translations are returned. } } void ApiUrl::setGameMode(const std::string &iGameMode) { if (not iGameMode.empty()) { aParameters["gameMode"] = iGameMode; //!< A recognized game mode, e.g. "constructed" //!< @see https://community.developer.battle.net/documentation/hearthstone/guides/game-modes } } void ApiUrl::setPageSize(const std::string &iPageSize) { if (not iPageSize.empty()) { aParameters["pageSize"] = iPageSize; //!< The number of results to choose per page, e.g. "40" } } std::string ApiUrl::operator()() const { 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; }