Holds the access data of an instance.
More...
#include <mastodonpp/instance.hpp>
Holds the access data of an instance.
- Since
- 0.1.0
◆ Instance()
mastodonpp::Instance::Instance |
( |
string_view |
hostname, |
|
|
string_view |
access_token |
|
) |
| |
|
explicit |
Construct a new Instance object.
Also queries /api/v1/instance
for ‘max_toot_chars’.
- Parameters
-
hostname | The hostname of the instance. |
access_token | Your access token. |
- Since
- 0.1.0
28 , _baseuri{
"https://" + _hostname}
29 , _access_token{access_token}
◆ get_access_token()
string_view mastodonpp::Instance::get_access_token |
( |
| ) |
const |
|
inline |
Returns the access token.
- Since
- 0.1.0
◆ get_baseuri()
string_view mastodonpp::Instance::get_baseuri |
( |
| ) |
const |
|
inline |
Returns the base URI.
The base URI is “https://” + the hostname.
- Since
- 0.1.0
◆ get_hostname()
string_view mastodonpp::Instance::get_hostname |
( |
| ) |
const |
|
inline |
Returns the hostname.
- Since
- 0.1.0
◆ get_max_chars()
uint64_t mastodonpp::Instance::get_max_chars |
( |
| ) |
|
Returns the maximum number of characters per post.
- Since
- 0.1.0
35 constexpr uint64_t default_max_chars{500};
41 debuglog <<
"Querying " << _hostname <<
" for max_toot_chars…\n";
43 _baseuri +
"/api/v1/instance", {})};
46 debuglog <<
"Could not get instance info.\n";
47 return default_max_chars;
50 _max_chars = [&answer]
52 auto &body{answer.body};
53 size_t pos_start{body.find(
"max_toot_chars")};
54 if (pos_start == string::npos)
56 debuglog <<
"max_toot_chars not found.\n";
57 return default_max_chars;
59 pos_start = body.find(
':', pos_start) + 1;
60 const size_t pos_end{body.find(
',', pos_start)};
62 const auto max_toot_chars{body.substr(pos_start,
63 pos_end - pos_start)};
64 return static_cast<uint64_t>(stoull(max_toot_chars));
66 debuglog <<
"Set _max_chars to: " << _max_chars <<
'\n';
68 catch (
const std::exception &e)
70 debuglog <<
"Unexpected exception: " << e.what() <<
'\n';
◆ get_proxy()
string_view mastodonpp::Instance::get_proxy |
( |
| ) |
const |
|
inline |
Returns the proxy string that was previously set.
Does not return the proxy if it was set from an environment variable.
- Since
- 0.1.0
◆ set_access_token()
void mastodonpp::Instance::set_access_token |
( |
string |
access_token | ) |
|
|
inline |
Set OAuth 2.0 Bearer Access Token.
Sets also the access token for all Connections that are initialized with this Instance afterwards.
- Since
- 0.1.0
102 _access_token = move(access_token);
◆ set_proxy()
void mastodonpp::Instance::set_proxy |
( |
const string_view |
proxy | ) |
|
|
inline |
Set the proxy to use.
See CURLOPT_PROXY(3).
- Parameters
-
proxy | Examples: "socks4a://127.0.0.1:9050", "http://[::1]:3128". |
- Since
- 0.1.0
Sets also the proxy for all Connections that are initialized with this Instance afterwards.
The documentation for this class was generated from the following files: