#include <iostream>
#include <mastodon-cpp/mastodon-cpp.hpp>
int main()
{
Mastodon::API masto("social.example.com", "auth_token");
std::cout << masto.get(Mastodon::API::v1::accounts_verify_credentials);
std::cout << std::endl;
}
|
1 year ago | |
---|---|---|
cmake | 1 year ago | |
examples | 1 year ago | |
pkg-config | 1 year ago | |
src | 1 year ago | |
tests | 1 year ago | |
.drone.yml | 1 year ago | |
.editorconfig | 1 year ago | |
.gitignore | 1 year ago | |
CMakeLists.txt | 1 year ago | |
CODE_OF_CONDUCT.adoc | 1 year ago | |
CONTRIBUTING.adoc | 1 year ago | |
Doxyfile | 1 year ago | |
ISSUE_TEMPLATE.md | 2 years ago | |
LICENSE | 1 year ago | |
README.adoc | 1 year ago | |
build_doc.sh | 3 years ago |
Important
|
This project has become too complicated to maintain by myself and I can’t find the energy to add features. You can find a complete rewrite, with cleaner and much easier to understand code at mastodonpp. I recommend switching to it. You can still report bugs here and I will respond, but I won’t put too much work in it. If you want to take over maintainership, get in touch. |
mastodon-cpp is a C++ wrapper for the Mastodon API. You submit an API call and get the raw JSON that you can then transform into easy to use abstractions.
The HTML reference can be generated with build_doc.sh
, if doxygen is
installed. It is also available at
doc.schlomp.space/mastodon-cpp/.
There are more examples in examples/
.
#include <iostream>
#include <mastodon-cpp/mastodon-cpp.hpp>
int main()
{
Mastodon::API masto("social.example.com", "auth_token");
std::cout << masto.get(Mastodon::API::v1::accounts_verify_credentials);
std::cout << std::endl;
}
Easy
interface to get the last posts from the federated timeline.#include <iostream>
#include <string>
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/all.hpp>
using Mastodon;
int main()
{
Easy::API masto("social.example", "");
return_call ret = masto.get(API::v1::timelines_public);
for (const std::string &str : Easy::json_array_to_vector(ret.answer))
{
Easy::Status status(str);
std::cout << " " << status.account().acct() << " wrote:\n";
std::cout << status.content() << '\n';
}
}
A project consisting of one file can be compiled as follows:
g++ --std=c++14 -lmastodon-cpp example.cpp
Learn more at https://doc.schlomp.space/mastodon-cpp/namespaceMastodon.html and https://doc.schlomp.space/mastodon-cpp/namespaceMastodon_1_1Easy.html.
Not included in this list are entities.
Mastodon::return_call
: Contains the response from Mastodon::API
calls.
Mastodon::parameters
: Vector of Mastodon::param
with custom find()
, for
specifying parameters to an Mastodon::API
call.
Mastodon::http_method
: HTTP method of an Mastodon::API
call.
Mastodon::Easy::event_type
: Event types returned in streams.
Mastodon::Easy::visibility_type
: Describes the visibility of a post.
Mastodon::Easy::attachment_type
: Describes the type of attachment.
Mastodon::Easy::card_type
: Describes the type of card.
Mastodon::Easy::notification_type
: The type of the notification.
Mastodon::Easy::context_type
: Describes the context of a filter.
Mastodon::Easy::stream_event_type
: Type and data of an events returned in
streams.
Mastodon::Easy::alert_type
, used for push subscriptions.
Mastodon::Easy::time_type
: Type for time, can be converted to time_point
and string
.
Mastodon::Easy::account_field_type
: Type for fields in accounts.
Mastodon::Easy::urls_type
: Type for URLs returned by Instance::urls()
.
Mastodon::Easy::stats_type
: Type for statistics returned by
Instance::stats()
.
Mastodon::Easy::poll_options_type
: Type for poll options returned by
Poll::options()
.
Code | Explanation |
---|---|
0 |
No error |
1 |
Invalid argument |
10 |
URL changed (HTTP 301 or 308) |
11 |
Connection timed out |
12 |
Connection refused (check http_error_code) |
13 |
No route to host / Could not resolve host |
14 |
Encryption error |
127 |
Unknown error |
If you use a debug build, you get more verbose error messages.
Starting with version 0.100.0
, large parts of the library have been rewritten.
Upgrading from previous versions will require extensive code changes.
Every release includes packages for Debian and Centos. Gentoo packages are available in my overlay.
Add my repository and install it from there.
eselect repository enable tastytea
echo 'dev-cpp/mastodon-cpp ~amd64' >> /etc/portage/package.accept_keywords/mastodon-cpp
emaint sync -r tastytea
emerge -a dev-cpp/mastodon-cpp
Prebuilt DEB and RPM packages for x86_64(amd64) are provided with each release.
.deb
packages are built on Debian stretch and .rpm
packages are built on
CentOS 7. These packages are automatically built and not tested.
apt-get install build-essential cmake libpoco-dev libjsoncpp-dev doxygen
Download the current release at schlomp.space.
git clone https://schlomp.space/tastytea/mastodon-cpp.git
mkdir build
cd build/
cmake ..
cmake --build . -- -j$(nproc --ignore=1)
-DCMAKE_BUILD_TYPE=Debug
for a debug build.
-DWITH_EASY=NO
to not build the Easy abstractions and to get rid of the
jsoncpp-dependency (not recommended).
-DWITH_EXAMPLES=YES
if you want to compile the examples.
-DWITH_TESTS=YES
if you want to compile the tests.
-DEXTRA_TEST_ARGS
to run only some tests
(format).
Possible tags: [api]
, [auth]
, [mastodon]
, [glitch-soc]
,
[pleroma]
, [upload]
, [entity]
.
-DWITH_DOC=NO
if you don’t want to compile the HTML reference.
One of:
-DWITH_DEB=YES
if you want to be able to generate a deb-package.
-DWITH_RPM=YES
if you want to be able to generate an rpm-package.
cmake -DWITH_TESTS=YES -DEXTRA_TEST_ARGS=[glitch-soc]~[upload] ..
You can run the tests with ctest
inside the build directory. You need to set
the environment variable MASTODON_CPP_ACCESS_TOKEN
to an access token with the
scopes read, write and follow for tests tagged with [auth]
.
You can select the instance to use with MASTODON_CPP_INSTANCE
, the default is
likeable.space. You can select the user ID with MASTODON_CPP_USER_ID
, the
default is 9hnrrVPriLiLVAhfVo. You can select the status ID with
MASTODON_CPP_STATUS_ID
, the default is 9hwnuJMq3eTdO4s1PU. You can select
the filter ID with MASTODON_CPP_FILTER_ID
. You can select the list ID with
MASTODON_CPP_LIST_ID
, the default is 2. You can select the media ID with
MASTODON_CPP_MEDIA_ID
, the default is 2127742613.
Have at least 1 follower.
Follow at least 1 account.
Have at least 1 account endorsed.
Have at least 1 public or unlisted status.
Have at least 1 post favourited.
Have no follow requests.
Have at least 1 list with at least one account in it.
have at least 1 account muted.
Read the Code of Conduct.
Before reporting a bug, please perform a search to see if the problem has already been reported. If it has, add a comment to the existing issue instead of opening a new one. Same for enhancements.
Please use similar coding conventions as the rest of the project. The basic rule to remember is to write code in the same style as the existing/surrounding code.
You can also send me your patches via E-Mail, ideally
using git format-patch
or git send-email
.
You can still use unsupported calls by using API::get
and the others with
strings and you can use unsupported fields in an Entity
by converting it to
Json::Value
.
Accounts
✓ GET /api/v1/accounts/:id
✓ POST /api/v1/accounts
✓ GET /api/v1/accounts/verify_credentials
✓ PATCH /api/v1/accounts/update_credentials
✓ GET /api/v1/accounts/:id/followers
✓ GET /api/v1/accounts/:id/following
✓ GET /api/v1/accounts/:id/statuses
✓ POST /api/v1/accounts/:id/follow
✓ POST /api/v1/accounts/:id/unfollow
✓ GET /api/v1/accounts/relationships
✓ GET /api/v1/accounts/search
Apps
✓ POST /api/v1/apps
✓ GET /api/v1/apps/verify_credentials
Blocks
✓ GET /api/v1/blocks
✓ POST /api/v1/accounts/:id/block
✓ POST /api/v1/accounts/:id/unblock
Custom emoji
✓ GET /api/v1/custom_emojis
Domain blocks
✓ GET /api/v1/domain_blocks
✓ POST /api/v1/domain_blocks
✓ DELETE /api/v1/domain_blocks
Endorsements
✓ GET /api/v1/endorsements
✓ POST /api/v1/accounts/:id/pin
✓ POST /api/v1/accounts/:id/unpin
Favourites
✓ GET /api/v1/favourites
✓ POST /api/v1/statuses/:id/favourite
✓ POST /api/v1/statuses/:id/unfavourite
Filters
✓ GET /api/v1/filters
✓ POST /api/v1/filters
✓ GET /api/v1/filters/:id
✓ PUT /api/v1/filters/:id
✓ DELETE /api/v1/filters/:id
Follow requests
✓ GET /api/v1/follow_requests
✓ POST /api/v1/follow_requests/:id/authorize
✓ POST /api/v1/follow_requests/:id/reject
Follow suggestions
✓ GET /api/v1/suggestions
✓ DELETE /api/v1/suggestions/:account_id
Instances
✓ GET /api/v1/instance
Lists
✓ GET /api/v1/lists
✓ GET /api/v1/accounts/:id/lists
✓ GET /api/v1/lists/:id/accounts
✓ GET /api/v1/lists/:id
✓ POST /api/v1/lists
✓ PUT /api/v1/lists/:id
✓ DELETE /api/v1/lists/:id
✓ POST /api/v1/lists/:id/accounts
✓ DELETE /api/v1/lists/:id/accounts
Media attachments
✓ POST /api/v1/media
✓ PUT /api/v1/media/:id
Mutes
✓ GET /api/v1/mutes
✓ POST /api/v1/accounts/:id/mute
✓ POST /api/v1/accounts/:id/unmute
✓ POST /api/v1/statuses/:id/mute
✓ POST /api/v1/statuses/:id/unmute
Notifications
✓ GET /api/v1/notifications
✓ GET /api/v1/notifications/:id
✓ POST /api/v1/notifications/clear
✓ POST /api/v1/notifications/dismiss
✓ POST /api/v1/push/subscription
✓ GET /api/v1/push/subscription
✓ PUT /api/v1/push/subscription
✓ DELETE /api/v1/push/subscription
Polls
✓ GET /api/v1/polls/:id
✓ POST /api/v1/polls/:id/votes
Reports
✓ POST /api/v1/reports
Scheduled Statuses
❏ GET /api/v1/scheduled_statuses
❏ GET /api/v1/scheduled_statuses/:id
❏ PUT /api/v1/scheduled_statuses/:id
❏ DELETE /api/v1/scheduled_statuses/:id
Search
✓ GET /api/v2/search
Statuses
✓ GET /api/v1/statuses/:id
✓ GET /api/v1/statuses/:id/context
✓ GET /api/v1/statuses/:id/card
✓ GET /api/v1/statuses/:id/reblogged_by
✓ GET /api/v1/statuses/:id/favourited_by
✓ POST /api/v1/statuses
✓ DELETE /api/v1/statuses/:id
✓ POST /api/v1/statuses/:id/reblog
✓ POST /api/v1/statuses/:id/unreblog
✓ POST /api/v1/statuses/:id/pin
✓ POST /api/v1/statuses/:id/unpin
Timelines
✓ GET /api/v1/timelines/home
✓ GET /api/v1/conversations
✓ GET /api/v1/timelines/public
✓ GET /api/v1/timelines/tag/:hashtag
✓ GET /api/v1/timelines/list/:list_id
Streaming API
✓ GET /api/v1/streaming/health
✓ GET /api/v1/streaming/user
✓ GET /api/v1/streaming/public
✓ GET /api/v1/streaming/public/local
✓ GET /api/v1/streaming/hashtag
✓ GET /api/v1/streaming/hashtag/local
✓ GET /api/v1/streaming/list
✓ GET /api/v1/streaming/direct
✓ Account
✓ Application
✓ Attachment
✓ Card
✓ Context
✓ Conversation
✓ Emoji
✓ Filter
✓ Instance
✓ List
✓ Mention
✓ Notification
✓ Poll
✓ PushSubscription
✓ Relationship
✓ Results
✓ Status
❏ ScheduledStatus
✓ Tag
❏ Token
✓ GET /api/v1/bookmarks
✓ POST /api/v1/statuses/:id/bookmark
✓ POST /api/v1/statuses/:id/unbookmark
✓ max_toot_chars
in Instance
❏ preview
and content_type
in POST /api/v1/statuses
❏ no_rich_text
, hide_followers
, hide_follows
, hide_favorites
and
show_role
in /api/v1/update_credentials
❏ GET /api/pleroma/emoji
❏ POST /api/pleroma/follow_import
❏ GET /api/pleroma/captcha
❏ POST /api/pleroma/delete_account
❏ POST /api/account/register
❏ POST /api/v1/pleroma/flavour/:flavour
❏ GET /api/v1/pleroma/flavour
❏ POST /api/pleroma/notifications/read
❏ POST /api/v1/pleroma/accounts/:id/subscribe
❏ POST /api/v1/pleroma/accounts/:id/unsubscribe
❏ GET /api/v1/pleroma/accounts/:id/favourites
❏ PUT /api/pleroma/notification_settings
❏ GET /api/pleroma/healthcheck
Admin API
❏ GET /api/pleroma/admin/users
❏ DELETE /api/pleroma/admin/user
❏ POST /api/pleroma/admin/user
❏ POST /api/pleroma/admin/user/follow
❏ POST /api/pleroma/admin/user/unfollow
❏ PATCH /api/pleroma/admin/users/:nickname/toggle_activation
❏ PUT /api/pleroma/admin/users/tag
❏ DELETE /api/pleroma/admin/users/tag
❏ GET /api/pleroma/admin/permission_group/:nickname
❏ GET /api/pleroma/admin/permission_group/:nickname/:permission_group
❏ POST /api/pleroma/admin/permission_group/:nickname/:permission_group
❏ DELETE /api/pleroma/admin/permission_group/:nickname/:permission_group
❏ PUT /api/pleroma/admin/activation_status/:nickname
❏ GET /api/pleroma/admin/users/:nickname
❏ POST /api/pleroma/admin/relay
❏ DELETE /api/pleroma/admin/relay
❏ GET /api/pleroma/admin/invite_token
❏ GET /api/pleroma/admin/invites
❏ POST /api/pleroma/admin/revoke_invite
❏ POST /api/pleroma/admin/email_invite
❏ GET /api/pleroma/admin/password_reset
pleroma
object in:
❏ Status
❏ Attachment
❏ Account
❏ Source
❏ Notification
Instances that are frequently used to hurt marginalized people are blocked from using this library.
Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>.
License AGPLv3: <https://www.gnu.org/licenses/agpl-3.0.html>.
This program comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.