diff --git a/.drone.yml b/.drone.yml index 987065e..c4e19d2 100644 --- a/.drone.yml +++ b/.drone.yml @@ -13,17 +13,17 @@ trigger: - tag steps: -- name: download mastodon-cpp for buster +- name: download mastodonpp for buster image: plugins/download settings: - source: https://schlomp.space/tastytea/mastodon-cpp/releases/download/0.111.5/libmastodon-cpp_0.111.5-0_buster_amd64.deb - destination: mastodon-cpp_buster.deb + source: https://schlomp.space/tastytea/mastodonpp/releases/download/0.4.0/libmastodonpp_0.4.0-0_amd64_buster.deb + destination: mastodonpp_buster.deb -# - name: download mastodon-cpp for bionic +# - name: download mastodonpp for bionic # image: plugins/download # settings: -# source: https://schlomp.space/tastytea/mastodon-cpp/releases/download/0.111.5/libmastodon-cpp_0.111.5-0_bionic_amd64.deb -# destination: mastodon-cpp_bionic.deb +# source: https://schlomp.space/tastytea/mastodonpp/releases/download/0.4.0/libmastodonpp_0.4.0-0_amd64_bionic.deb +# destination: mastodonpp_bionic.deb # Workaround until the debian packages are fixed. - name: download restclient-cpp source @@ -50,7 +50,7 @@ steps: - apt-get update -q - apt-get install -qq build-essential cmake asciidoc - apt-get install -qq libboost-filesystem-dev libboost-log-dev libboost-regex-dev libjsoncpp-dev catch libcurl4-openssl-dev restclient-cpp libpoco-dev - - apt-get -qq install ./mastodon-cpp_buster.deb + - apt-get -qq install ./mastodonpp_buster.deb - tar -xf restclient-cpp.tar.gz - cd restclient-cpp-* - cmake -DCMAKE_INSTALL_PREFIX=/usr . @@ -83,7 +83,7 @@ steps: # - apt-get update -q # - apt-get install -qq build-essential cmake asciidoc # - apt-get install -qq libboost-filesystem-dev libboost-log-dev libboost-regex-dev libjsoncpp-dev catch libcurl4-openssl-dev restclient-cpp libpoco-dev -# - apt-get -qq install ./mastodon-cpp_bionic.deb +# - apt-get -qq install ./mastodonpp_bionic.deb # - rm -rf build && mkdir -p build && cd build # - cmake .. # - make VERBOSE=1 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3d84df8..550afed 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,7 +6,7 @@ find_package(jsoncpp REQUIRED CONFIG) # 1.7.4 (Debian buster) has no version. find_package(CURL 7.52 REQUIRED) find_package(Threads REQUIRED) find_package(restclient-cpp 0.5 CONFIG) -find_package(mastodon-cpp REQUIRED CONFIG) +find_package(mastodonpp 0.4 REQUIRED CONFIG) if(NOT ${restclient-cpp_FOUND}) find_file(restclient_h NAMES "restclient-cpp/restclient.h" @@ -31,7 +31,7 @@ file(GLOB sources *.cpp) add_executable(mastorss ${sources}) target_link_libraries(mastorss PRIVATE - jsoncpp_lib restclient-cpp mastodon-cpp::mastodon-cpp + jsoncpp_lib restclient-cpp mastodonpp::mastodonpp Boost::filesystem Boost::log Boost::regex) if(BUILD_SHARED_LIBS) target_compile_definitions(mastorss PRIVATE "BOOST_ALL_DYN_LINK=1") diff --git a/src/config.cpp b/src/config.cpp index da22df7..769779b 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -18,7 +18,7 @@ #include "exceptions.hpp" #include -#include +#include #include #include @@ -192,32 +192,29 @@ string Config::get_access_token(const string &instance) const string client_id; string client_secret; string url; - Mastodon::API masto(instance, ""); + mastodonpp::Instance masto{instance, ""}; + mastodonpp::Instance::ObtainToken token{masto}; - auto ret = masto.register_app1("mastorss", "urn:ietf:wg:oauth:2.0:oob", - "write", - "https://schlomp.space/tastytea/mastorss", - client_id, client_secret, url); + auto ret{token.step_1("mastorss", "write:statuses", + "https://schlomp.space/tastytea/mastorss")}; if (ret) { string code; string access_token; - cout << "Visit " << url << " to authorize this application.\n"; + cout << "Visit " << ret << " to authorize this application.\n"; cout << "Insert code: "; std::getline(cin, code); - ret = masto.register_app2(client_id, client_secret, - "urn:ietf:wg:oauth:2.0:oob", - code, access_token); + ret = token.step_2(code); if (ret) { - BOOST_LOG_TRIVIAL(debug) << "Got access token: " << access_token; + BOOST_LOG_TRIVIAL(debug) << "Got access token."; return access_token; } } - throw MastodonException{ret.error_code}; + throw MastodonException{ret.curl_error_code}; } void Config::parse() diff --git a/src/document.cpp b/src/document.cpp index 9354b20..c327445 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include @@ -214,7 +214,7 @@ void Document::parse_rss(const pt::ptree &tree) string Document::remove_html(string html) const { - html = Mastodon::unescape_html(html); // Decode HTML entities. + html = mastodonpp::unescape_html(html); // Decode HTML entities. html = regex_replace(html, regex{"

"}, "\n\n"); diff --git a/src/mastoapi.cpp b/src/mastoapi.cpp index f7ae1ed..e26112a 100644 --- a/src/mastoapi.cpp +++ b/src/mastoapi.cpp @@ -29,7 +29,7 @@ using std::string_view; MastoAPI::MastoAPI(ProfileData &data) : _profile{data} - , _masto{_profile.instance, _profile.access_token} + , _instance{_profile.instance, _profile.access_token} { } @@ -100,20 +100,21 @@ void MastoAPI::post_item(const Item &item) BOOST_LOG_TRIVIAL(debug) << "Status length: " << status.size(); BOOST_LOG_TRIVIAL(debug) << "Status: \"" << status << '"'; - Mastodon::parameters params{{"status", {status}}}; + mastodonpp::parametermap params{{"status", status}}; if (_profile.titles_as_cw) { - params.push_back({"spoiler_text", {item.title}}); + params.insert({"spoiler_text", item.title}); } - const auto ret = _masto.post(Mastodon::API::v1::statuses, params); + mastodonpp::Connection connection{_instance}; + const auto ret = connection.post(mastodonpp::API::v1::statuses, params); if (!ret) { - if (ret.http_error_code != 200) + if (ret.http_status != 200) { - throw HTTPException{ret.http_error_code}; + throw HTTPException{ret.http_status}; } - throw MastodonException{ret.error_code}; + throw MastodonException{ret.curl_error_code}; } BOOST_LOG_TRIVIAL(debug) << "Posted status with GUID: " << item.guid; diff --git a/src/mastoapi.hpp b/src/mastoapi.hpp index d0cde7a..63775cc 100644 --- a/src/mastoapi.hpp +++ b/src/mastoapi.hpp @@ -20,7 +20,7 @@ #include "config.hpp" #include "document.hpp" -#include +#include namespace mastorss { @@ -33,7 +33,7 @@ public: private: ProfileData &_profile; - Mastodon::API _masto; + mastodonpp::Instance _instance; constexpr static size_t _max_guids{100}; }; } // namespace mastorss