C++ wrapper for the Mastodon API
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

example10_simplify.cpp 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* This file is part of mastodon-cpp.
  2. * Simplify the interface
  3. */
  4. #include <iostream>
  5. #include <string>
  6. #include <cstdint>
  7. #ifdef MASTODON_CPP
  8. #include "mastodon-cpp.hpp"
  9. #else
  10. #include <mastodon-cpp/mastodon-cpp.hpp>
  11. #endif
  12. using Mastodon::API;
  13. class EasyToot : public Mastodon::API
  14. {
  15. public:
  16. explicit EasyToot(const std::string &instance, const std::string &access_token)
  17. : API(instance, access_token)
  18. {}
  19. std::uint16_t toot(const std::string &text, const std::string &cw = "")
  20. {
  21. std::string answer;
  22. API::parametermap parameters;
  23. parameters.insert({ "status", { text } } );
  24. if (!cw.empty())
  25. {
  26. parameters.insert({ "spoiler_text", { cw } } );
  27. }
  28. return post(API::v1::statuses, parameters, answer);
  29. }
  30. };
  31. int main(int argc, char *argv[])
  32. {
  33. if (argc < 3)
  34. {
  35. std::cerr << "usage: " << argv[0] << " <instance> <access_token>\n";
  36. return 1;
  37. }
  38. std::uint16_t ret = 0;
  39. EasyToot masto(argv[1], argv[2]);
  40. ret = masto.toot("Test");
  41. if (ret != 0)
  42. {
  43. std::cerr << "Error: " << ret << '\n';
  44. }
  45. return ret;
  46. }