Added example for simplifying the interface, renamed examples
This commit is contained in:
parent
cd5294683d
commit
4372f3249c
@ -1,6 +1,6 @@
|
||||
cmake_minimum_required (VERSION 3.7)
|
||||
project (mastodon-cpp
|
||||
VERSION 0.5.0
|
||||
VERSION 0.5.1
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
|
@ -115,6 +115,8 @@ If you use a debug build, you get more verbose error messages.
|
||||
|
||||
## Status of implementation
|
||||
|
||||
Feature complete as of Mastodon 2.2.0
|
||||
|
||||
* [x] GET /api/v1/accounts/:id
|
||||
* [x] GET /api/v1/accounts/verify_credentials
|
||||
* [x] PATCH /api/v1/accounts/update_credentials
|
||||
|
53
src/examples/example10_simplify.cpp
Normal file
53
src/examples/example10_simplify.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
/* This file is part of mastodon-cpp.
|
||||
* Simplify the interface
|
||||
*/
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
#include "../mastodon-cpp.hpp"
|
||||
|
||||
using Mastodon::API;
|
||||
|
||||
class EasyToot : public Mastodon::API
|
||||
{
|
||||
public:
|
||||
explicit EasyToot(const std::string &instance, const std::string &access_token)
|
||||
: API(instance, access_token)
|
||||
{}
|
||||
|
||||
std::uint16_t toot(const std::string &text, const std::string &cw = "")
|
||||
{
|
||||
std::string answer;
|
||||
API::parametermap parameters;
|
||||
parameters.insert({ "status", { text } } );
|
||||
if (!cw.empty())
|
||||
{
|
||||
parameters.insert({ "spoiler_text", { cw } } );
|
||||
}
|
||||
|
||||
return post(API::v1::statuses, parameters, answer);
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc < 3)
|
||||
{
|
||||
std::cerr << "usage: " << argv[0] << " <instance> <access_token>\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string answer;
|
||||
std::uint16_t ret = 0;
|
||||
EasyToot masto(argv[1], argv[2]);
|
||||
|
||||
masto.toot("Test");
|
||||
if (ret != 0)
|
||||
{
|
||||
std::cerr << "Error: " << ret << '\n';
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
@ -26,15 +26,16 @@
|
||||
#include <curlpp/Easy.hpp>
|
||||
|
||||
/*!
|
||||
* @example example1_dump_json.cpp
|
||||
* @example example2_parse_account.cpp
|
||||
* @example example3_mastocron.cpp
|
||||
* @example example4_update_credentials.cpp
|
||||
* @example example5_follow_unfollow.cpp
|
||||
* @example example6_toot_delete-toot.cpp
|
||||
* @example example7_register_app.cpp
|
||||
* @example example8_rate_limiting.cpp
|
||||
* @example example9_streaming_api.cpp
|
||||
* @example example01_dump_json.cpp
|
||||
* @example example02_parse_account.cpp
|
||||
* @example example03_mastocron.cpp
|
||||
* @example example04_update_credentials.cpp
|
||||
* @example example05_follow_unfollow.cpp
|
||||
* @example example06_toot_delete-toot.cpp
|
||||
* @example example07_register_app.cpp
|
||||
* @example example08_rate_limiting.cpp
|
||||
* @example example09_streaming_api.cpp
|
||||
* @example example10_simplify.cpp
|
||||
*/
|
||||
namespace Mastodon
|
||||
{
|
||||
|
Reference in New Issue
Block a user