diff --git a/include/api.hpp b/include/api.hpp index d7c3fa5..6c45ab2 100644 --- a/include/api.hpp +++ b/include/api.hpp @@ -17,21 +17,76 @@ #ifndef MASTODONPP_API_HPP #define MASTODONPP_API_HPP -namespace mastodonpp::API +#include +#include +#include + +namespace mastodonpp { +using std::string; +using std::variant; + /*! - * @brief A list of all v1 API calls. - * - * The original `/` are substituted by `_`. + * @brief Holds API endpoints. * * @since 0.1.0 */ -enum class v1 +class API { - instance +public: + /*! + * @brief An enumeration of all v1 API endpoints. + * + * The original `/` are substituted with `_`. + * + * @since 0.1.0 + */ + enum class v1 + { + instance + }; + + /*! + * @brief An enumeration of all v2 API endpoints. + * + * The original `/` are substituted with `_`. + * + * @since 0.1.0 + */ + enum class v2 + { + search + }; + + /*! + * @brief Type for endpoints. Either API::v1 or API::v2. + * + * @since 0.1.0 + */ + using endpoint_type = variant; + + /*! + * @brief Constructs an API object. You should never need this. + * + * This constructor exists to hide away the class members, which are used + * internally. + * + * @since 0.1.0 + */ + explicit API(endpoint_type &endpoint); + + /*! + * @brief Convert #endpoint_type to string. + * + * @since 0.1.0 + */ + string to_string() const; + +private: + const endpoint_type _endpoint; }; -} // namespace mastodonpp::API +} // namespace mastodonpp #endif // MASTODONPP_API_HPP diff --git a/src/api.cpp b/src/api.cpp new file mode 100644 index 0000000..30a11b9 --- /dev/null +++ b/src/api.cpp @@ -0,0 +1,43 @@ +/* This file is part of mastodonpp. + * Copyright © 2020 tastytea + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "api.hpp" + +#include +#include +#include + +namespace mastodonpp +{ + +using std::map; +using std::string_view; +using std::move; + +API::API(endpoint_type &endpoint) + : _endpoint{move(endpoint)} +{} + +string API::to_string() const +{ + static const map endpoint_map + { + {v1::instance, "/api/v1/instance"}, + {v2::search, "/api/v2/search"} + }; + return endpoint_map.at(_endpoint).data(); +} +} // namespace mastodonpp