2019-04-14 06:21:26 +02:00
**mastodon-cpp** is a C++ wrapper for the Mastodon API. You submit an API call
2019-04-15 04:29:54 +02:00
and get the raw JSON or easy to use abstractions.
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-04-17 20:10:42 +02:00
[Subscribe to mastodon-cpp releases ](https://rss.schlomp.space/?repo=tastytea/mastodon-cpp ).
2019-04-17 05:37:28 +02:00
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>
2018-03-21 17:08:33 +01:00
#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
2019-04-14 06:21:26 +02:00
Using the `Easy` interface.
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>
2019-04-14 06:21:26 +02:00
using Mastodon;
2018-04-01 05:03:35 +02:00
int main()
{
2019-04-14 06:21:26 +02:00
Easy::API masto("social.example", "");
return_call ret = masto.get(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.
2019-04-23 20:07:15 +02:00
* `Mastodon::Easy::return_entity` : Contains the response from high-level
functions that return a single `Mastodon::Easy::Entity` .
2019-04-13 21:50:20 +02:00
* `Mastodon::Easy::return_entities_vector` : Contains the response from
2019-04-23 20:07:15 +02:00
high-level functions that return multiple `Mastodon::Easy::Entity` .
2019-04-13 21:50:20 +02:00
### Other types
2019-04-23 20:07:15 +02:00
* `Mastodon::parameters` : Vector of `Mastodon::param` , for specifying parameters
to an `Mastodon::API` call.
2019-04-13 21:50:20 +02:00
* `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.
2019-04-19 06:00:26 +02:00
* `Mastodon::Easy::context_type` : Describes the context of a filter.
2019-04-13 21:50:20 +02:00
* `Mastodon::Easy::stream_event` : Type and data of an events returned in
streams.
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) |
2019-04-10 20:52:36 +02:00
| 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
2018-12-04 12:27:35 +01:00
* [Mastodon documentation ](https://docs.joinmastodon.org/ )
2019-04-13 21:59:27 +02:00
* [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-01-13 15:49:46 +01:00
2019-04-14 06:21:26 +02:00
## Upgrading from versions below 0.100.0
Starting with version `0.100.0` , large parts of the library have been rewritten.
Upgrading from previous versions will require extensive code changes. You can
keep using the old version, it is archived in the branch
[pre-0.100.0 ](https://schlomp.space/tastytea/mastodon-cpp/src/branch/pre-0.100.0 ).
It will receive bug-fixes for a while but no new features.
2018-03-18 01:32:54 +01:00
## Packages
2018-06-07 23:01:27 +02:00
Every [release ](https://schlomp.space/tastytea/mastodon-cpp/releases ) includes
2019-04-19 06:00:26 +02:00
packages for Debian and Centos. Gentoo packages are available in my 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
2019-04-14 06:21:26 +02:00
echo 'dev-cpp/mastodon-cpp ~amd64' >> /etc/portage/package.accept_keywords/mastodon-cpp
2018-06-07 23:11:08 +02:00
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
2019-04-14 06:21:26 +02:00
CentOS 7. These packages are automatically built and not tested.
2018-03-18 01:32:54 +01:00
2019-04-22 04:01:18 +02:00
To use the `.deb` package on Debian stretch, you will need
2019-04-08 21:24:08 +02:00
[libcurlpp0 ](https://packages.debian.org/libcurlpp0 ) from sid.
2018-03-18 01:32:54 +01:00
2019-04-14 06:21:26 +02:00
To use the `.rpm` package on CentOS 7, you will need
[libcurlpp ](https://download.fedoraproject.org/pub/epel/6/x86_64/Packages/c/ )
from EPEL 6.
2018-03-18 01:32:54 +01:00
## From source
### Dependencies
2018-01-13 15:49:46 +01:00
2018-03-26 01:14:59 +02:00
* Tested OS: Linux
2019-04-16 04:10:39 +02:00
* C++ compiler (tested: [gcc ](https://gcc.gnu.org/ ) 6/7/8,
[clang ](https://llvm.org/ ) 5/6)
2019-04-14 06:21:26 +02:00
* [cmake ](https://cmake.org/ ) (at least: 3.6)
* [pkgconfig ](https://pkgconfig.freedesktop.org/wiki/ ) (tested: 0.29 / 0.27)
2018-08-15 07:36:49 +02:00
* [curlpp ](http://www.curlpp.org/ ) (tested: 0.8)
2018-03-08 11:07:41 +01:00
* 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)
2019-04-14 06:21:26 +02:00
* DEB package: [dpkg ](https://packages.qa.debian.org/dpkg ) (tested: 1.18)
* RPM package: [rpm-build ](http://www.rpm.org ) (tested: 4.11)
* Tests: [catch ](https://github.com/catchorg/Catch2 ) (tested: 2.5 / 1.2)
2018-01-06 21:33:52 +01:00
2019-04-22 04:01:18 +02:00
#### Debian stretch
``` shellsession
echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release
echo "deb http://deb.debian.org/debian sid main" >> /etc/apt/sources.list.d/sid.list
apt-get update
apt-get install build-essential cmake pkg-config libcurl4-openssl-dev libjsoncpp-dev doxygen file
apt-get install -t sid libcurlpp-dev
```
#### Centos 7
``` shellsession
wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -i epel-release-latest-7.noarch.rpm
yum install centos-release-scl
yum install devtoolset-6
scl enable devtoolset-6 bash
yum install libcurl-devel doxygen rpm-build
yum --enablerepo=epel install cmake3 jsoncpp-devel
wget https://download.fedoraproject.org/pub/epel/6/x86_64/Packages/c/curlpp-devel-0.7.3-5.el6.x86_64.rpm
wget https://download.fedoraproject.org/pub/epel/6/x86_64/Packages/c/curlpp-0.7.3-5.el6.x86_64.rpm
yum localinstall curlpp-devel-0.7.3-5.el6.x86_64.rpm curlpp-0.7.3-5.el6.x86_64.rpm
```
2018-03-18 01:32:54 +01:00
### Get sourcecode
2018-01-13 15:49:46 +01:00
2018-03-18 01:32:54 +01:00
#### Release
2018-01-13 21:12:07 +01:00
2019-04-14 06:21:26 +02:00
Download the current release at
[schlomp.space ](https://schlomp.space/tastytea/mastodon-cpp/releases ).
2018-01-13 21:12:07 +01:00
2018-03-18 01:32:54 +01:00
#### Development version
2018-01-13 15:49:46 +01:00
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
2018-01-13 15:49:46 +01:00
2019-04-02 11:28:53 +02:00
```shellsession
2018-06-07 23:11:08 +02:00
mkdir build
cd build/
cmake ..
2019-04-14 06:21:26 +02:00
cmake --build . -- -j$(nproc --ignore=1)
2018-06-07 23:11:08 +02:00
```
2018-01-06 21:33:52 +01:00
2018-01-13 21:12:07 +01:00
cmake options:
2019-04-27 23:12:01 +02:00
* `-DCMAKE_BUILD_TYPE=Debug` for a debug build.
2019-04-27 22:03:16 +02:00
* `-DWITH_EASY=NO` to not build the Easy abstractions and to get rid of the
2019-04-27 23:12:01 +02:00
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](https://github.com/catchorg/Catch2/blob/master/docs/command-line.md#specifying-which-tests-to-run)).
2019-04-27 22:44:41 +02:00
* Possible tags: `[api]` , `[auth]` , `[mastodon]` , `[glitch-soc]` ,
2019-04-27 23:12:01 +02:00
`[pleroma]` , `[upload]` .
* `[upload]` tags tests that upload files.
2019-04-27 22:03:16 +02:00
* `-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
2018-01-13 21:12:07 +01:00
2019-04-14 23:08:44 +02:00
Install with `make install` .
### Tests
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
2019-04-27 22:44:41 +02:00
scopes *read* , *write* and *follow* for tests tagged with `[auth]` .
2019-04-14 23:08:44 +02:00
You can select the instance to use with `MASTODON_CPP_INSTANCE` , the default is
2019-04-15 01:11:22 +02:00
*likeable.space*. You can select the user ID with `MASTODON_CPP_USER_ID` , the
2019-04-19 01:58:57 +02:00
default is *9hnrrVPriLiLVAhfVo* . You can select the status ID with
2019-04-19 05:35:43 +02:00
`MASTODON_CPP_STATUS_ID` , the default is *9hwnuJMq3eTdO4s1PU* . You can select
2019-04-25 15:39:50 +02:00
the filter ID with `MASTODON_CPP_FILTER_ID` . You can select the list ID with
2019-04-27 22:33:01 +02:00
`MASTODON_CPP_LIST_ID` , the default is *2* . You can select the media ID with
`MASTODON_CPP_MEDIA_ID` , the default is *2127742613* .
2018-03-08 11:07:41 +01:00
2019-04-16 23:28:04 +02:00
Requirements for the test-user:
* Have at least 1 follower.
* Follow at least 1 account.
* Have at least 1 account endorsed.
* Have at least 1 public or unlisted status.
2019-04-19 01:40:36 +02:00
* Have at least 1 post favourited.
2019-04-20 00:05:56 +02:00
* Have no follow requests.
2019-04-25 14:25:37 +02:00
* Have at least 1 list with at least one account in it.
2019-04-16 23:28:04 +02:00
2018-03-18 01:32:54 +01:00
### Packages
2018-03-08 11:07:41 +01:00
2018-03-18 01:32:54 +01:00
#### DEB and RPM
2018-03-08 11:07:41 +01:00
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-08 11:07:41 +01:00
2018-03-18 01:32:54 +01:00
Run `make package` from the build directory to generate a tar.gz archive.
2018-01-13 15:49:46 +01:00
2018-03-08 11:07:41 +01:00
# Status of implementation
2018-01-13 15:49:46 +01:00
2019-03-03 10:29:43 +01:00
~~Feature complete as of Mastodon 2.6.1~~
2018-03-05 12:12:58 +01:00
2018-01-09 22:12:11 +01:00
* [x] GET /api/v1/accounts/:id
2019-04-16 18:41:09 +02:00
* [x] POST /api/v1/accounts
2018-01-09 22:12:11 +01:00
* [x] GET /api/v1/accounts/verify_credentials
2018-01-22 02:09:44 +01:00
* [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
2018-01-22 02:09:44 +01:00
* [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
2018-01-22 02:09:44 +01:00
* [x] POST /api/v1/apps
2019-04-16 02:51:29 +02:00
* [x] GET /api/v1/apps/verify_credentials
2018-01-12 20:49:15 +01:00
* [x] GET /api/v1/blocks
2019-03-03 10:29:43 +01:00
* [x] POST /api/v1/accounts/:id/block
* [x] POST /api/v1/accounts/:id/unblock
* [x] GET /api/v1/custom_emojis
2018-01-12 20:49:15 +01:00
* [x] GET /api/v1/domain_blocks
2018-01-22 02:09:44 +01:00
* [x] POST /api/v1/domain_blocks
2018-01-24 18:52:24 +01:00
* [x] DELETE /api/v1/domain_blocks
2018-11-17 21:05:07 +01:00
* [x] GET /api/v1/endorsements
* [x] POST /api/v1/accounts/:id/pin
* [x] POST /api/v1/accounts/:id/unpin
2018-01-12 20:49:15 +01:00
* [x] GET /api/v1/favourites
2019-03-03 10:29:43 +01:00
* [x] POST /api/v1/statuses/:id/favourite
* [x] POST /api/v1/statuses/:id/unfavourite
2019-04-19 04:39:46 +02:00
* [x] GET /api/v1/filters
* [x] POST /api/v1/filters
* [x] GET /api/v1/filters/:id
* [x] PUT /api/v1/filters/:id
* [x] DELETE /api/v1/filters/:id
2018-01-12 20:49:15 +01:00
* [x] GET /api/v1/follow_requests
2018-01-22 02:09:44 +01:00
* [x] POST /api/v1/follow_requests/:id/authorize
* [x] POST /api/v1/follow_requests/:id/reject
2019-04-20 00:39:52 +02:00
* [x] GET /api/v1/suggestions
* [x] DELETE /api/v1/suggestions/:account_id
2018-01-12 20:49:15 +01:00
* [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
2018-01-22 02:09:44 +01:00
* [x] POST /api/v1/lists
2018-01-24 18:52:24 +01:00
* [x] PUT /api/v1/lists/:id
* [x] DELETE /api/v1/lists/:id
2018-01-22 02:09:44 +01:00
* [x] POST /api/v1/lists/:id/accounts
2018-01-24 18:52:24 +01:00
* [x] DELETE /api/v1/lists/:id/accounts
2018-01-22 02:09:44 +01:00
* [x] POST /api/v1/media
2018-04-19 01:27:22 +02:00
* [x] PUT /api/v1/media/:id
2018-01-12 20:49:15 +01:00
* [x] GET /api/v1/mutes
2019-03-03 10:29:43 +01:00
* [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
2018-01-12 20:49:15 +01:00
* [x] GET /api/v1/notifications
* [x] GET /api/v1/notifications/:id
2018-01-22 02:09:44 +01:00
* [x] POST /api/v1/notifications/clear
* [x] POST /api/v1/notifications/dismiss
2019-03-03 10:29:43 +01:00
* [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)
2018-01-22 02:09:44 +01:00
* [x] POST /api/v1/reports
2019-03-03 10:29:43 +01:00
* [ ] 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
2018-01-12 20:49:15 +01:00
* [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
2018-01-22 02:09:44 +01:00
* [x] POST /api/v1/statuses
2018-01-24 18:52:24 +01:00
* [x] DELETE /api/v1/statuses/:id
2018-01-22 02:09:44 +01:00
* [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
2018-01-12 20:49:15 +01:00
* [x] GET /api/v1/timelines/home
2019-03-03 10:29:43 +01:00
* [ ] GET /api/v1/conversations
2018-01-12 20:49:15 +01:00
* [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
2019-03-03 10:29:43 +01:00
* [ ] GET /api/v1/streaming/hashtag/local
2018-02-26 07:57:30 +01:00
* [x] GET /api/v1/streaming/list
2019-03-03 10:29:43 +01:00
* [ ] GET /api/v1/streaming/direct
2018-02-11 22:41:47 +01:00
2018-12-04 10:04:54 +01:00
## Glitch-Soc support
* [x] max_toot_chars in /api/v1/instance
2018-12-04 10:34:51 +01:00
* [x] GET /api/v1/bookmarks
* [x] POST /api/v1/statuses/:id/bookmark
* [x] POST /api/v1/statuses/:id/unbookmark
2018-12-04 10:04:54 +01:00
2018-01-06 21:33:52 +01:00
# Copyright
2018-01-13 00:34:16 +01:00
2019-04-02 11:28:53 +02:00
``` text
2019-03-03 10:29:43 +01:00
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.
```