mastodonpp  0.5.7
C++ wrapper for the Mastodon and Pleroma APIs.
mastodonpp Reference

Using the library

Include mastodonpp.hpp, which then includes all other headers.

#include <mastodonpp/mastodonpp.hpp>

Use it in your CMake project like this:

find_package(mastodonpp REQUIRED CONFIG)
target_link_libraries(MyProject mastodonpp::mastodonpp)
C++ wrapper for the Mastodon API.
Definition: api.hpp:25

Or compile your code with g++ $(pkg-config --cflags --libs mastodonpp).

Since we use C++17 features in the headers of this library, your program needs to be compiled as C++17 or higher too.

Example

#include <mastodonpp/mastodonpp.hpp>
#include <iostream>
int main()
{
mastodonpp::Instance instance{"example.com", {}};
std::cout << "Maximum characters per post: "
<< instance.get_max_chars() << std::endl;
mastodonpp::Connection connection{instance};
auto answer{connection.get(mastodonpp::API::v1::instance)};
if (answer)
{
std::cout << answer << std::endl;
}
}
Represents a connection to an instance. Used for requests.
Definition: connection.hpp:79
answer_type get(const endpoint_variant &endpoint, const parametermap &parameters)
Make a HTTP GET call with parameters.
Definition: connection.cpp:34
Holds the access data of an instance.
Definition: instance.hpp:49
uint64_t get_max_chars() noexcept
Returns the maximum number of characters per post.

Input

  • All text input is expected to be UTF-8.
  • To send a file, use “@file:” followed by the file name as value in the parametermap.

Exceptions

Any unrecoverable libcurl error will be thrown as a mastodonpp::CURLException. Network errors will not be thrown, but reported via the return value.

Thread safety

The first time you construct an Instance, curl_global_init(3) is called. When the last Instance is destroyed, curl_global_cleanup(3) is called. Both are not thread safe.

Do not make 2 requests with the same Connection at the same time. You can create as many Connections as you want from one Instance.

If you are using libcurl with OpenSSL before 1.1.0, please read libcurl-thread(3).