mastodonpp  0.0.0
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

Public Member Functions

 Instance (string hostname, string access_token)
 Construct a new Instance object. More...
 
string_view get_hostname () const
 Returns the hostname. More...
 
string_view get_baseuri () const
 Returns the base URI. More...
 
string_view get_access_token () const
 Returns the access token. More...
 
uint64_t get_max_chars () const
 Returns the maximum number of characters per post. More...
 
- Public Member Functions inherited from mastodonpp::CURLWrapper
 CURLWrapper ()
 Initializes curl and sets up connection. More...
 
 CURLWrapper (const CURLWrapper &other)=default
 Copy constructor. More...
 
 CURLWrapper (CURLWrapper &&other) noexcept=default
 Move constructor. More...
 
virtual ~CURLWrapper () noexcept
 Cleans up curl and connection. More...
 
CURLWrapperoperator= (const CURLWrapper &other)=default
 Copy assignment operator. More...
 
CURLWrapperoperator= (CURLWrapper &&other) noexcept=default
 Move assignment operator. More...
 
answer_type make_request (const http_method &method, const string_view &uri)
 Make a request. More...
 

Detailed Description

Holds the access data of an instance.

Since
0.1.0

Constructor & Destructor Documentation

◆ Instance()

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

Construct a new Instance object.

Also queries /api/v1/instance for ‘max_toot_chars’.

Parameters
hostnameThe hostname of the instance.
access_tokenYour access token.
Since
0.1.0
29  : _hostname{move(hostname)}
30  , _baseuri{"https://" + _hostname}
31  , _access_token{move(access_token)}
32  , _max_chars{500}
33 {
34  try
35  {
36  const auto answer{make_request(http_method::GET,
37  _baseuri + "/api/v1/instance")};
38  if (answer)
39  {
40  debuglog << "Querying instance for max_toot_chars…\n";
41  auto &body{answer.body};
42  size_t pos_start{body.find("max_toot_chars")};
43  if (pos_start == string::npos)
44  {
45  debuglog << "max_toot_chars not found.";
46  return;
47  }
48  pos_start = body.find(':', pos_start) + 1;
49  const size_t pos_end{body.find(',', pos_start)};
50 
51  const auto max_toot_chars{body.substr(pos_start,
52  pos_end - pos_start)};
53  _max_chars = std::stoull(max_toot_chars);
54  debuglog << "Set _max_chars to: " << _max_chars << '\n';
55  }
56  }
57  catch (const std::exception &e)
58  {
59  debuglog << "Unexpected exception: " << e.what() << '\n';
60  }
61 }

Member Function Documentation

◆ get_access_token()

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

Returns the access token.

Since
0.1.0
86  {
87  return _access_token;
88  }

◆ 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
75  {
76  return _baseuri;
77  }

◆ get_hostname()

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

Returns the hostname.

Since
0.1.0
62  {
63  return _hostname;
64  }

◆ get_max_chars()

uint64_t mastodonpp::Instance::get_max_chars ( ) const
inline

Returns the maximum number of characters per post.

Since
0.1.0
97  {
98  return _max_chars;
99  }

The documentation for this class was generated from the following files:
mastodonpp::CURLWrapper::make_request
answer_type make_request(const http_method &method, const string_view &uri)
Make a request.
Definition: curl_wrapper.cpp:42