mastodonpp  0.2.0
instance.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_INSTANCE_HPP
18 #define MASTODONPP_INSTANCE_HPP
19 
20 #include "curl_wrapper.hpp"
21 
22 #include <cstdint>
23 #include <string>
24 #include <string_view>
25 #include <utility>
26 
27 namespace mastodonpp
28 {
29 
30 using std::uint64_t;
31 using std::string;
32 using std::string_view;
33 using std::move;
34 
42 class Instance : public CURLWrapper
43 {
44 public:
53  explicit Instance(string_view hostname, string_view access_token);
54 
60  [[nodiscard]]
61  inline string_view get_hostname() const
62  {
63  return _hostname;
64  }
65 
73  [[nodiscard]]
74  inline string_view get_baseuri() const
75  {
76  return _baseuri;
77  }
78 
84  [[nodiscard]]
85  inline string_view get_access_token() const
86  {
87  return _access_token;
88  }
89 
98  inline void set_access_token(string access_token)
99  {
100  _access_token = move(access_token);
101  }
102 
111  [[nodiscard]]
112  uint64_t get_max_chars();
113 
119  void set_proxy(const string_view proxy)
120  {
121  _proxy = proxy;
122  CURLWrapper::set_proxy(proxy);
123  }
124 
132  [[nodiscard]]
133  string_view get_proxy() const
134  {
135  return _proxy;
136  }
137 
138 private:
139  const string _hostname;
140  const string _baseuri;
141  string _access_token;
142  uint64_t _max_chars;
143  string _proxy;
144 };
145 
146 } // namespace mastodonpp
147 
148 #endif // MASTODONPP_INSTANCE_HPP
mastodonpp::Instance::get_proxy
string_view get_proxy() const
Returns the proxy string that was previously set.
Definition: instance.hpp:133
mastodonpp::Instance::get_access_token
string_view get_access_token() const
Returns the access token.
Definition: instance.hpp:85
mastodonpp
C++ wrapper for the Mastodon API.
Definition: answer.cpp:22
mastodonpp::Instance::get_max_chars
uint64_t get_max_chars()
Returns the maximum number of characters per post.
Definition: instance.cpp:36
mastodonpp::Instance::set_access_token
void set_access_token(string access_token)
Set OAuth 2.0 Bearer Access Token.
Definition: instance.hpp:98
mastodonpp::Instance::Instance
Instance(string_view hostname, string_view access_token)
Construct a new Instance object.
Definition: instance.cpp:29
mastodonpp::CURLWrapper::set_proxy
void set_proxy(string_view proxy)
Set the proxy to use.
Definition: curl_wrapper.cpp:67
mastodonpp::Instance::set_proxy
void set_proxy(const string_view proxy)
Set the proxy to use.
Definition: instance.hpp:119
mastodonpp::Instance::get_baseuri
string_view get_baseuri() const
Returns the base URI.
Definition: instance.hpp:74
mastodonpp::Instance
Holds the access data of an instance.
Definition: instance.hpp:42
mastodonpp::CURLWrapper
Handles the details of network connections.
Definition: curl_wrapper.hpp:96
mastodonpp::Instance::get_hostname
string_view get_hostname() const
Returns the hostname.
Definition: instance.hpp:61