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:
55  explicit Instance(string_view hostname, string_view access_token);
56 
62  [[nodiscard]]
63  inline string_view get_hostname() const
64  {
65  return _hostname;
66  }
67 
75  [[nodiscard]]
76  inline string_view get_baseuri() const
77  {
78  return _baseuri;
79  }
80 
86  [[nodiscard]]
87  inline string_view get_access_token() const
88  {
89  return _access_token;
90  }
91 
100  inline void set_access_token(string access_token)
101  {
102  _access_token = move(access_token);
103  }
104 
110  [[nodiscard]]
111  uint64_t get_max_chars();
112 
118  void set_proxy(const string_view proxy)
119  {
120  _proxy = proxy;
121  CURLWrapper::set_proxy(proxy);
122  }
123 
131  [[nodiscard]]
132  string_view get_proxy() const
133  {
134  return _proxy;
135  }
136 
137 private:
138  const string _hostname;
139  const string _baseuri;
140  string _access_token;
141  uint64_t _max_chars;
142  string _proxy;
143 };
144 
145 } // namespace mastodonpp
146 
147 #endif // MASTODONPP_INSTANCE_HPP
mastodonpp::Instance::get_proxy
string_view get_proxy() const
Returns the proxy string that was previously set.
Definition: instance.hpp:132
mastodonpp::Instance::get_access_token
string_view get_access_token() const
Returns the access token.
Definition: instance.hpp:87
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:33
mastodonpp::Instance::set_access_token
void set_access_token(string access_token)
Set OAuth 2.0 Bearer Access Token.
Definition: instance.hpp:100
mastodonpp::Instance::Instance
Instance(string_view hostname, string_view access_token)
Construct a new Instance object.
Definition: instance.cpp:26
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:118
mastodonpp::Instance::get_baseuri
string_view get_baseuri() const
Returns the base URI.
Definition: instance.hpp:76
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:63