#if __has_include("mastodonpp.hpp")
# include "mastodonpp.hpp"
#else
# include <mastodonpp/mastodonpp.hpp>
#endif
#include <chrono>
#include <iostream>
#include <string>
#include <string_view>
#include <thread>
#include <vector>
using namespace std::chrono_literals;
using std::cerr;
using std::cout;
using std::endl;
using std::string_view;
using std::to_string;
using std::vector;
using std::this_thread::sleep_for;
int main(int argc, char *argv[])
{
const vector<string_view> args(argv, argv + argc);
if (args.size() <= 2)
{
cerr << "Usage: " << args[0] << " <instance hostname> <access token>\n";
return 1;
}
try
{
masto::Instance instance{args[1], args[2]};
masto::Connection connection{instance};
auto answer{connection.post(masto::API::v1::statuses,
{{"status", "Delete me."}})};
if (answer)
{
cout << "Successfully posted a status.\n";
const auto pos{answer.body.rfind(R"("id":")") + 6};
const auto endpos{answer.body.find(R"(",)", pos)};
const auto id{answer.body.substr(pos, endpos - pos)};
cout << "Post has ID: " << id << endl;
cout << "Waiting 10 seconds…\n";
sleep_for(10s);
answer = connection.del(masto::API::v1::statuses_id, {{"id", id}});
if (answer)
{
cout << "Successfully deleted the status.\n";
}
}
else
{
if (answer.curl_error_code == 0)
{
cerr << "HTTP status: " << answer.http_status << endl;
}
else
{
cerr << "libcurl error " << to_string(answer.curl_error_code)
<< ": " << answer.error_message << endl;
}
}
}
catch (const masto::CURLException &e)
{
cerr << e.what() << endl;
}
return 0;
}
C++ wrapper for the Mastodon API.
Definition: api.hpp:25