mastodonpp  0.0.0
connection.hpp
1 /* This file is part of mastodonpp.
2  * Copyright © 2020 tastytea <tastytea@tastytea.de>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Affero General Public License as published by
6  * the Free Software Foundation, version 3.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Affero General Public License for more details.
12  *
13  * You should have received a copy of the GNU Affero General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #ifndef MASTODONPP_CONNECTION_HPP
18 #define MASTODONPP_CONNECTION_HPP
19 
20 #include "answer.hpp"
21 #include "api.hpp"
22 #include "curl_wrapper.hpp"
23 #include "instance.hpp"
24 
25 #include <string>
26 #include <string_view>
27 #include <variant>
28 
29 namespace mastodonpp
30 {
31 
32 using std::string;
33 using std::string_view;
34 using std::variant;
35 
41 using endpoint_variant = variant<API::endpoint_type,string_view>;
42 
50 class Connection : public CURLWrapper
51 {
52 public:
60  explicit Connection(Instance &instance);
61 
80  [[nodiscard]]
81  answer_type get(const endpoint_variant &endpoint,
82  const parametermap &parameters);
83 
96  [[nodiscard]]
97  inline answer_type get(const endpoint_variant &endpoint)
98  {
99  return get(endpoint, {});
100  }
101 
107  void set_proxy(string_view proxy);
108 
118  string get_new_stream_contents();
119 
120 private:
121  Instance &_instance;
122  const string_view _baseuri;
123 };
124 
125 } // namespace mastodonpp
126 
127 #endif // MASTODONPP_CONNECTION_HPP
mastodonpp::Connection::get
answer_type get(const endpoint_variant &endpoint, const parametermap &parameters)
Make a HTTP GET call with parameters.
Definition: connection.cpp:29
mastodonpp::parametermap
map< string_view, variant< string_view, vector< string_view > >> parametermap
std::map of parameters for API calls.
Definition: curl_wrapper.hpp:69
mastodonpp::Connection::set_proxy
void set_proxy(string_view proxy)
Set the proxy to use.
Definition: connection.cpp:45
mastodonpp::Connection::Connection
Connection(Instance &instance)
Construct a new Connection object.
Definition: connection.cpp:24
mastodonpp::Connection::get
answer_type get(const endpoint_variant &endpoint)
Make a HTTP GET call.
Definition: connection.hpp:97
mastodonpp
C++ wrapper for the Mastodon API.
Definition: answer.cpp:19
mastodonpp::endpoint_variant
variant< API::endpoint_type, string_view > endpoint_variant
An endpoint. Either API::endpoint_type or std::string_view.
Definition: connection.hpp:41
mastodonpp::answer_type
Return type for Requests.
Definition: answer.hpp:40
mastodonpp::Instance
Holds the access data of an instance.
Definition: instance.hpp:40
mastodonpp::Connection
Represents a connection to an instance. Used for requests.
Definition: connection.hpp:50
mastodonpp::CURLWrapper
Handles the details of network connections.
Definition: curl_wrapper.hpp:80
mastodonpp::Connection::get_new_stream_contents
string get_new_stream_contents()
Copy new stream contents and delete the “original”.
Definition: connection.cpp:51