diff --git a/.drone.yml b/.drone.yml index 4ebd1fb..249f69c 100644 --- a/.drone.yml +++ b/.drone.yml @@ -2,7 +2,7 @@ pipeline: download: image: plugins/download pull: true - source: https://schlomp.space/attachments/74cfa418-aecd-403d-9abe-ab3f5e3cce48 + source: https://schlomp.space/attachments/e1c1e64b-1192-4037-aad4-95238ad648b0 destination: mastodon-cpp.deb gcc8: diff --git a/README.md b/README.md index fd496d4..dbe8683 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,8 @@ The documentation is far from complete, sorry. * [cmake](https://cmake.org/) (tested: 3.9 / 3.12) * [boost](http://www.boost.org/) (tested: 1.65 / 1.62) * [curlpp](http://www.curlpp.org/) (tested: 0.8) - * [mastodon-cpp](https://schlomp.space/tastytea/mastodon-cpp) (at least: 0.18.9) + * [mastodon-cpp](https://schlomp.space/tastytea/mastodon-cpp) (at least: + 0.105.0) * [jsoncpp](https://github.com/open-source-parsers/jsoncpp) (tested: 1.8 / 1.7) ## Get sourcecode @@ -36,10 +37,10 @@ Install with `make install`. # Usage -Put `watchwords.json` into `~/.config/mastorss/`. Launch with profile name. -The first occurence of every watchword in an RSS item will be turned into a hashtag. -For profile-specific watchwords see the example in `watchwords.json`. -In the first run only the newest entry is tooted. +Put `watchwords.json` into `~/.config/mastorss/`. Launch with profile name. The +first occurence of every watchword in an RSS item will be turned into a hashtag. +For profile-specific watchwords see the example in `watchwords.json`. In the +first run only the newest entry is tooted. The profile can't be named "global". @@ -81,7 +82,9 @@ plus: # Copyright - Copyright © 2018 tastytea . - License GPLv3: GNU GPL version 3 . - This program comes with ABSOLUTELY NO WARRANTY. This is free software, - and you are welcome to redistribute it under certain conditions. +``` text +Copyright © 2018, 2019 tastytea . +License GPLv3: GNU GPL version 3 . +This program comes with ABSOLUTELY NO WARRANTY. This is free software, +and you are welcome to redistribute it under certain conditions. +``` diff --git a/src/config.cpp b/src/config.cpp index 234ab33..c0edeaa 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -1,5 +1,5 @@ /* This file is part of mastorss. - * Copyright © 2018 tastytea + * Copyright © 2018, 2019 tastytea * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -74,14 +74,15 @@ std::uint16_t read_config(string &instance, string &access_token, string &feedur cout << "No access token found.\n"; string client_id, client_secret, url; Mastodon::API masto(instance, ""); - std::uint16_t ret = masto.register_app1("mastorss", - "urn:ietf:wg:oauth:2.0:oob", - "write", - "https://schlomp.space/tastytea/mastorss", - client_id, - client_secret, - url); - if (ret == 0) + Mastodon::return_call ret + = masto.register_app1("mastorss", + "urn:ietf:wg:oauth:2.0:oob", + "write", + "https://schlomp.space/tastytea/mastorss", + client_id, + client_secret, + url); + if (!ret) { string code; cout << "Visit " << url << " to authorize this application.\n"; @@ -93,21 +94,21 @@ std::uint16_t read_config(string &instance, string &access_token, string &feedur "urn:ietf:wg:oauth:2.0:oob", code, access_token); - if (ret == 0) + if (!ret) { config[profile]["access_token"] = access_token; config_changed = true; } else { - cerr << "Error code: " << ret << '\n'; - return ret; + cerr << "Error code: " << ret.error_code << '\n'; + return ret.error_code; } } else { - cerr << "Error code: " << ret << '\n'; - return ret; + cerr << "Error code: " << ret.error_code << '\n'; + return ret.error_code; } } diff --git a/src/mastorss.cpp b/src/mastorss.cpp index 4218897..28e33a8 100644 --- a/src/mastorss.cpp +++ b/src/mastorss.cpp @@ -1,5 +1,5 @@ /* This file is part of mastorss. - * Copyright © 2018 tastytea + * Copyright © 2018, 2019 tastytea * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,10 +27,12 @@ #include "version.hpp" #include "mastorss.hpp" -using Mastodon::API; +using namespace Mastodon; + using std::cout; using std::cerr; using std::cin; +using std::endl; using std::string; using std::this_thread::sleep_for; using std::chrono::seconds; @@ -98,42 +100,54 @@ int main(int argc, char *argv[]) continue; } - Mastodon::Easy::Status answer; - Mastodon::Easy masto(instance, access_token); + Easy::return_entity ret_status; + Mastodon::Easy::API masto(instance, access_token); - answer = masto.send_post(*rit, ret); + ret_status = masto.send_post(*rit); - if (ret != 0) + if (!ret_status) { - switch (ret) + const uint8_t err = ret_status.error_code; + switch (err) { - case 15: - std::cerr << "Error " << ret << ": Network error\n"; - break; - case 16: - std::cerr << "Error " << ret << ": Timeout\n"; - break; - case 403: - std::cerr << "Error " << ret << ": Forbidden\n"; - break; - case 404: - std::cerr << "Error " << ret << ": Not found\n"; - break; - case 503: - std::cerr << "Error " << ret << ": Service Unavailable\n"; - break; - default: - std::cerr << "Error " << ret << '\n'; + case 110: + { + cerr << "Error " << err << ": Timeout\n"; + break; + } + case 111: + { + cerr << "Error " << err << ": Connection refused\n"; + cerr << "HTTP Error " << ret_status.http_error_code << endl; + break; + } + case 113: + { + cerr << "Error " << err << ": Could not reach host.\n"; + break; + } + case 192: + case 193: + { + cerr << "Error " << err << ": curlpp error\n"; + break; + } + default: + { + cerr << "Error " << err << '\n'; + cerr << "HTTP status " << ret_status.http_error_code << endl; + } } - std::cerr << answer.to_object().asString() << '\n'; + cerr << ret_status.entity.to_string() << '\n'; return ret; } - if (answer.to_object().isNull()) + if (!ret_status.entity.valid()) { - std::cerr << "Could not send post for unknown reasons.\n"; - std::cerr << "Please file a bug at .\n"; + cerr << "Could not send post for unknown reasons.\n"; + cerr << "Please file a bug at " + ".\n"; return 1; } diff --git a/src/parse.cpp b/src/parse.cpp index 985a928..d8b6b77 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -1,5 +1,5 @@ /* This file is part of mastorss. - * Copyright © 2018 tastytea + * Copyright © 2018, 2019 tastytea * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -83,7 +83,7 @@ std::vector parse_feed(const string &xml) string content = ""; if (config[profile]["titles_as_cw"].asBool()) { - status.spoiler_text(Mastodon::API::unescape_html(title)); + status.spoiler_text(Mastodon::unescape_html(title)); } else { @@ -130,7 +130,7 @@ std::vector parse_feed(const string &xml) continue; } - content = Mastodon::API::unescape_html(content); + content = Mastodon::unescape_html(content); // Try to turn the HTML into human-readable text std::regex reparagraph("

");