mastodonpp  0.5.4
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 (string_view hostname, string_view access_token)
 Construct a new Instance object. More...
 
 Instance (const Instance &other)
 Copy constructor. A new CURLWrapper is constructed. More...
 
 Instance (Instance &&other) noexcept=delete
 Move constructor. More...
 
 ~Instance () noexcept override=default
 Destructor. More...
 
Instanceoperator= (const Instance &other)=delete
 Copy assignment operator. More...
 
Instanceoperator= (Instance &&other) noexcept=delete
 Move assignment operator. More...
 
void copy_connection_properties (CURLWrapper &curlwrapper) const
 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 (const string_view 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) override
 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) override
 Set path to Certificate Authority (CA) bundle. More...
 
void set_useragent (const string_view useragent) override
 Sets the User-Agent. More...
 
- Public Member Functions inherited from mastodonpp::CURLWrapper
 CURLWrapper ()
 Initializes curl and sets up connection. More...
 
 CURLWrapper (const CURLWrapper &)
 Copy constructor. Does the same as the 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_access_token (string_view access_token)
 Set OAuth 2.0 Bearer Access Token. 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.

Instances are needed to initialize Connections. All properties you set here (with set_proxy(), set_useragent() and so on) are copied to every Connection you initialize afterwards.

Since
0.1.0

Constructor & Destructor Documentation

◆ Instance() [1/3]

mastodonpp::Instance::Instance ( string_view  hostname,
string_view  access_token 
)
explicit

Construct a new Instance object.

Parameters
hostnameThe hostname of the instance.
access_tokenYour access token.
Since
0.1.0

◆ Instance() [2/3]

mastodonpp::Instance::Instance ( const Instance other)

Copy constructor. A new CURLWrapper is constructed.

Since
0.5.2

◆ Instance() [3/3]

mastodonpp::Instance::Instance ( Instance &&  other)
deletenoexcept

Move constructor.

◆ ~Instance()

mastodonpp::Instance::~Instance ( )
overridedefaultnoexcept

Destructor.

Member Function Documentation

◆ copy_connection_properties()

void mastodonpp::Instance::copy_connection_properties ( CURLWrapper curlwrapper) const
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
92  {
93  curlwrapper.setup_connection_properties(_proxy, _access_token, _cainfo,
94  _useragent);
95  }

◆ get_access_token()

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

Returns the access token.

Since
0.1.0
128  {
129  return _access_token;
130  }

◆ 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
117  {
118  return _baseuri;
119  }

◆ get_hostname()

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

Returns the hostname.

Since
0.1.0
104  {
105  return _hostname;
106  }

◆ 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

◆ operator=() [1/2]

Instance& mastodonpp::Instance::operator= ( const Instance other)
delete

Copy assignment operator.

◆ operator=() [2/2]

Instance& mastodonpp::Instance::operator= ( Instance &&  other)
deletenoexcept

Move assignment operator.

◆ set_access_token()

void mastodonpp::Instance::set_access_token ( const string_view  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
141  {
142  _access_token = access_token;
143  CURLWrapper::set_access_token(access_token);
144  }

◆ set_cainfo()

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

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

Reimplemented from mastodonpp::CURLWrapper.

205  {
206  _cainfo = path;
208  }

◆ set_proxy()

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

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.

Reimplemented from mastodonpp::CURLWrapper.

166  {
167  _proxy = proxy;
168  CURLWrapper::set_proxy(proxy);
169  }

◆ set_useragent()

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

Sets the User-Agent.

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

Since
0.3.0

Reimplemented from mastodonpp::CURLWrapper.

219  {
220  _useragent = useragent;
221  CURLWrapper::set_useragent(useragent);
222  }

The documentation for this class was generated from the following file:
mastodonpp::CURLWrapper::set_proxy
virtual void set_proxy(string_view proxy)
Set the proxy to use.
Definition: curl_wrapper.cpp:234
mastodonpp::CURLWrapper::set_cainfo
virtual void set_cainfo(string_view path)
Set path to Certificate Authority (CA) bundle.
Definition: curl_wrapper.cpp:271
mastodonpp::CURLWrapper::set_useragent
virtual void set_useragent(string_view useragent)
Sets the User-Agent.
Definition: curl_wrapper.cpp:281
mastodonpp::CURLWrapper::set_access_token
void set_access_token(string_view access_token)
Set OAuth 2.0 Bearer Access Token.
Definition: curl_wrapper.cpp:245