about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt12
-rw-r--r--wordplay.cpp32
2 files changed, 25 insertions, 19 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index fe7fd64..3f11278 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt
@@ -3,16 +3,20 @@ project (wordplay)
3 3
4find_package(PkgConfig) 4find_package(PkgConfig)
5pkg_check_modules(yaml-cpp yaml-cpp REQUIRED) 5pkg_check_modules(yaml-cpp yaml-cpp REQUIRED)
6pkg_check_modules(mastodonpp mastodonpp REQUIRED)
6 7
7add_subdirectory(vendor/libtwittercpp)
8add_subdirectory(vendor/verbly) 8add_subdirectory(vendor/verbly)
9 9
10include_directories( 10include_directories(
11 vendor/verbly/lib 11 vendor/verbly/lib
12 vendor/libtwittercpp/src 12 ${mastodonpp_INCLUDE_DIRS}
13 ${yaml-cpp_INCLUDE_DIRS}) 13 ${yaml-cpp_INCLUDE_DIRS})
14 14
15link_directories(
16 ${mastodonpp_LIBRARY_DIRS}
17 ${yaml-cpp_LIBRARY_DIRS})
18
15add_executable(wordplay wordplay.cpp) 19add_executable(wordplay wordplay.cpp)
16set_property(TARGET wordplay PROPERTY CXX_STANDARD 11) 20set_property(TARGET wordplay PROPERTY CXX_STANDARD 17)
17set_property(TARGET wordplay PROPERTY CXX_STANDARD_REQUIRED ON) 21set_property(TARGET wordplay PROPERTY CXX_STANDARD_REQUIRED ON)
18target_link_libraries(wordplay verbly twitter++ ${yaml-cpp_LIBRARIES}) 22target_link_libraries(wordplay verbly ${mastodonpp_LIBRARIES} ${yaml-cpp_LIBRARIES})
diff --git a/wordplay.cpp b/wordplay.cpp index 5b60a4f..d5051e6 100644 --- a/wordplay.cpp +++ b/wordplay.cpp
@@ -3,7 +3,7 @@
3#include <iostream> 3#include <iostream>
4#include <list> 4#include <list>
5#include <algorithm> 5#include <algorithm>
6#include <twitter.h> 6#include <mastodonpp/mastodonpp.hpp>
7#include <verbly.h> 7#include <verbly.h>
8#include <chrono> 8#include <chrono>
9#include <thread> 9#include <thread>
@@ -19,13 +19,10 @@ int main(int argc, char** argv)
19 std::string configfile(argv[1]); 19 std::string configfile(argv[1]);
20 YAML::Node config = YAML::LoadFile(configfile); 20 YAML::Node config = YAML::LoadFile(configfile);
21 21
22 twitter::auth auth; 22 mastodonpp::Instance instance{
23 auth.setConsumerKey(config["consumer_key"].as<std::string>()); 23 config["mastodon_instance"].as<std::string>(),
24 auth.setConsumerSecret(config["consumer_secret"].as<std::string>()); 24 config["mastodon_token"].as<std::string>()};
25 auth.setAccessKey(config["access_key"].as<std::string>()); 25 mastodonpp::Connection connection{instance};
26 auth.setAccessSecret(config["access_secret"].as<std::string>());
27
28 twitter::client client(auth);
29 26
30 verbly::database database(config["verbly_datafile"].as<std::string>()); 27 verbly::database database(config["verbly_datafile"].as<std::string>());
31 28
@@ -75,14 +72,19 @@ int main(int argc, char** argv)
75 std::string result = action.compile(); 72 std::string result = action.compile();
76 std::cout << result << std::endl; 73 std::cout << result << std::endl;
77 74
78 try 75 const mastodonpp::parametermap parameters{{"status", result}};
79 { 76 auto answer{connection.post(mastodonpp::API::v1::statuses, parameters)};
80 client.updateStatus(result); 77 if (!answer)
81
82 std::cout << "Tweeted!" << std::endl;
83 } catch (const twitter::twitter_error& e)
84 { 78 {
85 std::cout << "Twitter error: " << e.what() << std::endl; 79 if (answer.curl_error_code == 0)
80 {
81 std::cout << "HTTP status: " << answer.http_status << std::endl;
82 }
83 else
84 {
85 std::cout << "libcurl error " << std::to_string(answer.curl_error_code)
86 << ": " << answer.error_message << std::endl;
87 }
86 } 88 }
87 89
88 std::cout << "Waiting..." << std::endl; 90 std::cout << "Waiting..." << std::endl;