2018-01-13 00:34:16 +01:00
**mastodon-cpp** is a C++ wrapper for the Mastodon API. The aim is to be as simple as possible.
2018-01-09 22:12:11 +01:00
The library takes care of the network stuff. You submit a query and get the raw JSON.
2018-02-22 03:04:15 +01:00
All versions below 1.0.0 (SOVERSION 0) are considered unstable and can change any time.
2018-01-06 21:33:52 +01:00
# Install
2018-01-13 15:49:46 +01:00
2018-01-06 21:33:52 +01:00
## Dependencies
2018-01-13 15:49:46 +01:00
2018-02-27 01:55:03 +01:00
* Tested OS: GNU/Linux, Termux/Android
2018-01-26 00:24:00 +01:00
* C++ compiler (tested: gcc 6.4, clang 5.0)
2018-01-06 21:33:52 +01:00
* [cmake ](https://cmake.org/ ) (tested: 3.9.6)
2018-02-09 16:17:32 +01:00
* [libcurl ](https://curl.haxx.se/ ) (tested: 7.58.0)
* [curlpp ](http://www.curlpp.org/ ) (tested: 0.8.1)
2018-02-13 11:27:04 +01:00
* Optional, documentation: [doxygen ](https://www.stack.nl/~dimitri/doxygen/ ) (tested: 1.8.13)
* Optional, examples: [boost ](http://www.boost.org/ ) (tested: 1.63.0)
2018-01-06 21:33:52 +01:00
## Get sourcecode
2018-01-13 15:49:46 +01:00
2018-01-13 21:12:07 +01:00
### Release
Download the current release at [GitHub ](https://github.com/tastytea/mastodon-cpp/releases ).
2018-01-06 21:33:52 +01:00
### Development version
2018-01-13 15:49:46 +01:00
2018-01-13 16:07:00 +01:00
git clone https://github.com/tastytea/mastodon-cpp.git
2018-01-06 21:33:52 +01:00
## Compile
2018-01-13 15:49:46 +01:00
2018-01-06 21:33:52 +01:00
mkdir build
cd build/
cmake ..
make
2018-01-13 21:12:07 +01:00
cmake options:
* `-DCMAKE_BUILD_TYPE=Debug` for a debug build
* `-DWITH_EXAMPLES=ON` if you want to compile the examples
* `-DWITH_TESTS=ON` if you want to compile the tests
* `-DWITH_DOC=ON` if you want to compile the HTML reference
You can run the tests with `ctest ..` inside the build directory.
Install with `make install` .
2018-01-13 15:49:46 +01:00
2018-01-06 21:33:52 +01:00
# Usage
2018-02-11 17:16:20 +01:00
The HTML reference can be generated with `build_doc.sh` , if doxygen is installed.
Or just look in `src/mastodon-cpp.hpp` . It is also available at [tastytea.github.io/mastodon-cpp/ ](https://tastytea.github.io/mastodon-cpp/docs/classMastodon_1_1API.html ).
There are examples in `src/examples/` .
2018-01-06 21:33:52 +01:00
2018-01-15 20:23:21 +01:00
## Most basic example
#include < iostream >
#include < string >
#include < mastodon-cpp.hpp >
int main()
{
2018-01-22 04:45:12 +01:00
Mastodon::API masto("social.example.com", "auth_token");
2018-01-15 20:23:21 +01:00
std::string answer;
2018-02-09 16:17:32 +01:00
masto.get(Mastodon::API::v1::accounts_verify_credentials, answer);
2018-01-15 20:23:21 +01:00
std::cout < < answer << ' \n';
}
2018-01-13 16:32:43 +01:00
## Compiling your project
After you did a `make install` , a project consisting of one file can be compiled as follows:
2018-02-09 16:17:32 +01:00
g++ -std=c++14 -lmastodon-cpp example.cpp
2018-01-13 16:32:43 +01:00
2018-01-13 15:49:46 +01:00
## Error codes
| Code | Explanation |
| --------: |:------------------------------|
| 0 | No error |
| 1 | Invalid call |
| 2 | Not implemented |
2018-02-17 20:01:51 +01:00
| 3 | URL changed (HTTP 301 or 308) |
2018-02-26 07:57:30 +01:00
| 4 | Aborted by user |
| 10 | Failed to connect |
2018-02-27 01:55:03 +01:00
| 11 | Couldn't resolve host |
2018-02-27 02:03:44 +01:00
| 12 | Network is unreachable |
2018-02-13 11:27:04 +01:00
| 100 - 999 | HTTP status codes |
| 65535 | Unknown error |
| | Deprecated (since 0.2.10) |
| --------: |:------------------------------|
2018-01-13 15:49:46 +01:00
| 16 | Connection failed |
| 17 | TLS error |
| 18 | Invalid response from server |
If you use a debug build, you get more verbose error messages.
2018-02-22 22:26:16 +01:00
## Useful links
* [Mastodon API reference ](https://github.com/tootsuite/documentation/blob/master/Using-the-API/API.md )
* [Mastodon streaming API reference ](https://github.com/tootsuite/documentation/blob/master/Using-the-API/Streaming-API.md )
2018-01-09 22:12:11 +01:00
# TODO
2018-01-13 15:49:46 +01:00
2018-02-22 03:04:15 +01:00
* Version 0.1.0
2018-01-13 16:07:00 +01:00
* [x] Implement all GET calls
2018-01-13 15:49:46 +01:00
* [x] Usable error handling
2018-01-09 22:12:11 +01:00
* [x] Network stuff
2018-01-13 15:49:46 +01:00
* [x] Comprehensive example
2018-02-22 03:04:15 +01:00
* Version 0.2.0
* [x] Escape user input
* [x] Implement all PATCH calls
* [x] Implement all POST calls
* [x] Implement all PUT calls
* [x] Implement all DELETE calls
* Version 0.3.0
2018-02-17 20:01:51 +01:00
* [x] Handle HTTP statuses 301, 302, 307 and 308
2018-02-09 22:19:25 +01:00
* [x] Support registering as an application
2018-02-22 03:04:15 +01:00
* Version 0.4.0
2018-02-26 09:06:55 +01:00
* [x] Make HTTP header available
2018-02-26 07:57:30 +01:00
* [x] Streaming API
2018-02-22 03:04:15 +01:00
* Later
2018-01-13 00:34:16 +01:00
* [ ] Asynchronous I/O
2018-02-17 20:01:51 +01:00
* [ ] Improve error reporting
2018-01-09 22:12:11 +01:00
## Status of implementation
2018-01-13 15:49:46 +01:00
2018-01-09 22:12:11 +01:00
* [x] GET /api/v1/accounts/:id
* [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
* [x] POST /api/v1/accounts/:id/block
* [x] POST /api/v1/accounts/:id/unblock
* [x] POST /api/v1/accounts/:id/mute
* [x] POST /api/v1/accounts/:id/unmute
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
2018-01-12 20:49:15 +01:00
* [x] GET /api/v1/blocks
* [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-01-12 20:49:15 +01:00
* [x] GET /api/v1/favourites
* [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
* [x] POST /api/v1/follows
2018-01-12 20:49:15 +01:00
* [x] GET /api/v1/instance
* [x] GET /api/v1/custom_emojis
* [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-01-12 20:49:15 +01:00
* [x] GET /api/v1/mutes
* [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
2018-01-12 20:49:15 +01:00
* [x] GET /api/v1/reports
2018-01-22 02:09:44 +01:00
* [x] POST /api/v1/reports
2018-01-12 20:49:15 +01:00
* [x] GET /api/v1/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
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/favourite
* [x] POST /api/v1/statuses/:id/unfavourite
* [x] POST /api/v1/statuses/:id/pin
* [x] POST /api/v1/statuses/:id/unpin
* [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/timelines/home
* [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
* [x] GET /api/v1/streaming/list
2018-02-11 22:41:47 +01:00
2018-01-06 21:33:52 +01:00
# Copyright
2018-01-13 00:34:16 +01:00
2018-01-09 22:12:11 +01:00
Copyright © 2018 tastytea < tastytea @ tastytea . de > .
2018-01-06 21:33:52 +01: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.