diff options
author | tastytea | 2020-01-03 12:42:10 +0100 |
---|---|---|
committer | tastytea | 2020-01-03 12:42:10 +0100 |
commit | 4c557aae6eff2023aadfc8f0cd393bbbf35096d5 (patch) | |
tree | cd689c3b9a7ea2639bc49023d7ca97b73068d541 | |
parent | 1d3275e429a58a6e1949d13ddb32433dc2724526 (diff) | |
download | mastodonpp-4c557aae6eff2023aadfc8f0cd393bbbf35096d5.tar mastodonpp-4c557aae6eff2023aadfc8f0cd393bbbf35096d5.tar.gz mastodonpp-4c557aae6eff2023aadfc8f0cd393bbbf35096d5.zip |
Use Instance and Request classes.
-rw-r--r-- | include/instance.hpp | 49 | ||||
-rw-r--r-- | include/mastodonpp.hpp | 31 | ||||
-rw-r--r-- | include/request.hpp | 36 | ||||
-rw-r--r-- | src/instance.cpp | 31 | ||||
-rw-r--r-- | src/mastodonpp.cpp | 7 | ||||
-rw-r--r-- | src/request.cpp | 26 | ||||
-rw-r--r-- | tests/test_instanciation.cpp | 27 |
7 files changed, 169 insertions, 38 deletions
diff --git a/include/instance.hpp b/include/instance.hpp new file mode 100644 index 0000000..c7be1cd --- /dev/null +++ b/include/instance.hpp @@ -0,0 +1,49 @@ +/* This file is part of mastodonpp. + * Copyright © 2020 tastytea <tastytea@tastytea.de> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef MASTODONPP_INSTANCE_HPP +#define MASTODONPP_INSTANCE_HPP + +#include <string> + +namespace mastodonpp +{ + +using std::string; + +class Instance +{ +public: + /*! + * @brief Construct a new Instance object. + * + * Holds the hostname and access token of the instance. + * + * @param instance The hostname of the instance. + * @param access_token Your access token. + * + * @since 0.1.0 + */ + explicit Instance(string instance, string access_token); + +private: + const string _instance; + string _access_token; +}; + +} // namespace mastodonpp + +#endif // MASTODONPP_INSTANCE_HPP diff --git a/include/mastodonpp.hpp b/include/mastodonpp.hpp index 080d4b2..0b7afc4 100644 --- a/include/mastodonpp.hpp +++ b/include/mastodonpp.hpp @@ -17,8 +17,8 @@ #ifndef MASTODONPP_HPP #define MASTODONPP_HPP +#include "instance.hpp" #include "return_types.hpp" -#include <string> /*! * @mainpage mastodonpp Reference @@ -43,44 +43,21 @@ * @section Example * * @code - * mastodonpp::API masto("example.com", ""); + * mastodonpp::Instance instance{"example.com", ""}; * @endcode */ -namespace mastodonpp -{ - -using std::string; - /*! * @brief C++ wrapper for the Mastodon API. * * All text input is expected to be UTF-8. * * @since 0.1.0 - * */ - -class API +namespace mastodonpp { -public: - /*! - * @brief Construct a new API object. - * - * To register your application, leave access_token blank and call - * API::register_app1() and API::register_app2(). - * - * @param instance The hostname of your instance. - * @param access_token Your access token. - * - * @since 0.1.0 - */ - explicit API(string instance, string access_token); -private: - const string _instance; - const string _access_token; -}; + } // namespace mastodonpp diff --git a/include/request.hpp b/include/request.hpp new file mode 100644 index 0000000..97aa2ec --- /dev/null +++ b/include/request.hpp @@ -0,0 +1,36 @@ +/* This file is part of mastodonpp. + * Copyright © 2020 tastytea <tastytea@tastytea.de> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef MASTODONPP_REQUEST_HPP +#define MASTODONPP_REQUEST_HPP + +#include "instance.hpp" + +namespace mastodonpp +{ + +class Request +{ +public: + explicit Request(Instance &instance); + +private: + Instance &_instance; +}; + +} // namespace mastodonpp + +#endif // MASTODONPP_REQUEST_HPP diff --git a/src/instance.cpp b/src/instance.cpp new file mode 100644 index 0000000..6b3443d --- /dev/null +++ b/src/instance.cpp @@ -0,0 +1,31 @@ +/* This file is part of mastodonpp. + * Copyright © 2020 tastytea <tastytea@tastytea.de> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#include "instance.hpp" + +#include <utility> + +namespace mastodonpp +{ + +using std::move; + +Instance::Instance(string instance, string access_token) + : _instance{move(instance)} + , _access_token{move(access_token)} +{} + +} // namespace mastodonpp diff --git a/src/mastodonpp.cpp b/src/mastodonpp.cpp index 7890ed6..99f2b27 100644 --- a/src/mastodonpp.cpp +++ b/src/mastodonpp.cpp @@ -16,16 +16,9 @@ #include "mastodonpp.hpp" -#include <utility> - namespace mastodonpp { -using std::move; -API::API(string instance, string access_token) - : _instance{move(instance)} - , _access_token{move(access_token)} -{} } // namespace mastodonpp diff --git a/src/request.cpp b/src/request.cpp new file mode 100644 index 0000000..26056fc --- /dev/null +++ b/src/request.cpp @@ -0,0 +1,26 @@ +/* This file is part of mastodonpp. + * Copyright © 2020 tastytea <tastytea@tastytea.de> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#include "request.hpp" + +namespace mastodonpp +{ + +Request::Request(Instance &instance) + : _instance{instance} +{} + +} // namespace mastodonpp diff --git a/tests/test_instanciation.cpp b/tests/test_instanciation.cpp index 3fbc0f3..3bd73ec 100644 --- a/tests/test_instanciation.cpp +++ b/tests/test_instanciation.cpp @@ -14,7 +14,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "mastodonpp.hpp" +#include "instance.hpp" +#include "request.hpp" #include <catch.hpp> @@ -26,15 +27,33 @@ namespace mastodonpp using std::string; -SCENARIO ("API can be instantiated.") +SCENARIO ("Instantiations.") { bool exception = false; - GIVEN ("One instanciation.") + WHEN ("Instance is instantiated.") { try { - API masto("example.com", ""); + Instance instance{"example.com", ""}; + } + catch (const std::exception &e) + { + exception = true; + } + + THEN ("No exception is thrown") + { + REQUIRE_FALSE(exception); + } + } + + WHEN ("Request is instantiated.") + { + try + { + Instance instance{"example.com", ""}; + Request request{instance}; } catch (const std::exception &e) { |