From f8727070361958a73e1d30dd39be824a674483b3 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 5 Jan 2020 09:38:13 +0100 Subject: Renamed “Request” to “Connection”. It will be used not for only one request, but for all requests to an instance. --- include/connection.hpp | 78 ++++++++++++++++++++++++++++++++++++++++++++ include/mastodonpp.hpp | 2 +- include/request.hpp | 78 -------------------------------------------- src/connection.cpp | 40 +++++++++++++++++++++++ src/request.cpp | 40 ----------------------- tests/test_instanciation.cpp | 6 ++-- 6 files changed, 122 insertions(+), 122 deletions(-) create mode 100644 include/connection.hpp delete mode 100644 include/request.hpp create mode 100644 src/connection.cpp delete mode 100644 src/request.cpp diff --git a/include/connection.hpp b/include/connection.hpp new file mode 100644 index 0000000..1db8286 --- /dev/null +++ b/include/connection.hpp @@ -0,0 +1,78 @@ +/* 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 . + */ + +#ifndef MASTODONPP_CONNECTION_HPP +#define MASTODONPP_CONNECTION_HPP + +#include "api.hpp" +#include "curl_wrapper.hpp" +#include "instance.hpp" +#include "return_types.hpp" + +#include + +namespace mastodonpp +{ + +using std::string; + +/*! + * @brief Represents a connection to an instance. Used for requests. + * + * @since 0.1.0 + * + * @headerfile connection.hpp mastodonpp/connection.hpp + */ +class Connection : public CURLWrapper +{ +public: + /*! + * @brief Construct a new Connection object. + * + * @param instance An Instance with the access data. + * + * @since 0.1.0 + */ + explicit Connection(Instance &instance); + + /*! + * @brief Make a HTTP GET call. + * + * @param endpoint Endpoint as API::endpoint_type, for example: + * `mastodonpp::API::v1::instance`. + * + * @since 0.1.0 + */ + [[nodiscard]] + answer_type get(API::endpoint_type endpoint); + + /*! + * @brief Make a HTTP GET call. + * + * @param endpoint Endpoint as string, for example: "/api/v1/instance". + * + * @since 0.1.0 + */ + [[nodiscard]] + answer_type get(string endpoint); + +private: + Instance &_instance; +}; + +} // namespace mastodonpp + +#endif // MASTODONPP_CONNECTION_HPP diff --git a/include/mastodonpp.hpp b/include/mastodonpp.hpp index 8b7ed45..2c24c85 100644 --- a/include/mastodonpp.hpp +++ b/include/mastodonpp.hpp @@ -20,7 +20,7 @@ #include "api.hpp" #include "exceptions.hpp" #include "instance.hpp" -#include "request.hpp" +#include "connection.hpp" #include "return_types.hpp" /*! diff --git a/include/request.hpp b/include/request.hpp deleted file mode 100644 index 36d4f41..0000000 --- a/include/request.hpp +++ /dev/null @@ -1,78 +0,0 @@ -/* 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 . - */ - -#ifndef MASTODONPP_REQUEST_HPP -#define MASTODONPP_REQUEST_HPP - -#include "api.hpp" -#include "curl_wrapper.hpp" -#include "instance.hpp" -#include "return_types.hpp" - -#include - -namespace mastodonpp -{ - -using std::string; - -/*! - * @brief Used to make a request to the Mastodon %API. - * - * @since 0.1.0 - * - * @headerfile request.hpp mastodonpp/request.hpp - */ -class Request : public CURLWrapper -{ -public: - /*! - * @brief Construct a new Request object. - * - * @param instance An Instance with the access data. - * - * @since 0.1.0 - */ - explicit Request(Instance &instance); - - /*! - * @brief Make a HTTP GET call. - * - * @param endpoint Endpoint as API::endpoint_type, for example: - * `mastodonpp::API::v1::instance`. - * - * @since 0.1.0 - */ - [[nodiscard]] - answer_type get(API::endpoint_type endpoint); - - /*! - * @brief Make a HTTP GET call. - * - * @param endpoint Endpoint as string, for example: "/api/v1/instance". - * - * @since 0.1.0 - */ - [[nodiscard]] - answer_type get(string endpoint); - -private: - Instance &_instance; -}; - -} // namespace mastodonpp - -#endif // MASTODONPP_REQUEST_HPP diff --git a/src/connection.cpp b/src/connection.cpp new file mode 100644 index 0000000..b7fe886 --- /dev/null +++ b/src/connection.cpp @@ -0,0 +1,40 @@ +/* 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 "connection.hpp" + +namespace mastodonpp +{ + +Connection::Connection(Instance &instance) + : _instance{instance} +{} + +answer_type Connection::get(API::endpoint_type endpoint) +{ + answer_type answer; + answer.body = API{endpoint}.to_string(); + return answer; +} + +answer_type Connection::get(string endpoint) +{ + answer_type answer; + answer.body = make_request(http_method::GET, "https://ip.tastytea.de/"); + return answer; +} + +} // namespace mastodonpp diff --git a/src/request.cpp b/src/request.cpp deleted file mode 100644 index 1e91504..0000000 --- a/src/request.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* 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 "request.hpp" - -namespace mastodonpp -{ - -Request::Request(Instance &instance) - : _instance{instance} -{} - -answer_type Request::get(API::endpoint_type endpoint) -{ - answer_type answer; - answer.body = API{endpoint}.to_string(); - return answer; -} - -answer_type Request::get(string endpoint) -{ - answer_type answer; - answer.body = make_request(http_method::GET, "https://ip.tastytea.de/"); - return answer; -} - -} // namespace mastodonpp diff --git a/tests/test_instanciation.cpp b/tests/test_instanciation.cpp index 3bd73ec..bde806a 100644 --- a/tests/test_instanciation.cpp +++ b/tests/test_instanciation.cpp @@ -15,7 +15,7 @@ */ #include "instance.hpp" -#include "request.hpp" +#include "connection.hpp" #include @@ -48,12 +48,12 @@ SCENARIO ("Instantiations.") } } - WHEN ("Request is instantiated.") + WHEN ("Connection is instantiated.") { try { Instance instance{"example.com", ""}; - Request request{instance}; + Connection connection{instance}; } catch (const std::exception &e) { -- cgit v1.2.3-54-g00ecf