This repository has been archived on 2020-05-10. You can view files and clone it, but cannot push or open issues or pull requests.
mastodon-cpp/README.md

331 lines
11 KiB
Markdown
Raw Permalink Normal View History

2018-03-07 17:17:26 +01:00
**mastodon-cpp** is a C++ wrapper for the Mastodon API.
2018-04-03 00:52:23 +02:00
The library takes care of the network stuff. You submit a query and get the raw
JSON. You can then put that JSON into easy to use classes.
2018-01-06 21:33:52 +01:00
2018-06-04 21:06:05 +02:00
[TODO-list](https://schlomp.space/tastytea/mastodon-cpp/milestones)
2018-03-18 14:02:53 +01:00
2018-10-09 23:43:44 +02:00
**The ABI will be unstable in versions < 1.0.0**
2019-02-22 08:07:55 +01:00
# Breaking API changes
2019-04-02 11:28:53 +02:00
I'm currently rewriting key parts of this library. The new API will be
incompatible with the old one. The new code will start with the version number
`0.100.0`. The old code is archived in the branch `pre-0.100.0` and will get
2019-04-13 21:53:06 +02:00
bug-fixes for a while.
2019-02-22 08:07:55 +01:00
**The code on the `master`-branch is not usable at the moment, stick to the
releases, please.**
2018-03-18 01:43:09 +01:00
# Usage
2019-04-02 11:28:53 +02:00
The HTML reference can be generated with `build_doc.sh`, if doxygen is
2019-04-13 21:50:20 +02:00
installed. It is also available at
[doc.schlomp.space/mastodon-cpp/](https://doc.schlomp.space/mastodon-cpp/annotated.html).
2019-04-02 11:28:53 +02:00
There are [examples](https://schlomp.space/tastytea/mastodon-cpp/src/branch/master/examples)
in `examples/`.
2018-03-18 01:43:09 +01:00
## Most basic example
2019-04-02 11:28:53 +02:00
```c++
2018-03-18 01:43:09 +01:00
#include <iostream>
#include <mastodon-cpp/mastodon-cpp.hpp>
2018-03-18 01:43:09 +01:00
int main()
{
Mastodon::API masto("social.example.com", "auth_token");
2019-03-03 11:22:11 +01:00
std::cout << masto.get(Mastodon::API::v1::accounts_verify_credentials);
std::cout << std::endl;
2018-03-18 01:43:09 +01:00
}
```
2018-04-01 05:03:35 +02:00
## Another simple example
Using the `Easy`-class.
2018-04-01 05:03:35 +02:00
2019-04-02 11:28:53 +02:00
```c++
2018-04-01 05:03:35 +02:00
#include <iostream>
#include <string>
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/all.hpp>
using Mastodon::Easy;
int main()
{
Easy masto("social.example", "");
2019-03-03 11:22:11 +01:00
return_call ret = masto.get(Mastodon::API::v1::timelines_public);
2018-04-01 05:03:35 +02:00
2019-03-03 11:22:11 +01:00
for (const std::string &str : Easy::json_array_to_vector(ret.answer))
2018-04-01 05:03:35 +02:00
{
Easy::Status status(str);
std::cout << " " << status.account().acct() << " wrote:\n";
std::cout << status.content() << '\n';
}
}
```
2018-03-18 01:43:09 +01:00
## Compiling your project
2018-03-26 01:14:59 +02:00
A project consisting of one file can be compiled as follows:
2018-03-18 01:43:09 +01:00
2019-04-02 11:28:53 +02:00
``` shellsession
2018-06-08 00:44:11 +02:00
g++ -std=c++14 -lmastodon-cpp example.cpp
```
2018-03-18 01:43:09 +01:00
2019-04-13 21:50:20 +02:00
## List of types
Learn more at <https://doc.schlomp.space/mastodon-cpp/namespaceMastodon.html>
and <https://doc.schlomp.space/mastodon-cpp/namespaceMastodon_1_1Easy.html>.
### Return types
* `Mastodon::return_call`: Contains the response from `Mastodon::API` calls.
* `Mastodon::Easy::return_entity`: Contains the response from
`Mastodon::Easy::API` calls that return a single `Mastodon::Easy::Entity`.
* `Mastodon::Easy::return_entities_vector`: Contains the response from
`Mastodon::Easy::API` calls that return multiple `Mastodon::Easy::Entity`.
### Other types
* `Mastodon::param`: A single parameter to an `Mastodon::API` call. Normally you
don't need this.
* `Mastodon::parameters`: All 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::stream_event`: Type and data of an events returned in
streams.
* `Mastodon::Easy::alert_type`: Type for a single alert.
2019-04-13 21:53:06 +02:00
* `Mastodon::Easy::alerts`: Vector of `Mastodon::Easy::alert_type`, used for
push subscriptions.
2019-04-13 21:50:20 +02:00
* `Mastodon::Easy::time`: Type for time, can be converted to `time_point` and
`string`.
2018-03-18 01:43:09 +01:00
## Error codes
2019-02-22 12:14:15 +01:00
| Code | Explanation |
| --------: |:-------------------------------------------|
| 0 | No error |
| 22 | Invalid argument |
| 78 | URL changed (HTTP 301 or 308) |
| 110 | Connection timed out |
| 111 | Connection refused (check http_error_code) |
| 113 | No route to host / Could not resolve host |
2019-02-28 15:47:25 +01:00
| 192 | curlpp runtime error |
| 193 | curlpp logic error |
2019-02-22 12:14:15 +01:00
| 255 | Unknown error |
2018-04-10 10:44:46 +02:00
2018-08-15 07:36:49 +02:00
If you use a debug build, you get more verbose error messages.
2018-03-18 01:43:09 +01:00
## Useful links
* [Mastodon documentation](https://docs.joinmastodon.org/)
* [Pleroma documentation](https://git.pleroma.social/pleroma/pleroma/tree/develop/docs/api)
* [glitch-soc documentation](https://glitch-soc.github.io/docs/#whats-different)
2018-03-18 01:43:09 +01:00
2018-01-06 21:33:52 +01:00
# Install
2018-03-18 01:32:54 +01:00
## Packages
Every [release](https://schlomp.space/tastytea/mastodon-cpp/releases) includes
2018-10-08 18:36:13 +02:00
packages for the package managers of Debian and Red Hat. Gentoo packages are
available in an overlay.
2018-03-18 01:32:54 +01:00
### Gentoo
2018-06-20 11:05:49 +02:00
Add my [repository](https://schlomp.space/tastytea/overlay) and
2018-05-08 07:51:50 +02:00
install it from there.
2019-04-02 11:28:53 +02:00
```shellsession
2018-06-20 11:05:49 +02:00
eselect repository enable tastytea
2018-06-07 23:11:08 +02:00
echo 'dev-cpp/mastodon-cpp ~amd64' >> /etc/portage/package.keywords/mastodon-cpp
emaint sync -r tastytea
emerge -a dev-cpp/mastodon-cpp
```
2018-05-08 07:51:50 +02:00
2018-03-18 01:32:54 +01:00
### DEB and RPM
Prebuilt DEB and RPM packages for x86_64(amd64) are provided with each release.
2019-04-08 21:24:08 +02:00
`.deb` packages are built on Debian stretch and `.rpm` packages are built on
CentOS 7. These packages are automatically built and not tested. Install with
`dpkg -i` or `rpm -i`, respectively.
2018-03-18 01:32:54 +01:00
2019-04-08 21:24:08 +02:00
To use the DEB package on Debian stretch, you will need
[libcurlpp0](https://packages.debian.org/libcurlpp0) from sid.
2018-03-18 01:32:54 +01:00
## From source
### Dependencies
2018-03-26 01:14:59 +02:00
* Tested OS: Linux
2019-03-03 11:34:09 +01:00
* C++ compiler (tested: gcc 6 / 7 / 8)
2018-10-08 22:41:28 +02:00
* [cmake](https://cmake.org/) (tested: 3.9 / 3.12)
2018-06-13 05:25:13 +02:00
* [pkgconfig](https://pkgconfig.freedesktop.org/wiki/) (tested: 0.29)
2018-08-15 07:36:49 +02:00
* [curlpp](http://www.curlpp.org/) (tested: 0.8)
* Optional
2018-06-13 05:25:13 +02:00
* Easy interface & Examples: [jsoncpp](https://github.com/open-source-parsers/jsoncpp) (tested: 1.8 / 1.7)
* Documentation: [doxygen](https://www.stack.nl/~dimitri/doxygen/) (tested: 1.8)
2018-10-08 22:41:28 +02:00
* DEB package: [dpkg](https://packages.qa.debian.org/dpkg) (tested: 1.19 / 1.18)
* RPM package: [rpm](http://www.rpm.org) (tested: 4.14 / 4.12)
2018-01-06 21:33:52 +01:00
2018-03-18 01:32:54 +01:00
### Get sourcecode
2018-03-18 01:32:54 +01:00
#### Release
Download the current release at [schlomp.space](https://schlomp.space/tastytea/mastodon-cpp/releases).
2018-03-18 01:32:54 +01:00
#### Development version
2019-04-02 11:28:53 +02:00
```shellsession
2018-06-07 23:23:39 +02:00
git clone https://schlomp.space/tastytea/mastodon-cpp.git
```
2018-01-06 21:33:52 +01:00
2018-03-18 01:32:54 +01:00
### Compile
2019-04-02 11:28:53 +02:00
```shellsession
2018-06-07 23:11:08 +02:00
mkdir build
cd build/
cmake ..
make
```
2018-01-06 21:33:52 +01:00
cmake options:
* `-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
* `-DWITH_DOC=NO` if you don't want to compile the HTML reference
2019-03-03 12:28:14 +01:00
* 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
You can run the tests with `ctest ..` inside the build directory.
2018-03-26 01:14:59 +02:00
To install, run `make install`.
2018-03-18 01:32:54 +01:00
### Packages
2018-03-18 01:32:54 +01:00
#### DEB and RPM
Compile with `-DWITH_DEB=ON` or `-DWITH_RPM=ON`.
Run `make package` from the build directory to generate a DEB/RPM package.
2018-03-18 01:32:54 +01:00
#### Other
2018-03-18 01:32:54 +01:00
Run `make package` from the build directory to generate a tar.gz archive.
# Status of implementation
~~Feature complete as of Mastodon 2.6.1~~
2018-01-09 22:12:11 +01:00
* [x] GET /api/v1/accounts/:id
* [ ] POST /api/v1/accounts
2018-01-09 22:12:11 +01:00
* [x] GET /api/v1/accounts/verify_credentials
* [x] PATCH /api/v1/accounts/update_credentials
2018-01-09 22:12:11 +01:00
* [x] GET /api/v1/accounts/:id/followers
* [x] GET /api/v1/accounts/:id/following
* [x] GET /api/v1/accounts/:id/statuses
* [x] POST /api/v1/accounts/:id/follow
* [x] POST /api/v1/accounts/:id/unfollow
2018-01-09 22:12:11 +01:00
* [x] GET /api/v1/accounts/relationships
* [x] GET /api/v1/accounts/search
* [x] POST /api/v1/apps
* [ ] GET /api/v1/apps/verify_credentials
* [x] GET /api/v1/blocks
* [x] POST /api/v1/accounts/:id/block
* [x] POST /api/v1/accounts/:id/unblock
* [x] GET /api/v1/custom_emojis
* [x] GET /api/v1/domain_blocks
* [x] POST /api/v1/domain_blocks
* [x] DELETE /api/v1/domain_blocks
* [x] GET /api/v1/endorsements
* [x] POST /api/v1/accounts/:id/pin
* [x] POST /api/v1/accounts/:id/unpin
* [x] GET /api/v1/favourites
* [x] POST /api/v1/statuses/:id/favourite
* [x] POST /api/v1/statuses/:id/unfavourite
* [ ] GET /api/v1/filters
* [ ] POST /api/v1/filters
* [ ] GET /api/v1/filters/:id
* [ ] DELETE /api/v1/filters/:id
* [x] GET /api/v1/follow_requests
* [x] POST /api/v1/follow_requests/:id/authorize
* [x] POST /api/v1/follow_requests/:id/reject
* [ ] GET /api/v1/suggestions
* [ ] DELETE /api/v1/suggestions/:account_id
* [x] GET /api/v1/instance
* [x] GET /api/v1/lists
* [x] GET /api/v1/accounts/:id/lists
* [x] GET /api/v1/lists/:id/accounts
* [x] GET /api/v1/lists/:id
* [x] POST /api/v1/lists
* [x] PUT /api/v1/lists/:id
* [x] DELETE /api/v1/lists/:id
* [x] POST /api/v1/lists/:id/accounts
* [x] DELETE /api/v1/lists/:id/accounts
* [x] POST /api/v1/media
* [x] PUT /api/v1/media/:id
* [x] GET /api/v1/mutes
* [x] POST /api/v1/accounts/:id/mute
* [x] POST /api/v1/accounts/:id/unmute
* [x] POST /api/v1/statuses/:id/mute
* [x] POST /api/v1/statuses/:id/unmute
* [x] GET /api/v1/notifications
* [x] GET /api/v1/notifications/:id
* [x] POST /api/v1/notifications/clear
* [x] POST /api/v1/notifications/dismiss
* [x] POST /api/v1/push/subscription
* [x] GET /api/v1/push/subscription
* [x] PUT /api/v1/push/subscription
* [x] DELETE /api/v1/push/subscription
* [x] ~~GET /api/v1/reports~~ (Deprecated)
* [x] POST /api/v1/reports
* [ ] GET /api/v1/scheduled_statuses
* [ ] GET /api/v1/scheduled_statuses/:id
* [ ] PUT /api/v1/scheduled_statuses/:id
* [ ] DELETE /api/v1/scheduled_statuses/:id
* [x] ~~GET /api/v1/search~~ (Deprecated)
* [x] GET /api/v2/search
* [x] GET /api/v1/statuses/:id
* [x] GET /api/v1/statuses/:id/context
* [x] GET /api/v1/statuses/:id/card
* [x] GET /api/v1/statuses/:id/reblogged_by
* [x] GET /api/v1/statuses/:id/favourited_by
* [x] POST /api/v1/statuses
* [x] DELETE /api/v1/statuses/:id
* [x] POST /api/v1/statuses/:id/reblog
* [x] POST /api/v1/statuses/:id/unreblog
* [x] POST /api/v1/statuses/:id/pin
* [x] POST /api/v1/statuses/:id/unpin
* [x] GET /api/v1/timelines/home
* [ ] GET /api/v1/conversations
* [x] GET /api/v1/timelines/public
* [x] GET /api/v1/timelines/tag/:hashtag
* [x] GET /api/v1/timelines/list/:list_id
2018-02-26 07:57:30 +01:00
* [x] GET /api/v1/streaming/user
* [x] GET /api/v1/streaming/public
* [x] GET /api/v1/streaming/public/local
* [x] GET /api/v1/streaming/hashtag
* [ ] GET /api/v1/streaming/hashtag/local
2018-02-26 07:57:30 +01:00
* [x] GET /api/v1/streaming/list
* [ ] GET /api/v1/streaming/direct
2018-02-11 22:41:47 +01:00
## Glitch-Soc support
* [x] max_toot_chars in /api/v1/instance
* [x] GET /api/v1/bookmarks
* [x] POST /api/v1/statuses/:id/bookmark
* [x] POST /api/v1/statuses/:id/unbookmark
2018-01-06 21:33:52 +01:00
# Copyright
2019-04-02 11:28:53 +02:00
``` text
Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>.
2018-06-07 23:11:08 +02:00
License GPLv3: GNU GPL version 3 <https://www.gnu.org/licenses/gpl-3.0.html>.
This program comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
```