mastodonpp  0.5.7
C++ wrapper for the Mastodon and Pleroma APIs.
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:
Inheritance graph
[legend]
Collaboration diagram for mastodonpp::Instance:
Collaboration graph
[legend]

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
91  {
92  curlwrapper.setup_connection_properties(_proxy, _access_token, _cainfo,
93  _useragent);
94  }

◆ get_access_token()

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

Returns the access token.

Since
0.1.0
124  {
125  return _access_token;
126  }

◆ 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
114  {
115  return _baseuri;
116  }

◆ get_hostname()

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

Returns the hostname.

Since
0.1.0
102  {
103  return _hostname;
104  }

◆ 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
137  {
138  _access_token = access_token;
139  CURLWrapper::set_access_token(access_token);
140  }
void set_access_token(string_view access_token)
Set OAuth 2.0 Bearer Access Token.
Definition: curl_wrapper.cpp:240

◆ 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.

199  {
200  _cainfo = path;
202  }
virtual void set_cainfo(string_view path)
Set path to Certificate Authority (CA) bundle.
Definition: curl_wrapper.cpp:266

◆ 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.

161  {
162  _proxy = proxy;
163  CURLWrapper::set_proxy(proxy);
164  }
virtual void set_proxy(string_view proxy)
Set the proxy to use.
Definition: curl_wrapper.cpp:229

◆ 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.

213  {
214  _useragent = useragent;
215  CURLWrapper::set_useragent(useragent);
216  }
virtual void set_useragent(string_view useragent)
Sets the User-Agent.
Definition: curl_wrapper.cpp:276

The documentation for this class was generated from the following file: