mastodonpp  0.4.0
Classes | Public Member Functions | List of all members
mastodonpp::Instance Class Reference

Holds the access data of an instance. More...

#include <mastodonpp/instance.hpp>

Inheritance diagram for mastodonpp::Instance:
mastodonpp::CURLWrapper

Classes

class  ObtainToken
 Simplifies obtaining an OAuth 2.0 Bearer Access Token. More...
 

Public Member Functions

 Instance (const string_view hostname, const string_view access_token)
 Construct a new Instance object. More...
 
void copy_connection_properties (CURLWrapper &curlwrapper)
 Set the properties of the connection of the calling class up. More...
 
string_view get_hostname () const noexcept
 Returns the hostname. More...
 
string_view get_baseuri () const noexcept
 Returns the base URI. More...
 
string_view get_access_token () const noexcept
 Returns the access token. More...
 
void set_access_token (string access_token)
 Set OAuth 2.0 Bearer Access Token. More...
 
uint64_t get_max_chars () noexcept
 Returns the maximum number of characters per post. More...
 
void set_proxy (const string_view proxy)
 Set the proxy to use. More...
 
answer_type get_nodeinfo ()
 Returns the NodeInfo of the instance. More...
 
vector< string > get_post_formats () noexcept
 Returns the allowed mime types for statuses. More...
 
void set_cainfo (string_view path)
 Set path to Certificate Authority (CA) bundle. More...
 
void set_useragent (const string_view useragent)
 Sets the User-Agent. More...
 
- Public Member Functions inherited from mastodonpp::CURLWrapper
 CURLWrapper ()
 Initializes curl and sets up connection. More...
 
 CURLWrapper (const CURLWrapper &other)=delete
 Copy constructor. More...
 
 CURLWrapper (CURLWrapper &&other) noexcept=delete
 Move constructor. More...
 
virtual ~CURLWrapper () noexcept
 Cleans up curl and connection. More...
 
CURLWrapperoperator= (const CURLWrapper &other)=delete
 Copy assignment operator. More...
 
CURLWrapperoperator= (CURLWrapper &&other) noexcept=delete
 Move assignment operator. More...
 
CURL * get_curl_easy_handle ()
 Returns pointer to the CURL easy handle. More...
 
string escape_url (const string_view url) const
 URL encodes the given string. More...
 
string unescape_url (const string_view url) const
 URL decodes the given string . More...
 
void setup_connection_properties (string_view proxy, string_view access_token, string_view cainfo, string_view useragent)
 Set some properties of the connection. More...
 

Additional Inherited Members

- Protected Member Functions inherited from mastodonpp::CURLWrapper
answer_type make_request (const http_method &method, string uri, const parametermap &parameters)
 Make a HTTP request. More...
 
string & get_buffer ()
 Returns a reference to the buffer libcurl writes into. More...
 
void cancel_stream ()
 Cancel the stream. More...
 
void set_proxy (string_view proxy)
 Set the proxy to use. More...
 
void set_access_token (string_view access_token)
 Set OAuth 2.0 Bearer Access Token. More...
 
void set_cainfo (string_view path)
 Set path to Certificate Authority (CA) bundle. More...
 
void set_useragent (string_view useragent)
 Sets the User-Agent. More...
 
- Protected Attributes inherited from mastodonpp::CURLWrapper
mutex buffer_mutex
 Mutex for get_buffer a.k.a. _curl_buffer_body. More...
 

Detailed Description

Holds the access data of an instance.

Since
0.1.0

Constructor & Destructor Documentation

◆ Instance()

mastodonpp::Instance::Instance ( const string_view  hostname,
const string_view  access_token 
)
inlineexplicit

Construct a new Instance object.

Parameters
hostnameThe hostname of the instance.
access_tokenYour access token.
Since
0.1.0
58  : _hostname{hostname}
59  , _baseuri{"https://" + _hostname}
60  , _access_token{access_token}
61  , _max_chars{0}
62  {}

Member Function Documentation

◆ copy_connection_properties()

void mastodonpp::Instance::copy_connection_properties ( CURLWrapper curlwrapper)
inline

Set the properties of the connection of the calling class up.

Meant for internal use. This aligns the properties of the connection of the calling class with the properties of connection of this class.

Parameters
curlwrapperThe CURLWrapper parent of the calling class.
Since
0.3.0
75  {
76  curlwrapper.setup_connection_properties(_proxy, _access_token, _cainfo,
77  _useragent);
78  }

◆ get_access_token()

string_view mastodonpp::Instance::get_access_token ( ) const
inlinenoexcept

Returns the access token.

Since
0.1.0
111  {
112  return _access_token;
113  }

◆ get_baseuri()

string_view mastodonpp::Instance::get_baseuri ( ) const
inlinenoexcept

Returns the base URI.

The base URI is “https://” + the hostname.

Since
0.1.0
100  {
101  return _baseuri;
102  }

◆ get_hostname()

string_view mastodonpp::Instance::get_hostname ( ) const
inlinenoexcept

Returns the hostname.

Since
0.1.0
87  {
88  return _hostname;
89  }

◆ get_max_chars()

uint64_t mastodonpp::Instance::get_max_chars ( )
noexcept

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.

After the first call, the value is saved internally. Subsequent calls return the saved value.

Since
0.1.0

◆ get_nodeinfo()

answer_type mastodonpp::Instance::get_nodeinfo ( )

Returns the NodeInfo of the instance.

Attempts to download the NodeInfo of the instance and returns it. Not every instance has it.

Since
0.3.0

◆ get_post_formats()

vector<string> mastodonpp::Instance::get_post_formats ( )
noexcept

Returns the allowed mime types for statuses.

Extracts metadata.postFormats from NodeInfo. If none can be found, returns {"text/plain"}.

After the first call, the value is saved internally. Subsequent calls return the saved value.

Since
0.3.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
124  {
125  _access_token = move(access_token);
126  }

◆ set_cainfo()

void mastodonpp::Instance::set_cainfo ( string_view  path)
inline

Set path to Certificate Authority (CA) bundle.

Sets also the CA info for all Connections that are initialized with this Instance afterwards.

Since
0.3.0
187  {
188  _cainfo = path;
190  }

◆ set_proxy()

void mastodonpp::Instance::set_proxy ( const string_view  proxy)
inline

Set the proxy to use.

See CURLOPT_PROXY(3).

Parameters
proxyExamples: "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.

148  {
149  _proxy = proxy;
150  CURLWrapper::set_proxy(proxy);
151  }

◆ set_useragent()

void mastodonpp::Instance::set_useragent ( const string_view  useragent)
inline

Sets the User-Agent.

Sets also the User-Agent for all Connections that are initialized with this Instance afterwards.

Since
0.3.0
201  {
202  _useragent = useragent;
203  CURLWrapper::set_useragent(useragent);
204  }

The documentation for this class was generated from the following file:
mastodonpp::CURLWrapper::set_proxy
void set_proxy(string_view proxy)
Set the proxy to use.
Definition: curl_wrapper.cpp:216
mastodonpp::CURLWrapper::set_cainfo
void set_cainfo(string_view path)
Set path to Certificate Authority (CA) bundle.
Definition: curl_wrapper.cpp:253
mastodonpp::CURLWrapper::set_useragent
void set_useragent(string_view useragent)
Sets the User-Agent.
Definition: curl_wrapper.cpp:263