diff --git a/CMakeLists.txt b/CMakeLists.txt index a92f117..6fe123c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.7) project (mastobotmon - VERSION 0.2.1 + VERSION 0.2.2 LANGUAGES CXX) include(GNUInstallDirs) diff --git a/README.md b/README.md index da8ccc9..62bef83 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ Same as [mastodon-cpp](https://github.com/tastytea/mastodon-cpp/blob/master/READ | Code | Explanation | | --------: |:------------------------------| | 1 | Couldn't read / create config | +| 2 | Reached limit of API calls | If you use a debug build, you get more verbose error messages. @@ -84,7 +85,7 @@ Mentions are written to `data_dir/mentions_account.csv`. The format is: acct;cre * [x] Allow to add accounts later * [x] Write mentions to file * Version 0.3.0 - * [ ] Respect X-RateLimit header + * [x] Respect X-RateLimit header * [ ] Write statistics to file * Version 0.4.0 * [ ] Daemon mode diff --git a/src/mastobotmon.cpp b/src/mastobotmon.cpp index 7cff56e..d49ec05 100644 --- a/src/mastobotmon.cpp +++ b/src/mastobotmon.cpp @@ -104,6 +104,12 @@ int main(int argc, char *argv[]) { std::string answer; uint16_t ret = acc.get(Mastodon::API::v1::accounts_verify_credentials, answer); + if (std::stoi(acc.get_header("X-RateLimit-Remaining")) < 2) + { + cerr << "ERROR: Reached limit of API calls.\n"; + cerr << "Counter will reset at " << acc.get_header("X-RateLimit-Reset") << '\n'; + return 2; + } if (ret == 0) { Json::Value json;