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.
- Parameters
-
hostname | The hostname of the instance. |
access_token | Your access token. |
- Since
- 0.1.0
31 , _baseuri{
"https://" + _hostname}
32 , _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.
Queries /api/v1/instance
for ‘max_toot_chars’. If the instance doesn't support it, the limit is assumed to be 500.
- Since
- 0.1.0
38 constexpr uint64_t default_max_chars{500};
44 debuglog <<
"Querying " << _hostname <<
" for max_toot_chars…\n";
46 _baseuri +
"/api/v1/instance", {})};
49 debuglog <<
"Could not get instance info.\n";
50 return default_max_chars;
53 _max_chars = [&answer]
55 auto &body{answer.body};
56 size_t pos_start{body.find(
"max_toot_chars")};
57 if (pos_start == string::npos)
59 debuglog <<
"max_toot_chars not found.\n";
60 return default_max_chars;
62 pos_start = body.find(
':', pos_start) + 1;
63 const size_t pos_end{body.find(
',', pos_start)};
65 const auto max_toot_chars{body.substr(pos_start,
66 pos_end - pos_start)};
67 return static_cast<uint64_t>(stoull(max_toot_chars));
69 debuglog <<
"Set _max_chars to: " << _max_chars <<
'\n';
71 catch (
const exception &e)
73 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
100 _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: