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 #include <vector>
29 
30 namespace mastodonpp
31 {
32 
33 using std::string;
34 using std::string_view;
35 using std::variant;
36 using std::vector;
37 
43 using endpoint_variant = variant<API::endpoint_type,string_view>;
44 
52 struct event_type
53 {
62  string type;
63 
65  string data;
66 };
67 
75 class Connection : public CURLWrapper
76 {
77 public:
85  explicit Connection(Instance &instance);
86 
105  [[nodiscard]]
106  answer_type get(const endpoint_variant &endpoint,
107  const parametermap &parameters);
108 
121  [[nodiscard]]
122  inline answer_type get(const endpoint_variant &endpoint)
123  {
124  return get(endpoint, {});
125  }
126 
138  string get_new_stream_contents();
139 
145  vector<event_type> get_new_events();
146 
147 private:
148  Instance &_instance;
149  const string_view _baseuri;
150 };
151 
152 } // namespace mastodonpp
153 
154 #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:35
mastodonpp::event_type::type
string type
The type of the event.
Definition: connection.hpp:62
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::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:122
mastodonpp::event_type::data
string data
The payload.
Definition: connection.hpp:65
mastodonpp
C++ wrapper for the Mastodon API.
Definition: answer.cpp:22
mastodonpp::Connection::get_new_events
vector< event_type > get_new_events()
Get new stream events.
Definition: connection.cpp:61
mastodonpp::endpoint_variant
variant< API::endpoint_type, string_view > endpoint_variant
An endpoint. Either API::endpoint_type or std::string_view.
Definition: connection.hpp:43
mastodonpp::event_type
A stream event.
Definition: connection.hpp:52
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:75
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