Reformat examples.

This commit is contained in:
tastytea 2020-11-13 14:05:28 +01:00
parent 3a93aec941
commit c9211e621e
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
9 changed files with 71 additions and 78 deletions

View File

@ -27,11 +27,11 @@
#include <vector> #include <vector>
namespace masto = mastodonpp; namespace masto = mastodonpp;
using std::cout;
using std::cerr; using std::cerr;
using std::cout;
using std::endl; using std::endl;
using std::to_string;
using std::string_view; using std::string_view;
using std::to_string;
using std::vector; using std::vector;
int main(int argc, char *argv[]) int main(int argc, char *argv[])

View File

@ -30,14 +30,14 @@
namespace masto = mastodonpp; namespace masto = mastodonpp;
using namespace std::chrono_literals; using namespace std::chrono_literals;
using std::cout;
using std::cerr; using std::cerr;
using std::cout;
using std::endl; using std::endl;
using std::to_string;
using std::string_view; using std::string_view;
using std::thread; using std::thread;
using std::this_thread::sleep_for; using std::to_string;
using std::vector; using std::vector;
using std::this_thread::sleep_for;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
@ -61,8 +61,10 @@ int main(int argc, char *argv[])
if (answer && answer.body == "OK") if (answer && answer.body == "OK")
{ {
// Make a thread, get all public events. // Make a thread, get all public events.
// clang-format off
thread stream_thread{[&] thread stream_thread{[&]
{ {
// clang-format on
answer = connection.get(masto::API::v1::streaming_public); answer = connection.get(masto::API::v1::streaming_public);
}}; }};
@ -73,8 +75,8 @@ int main(int argc, char *argv[])
for (const auto &event : connection.get_new_events()) for (const auto &event : connection.get_new_events())
{ {
// Print type of event and the beginning of the data. // Print type of event and the beginning of the data.
cout << event.type << ": " cout << event.type << ": " << event.data.substr(0, 70)
<< event.data.substr(0, 70) << "" << endl; << "" << endl;
} }
} }

View File

@ -27,11 +27,11 @@
#include <vector> #include <vector>
namespace masto = mastodonpp; namespace masto = mastodonpp;
using std::cout;
using std::cerr; using std::cerr;
using std::cout;
using std::endl; using std::endl;
using std::to_string;
using std::string_view; using std::string_view;
using std::to_string;
using std::vector; using std::vector;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
@ -51,12 +51,12 @@ int main(int argc, char *argv[])
// Set up the parameters. // Set up the parameters.
constexpr auto poll_seconds{60 * 60 * 24 * 2}; // 2 days. constexpr auto poll_seconds{60 * 60 * 24 * 2}; // 2 days.
const masto::parametermap parameters const masto::parametermap parameters{{"status", "How is the weather?"},
{ {"poll[options]",
{"status", "How is the weather?"}, vector<string_view>{"Nice",
{"poll[options]", vector<string_view>{"Nice", "not nice"}}, "not nice"}},
{"poll[expires_in]", to_string(poll_seconds)} {"poll[expires_in]",
}; to_string(poll_seconds)}};
// Post the status. // Post the status.
auto answer{connection.post(masto::API::v1::statuses, parameters)}; auto answer{connection.post(masto::API::v1::statuses, parameters)};

View File

@ -27,12 +27,12 @@
#include <vector> #include <vector>
namespace masto = mastodonpp; namespace masto = mastodonpp;
using std::cout;
using std::cerr; using std::cerr;
using std::cout;
using std::endl; using std::endl;
using std::string; using std::string;
using std::to_string;
using std::string_view; using std::string_view;
using std::to_string;
using std::vector; using std::vector;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
@ -54,10 +54,8 @@ int main(int argc, char *argv[])
// Create attachment. // Create attachment.
auto answer{connection.post(masto::API::v1::media, auto answer{connection.post(masto::API::v1::media,
{ {{"file", string("@file:") += filename},
{"file", string("@file:") += filename}, {"description", "Test."}})};
{"description", "Test."}
})};
// Get the ID of the attachment. // Get the ID of the attachment.
// You normally would use a JSON parser, of course. I don't use one // You normally would use a JSON parser, of course. I don't use one
@ -69,11 +67,9 @@ int main(int argc, char *argv[])
// Post the status. Note that “media_ids” always has to be a vector. // Post the status. Note that “media_ids” always has to be a vector.
answer = connection.post(masto::API::v1::statuses, answer = connection.post(masto::API::v1::statuses,
{ {{"status", "Attachment test."},
{"status", "Attachment test."},
{"media_ids", {"media_ids",
vector<string_view>{media_id}} vector<string_view>{media_id}}});
});
if (answer) if (answer)
{ {
cout << "Successfully posted " << filename << ".\n"; cout << "Successfully posted " << filename << ".\n";

View File

@ -27,11 +27,11 @@
#include <vector> #include <vector>
namespace masto = mastodonpp; namespace masto = mastodonpp;
using std::cout;
using std::cerr; using std::cerr;
using std::cout;
using std::endl; using std::endl;
using std::to_string;
using std::string_view; using std::string_view;
using std::to_string;
using std::vector; using std::vector;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
@ -50,8 +50,8 @@ int main(int argc, char *argv[])
masto::Connection connection{instance}; masto::Connection connection{instance};
// Update the settings. // Update the settings.
const auto answer{connection.put( const auto answer{
masto::API::pleroma::notification_settings, connection.put(masto::API::pleroma::notification_settings,
{ {
{"followers", "true"}, {"followers", "true"},
{"follows", "true"}, {"follows", "true"},

View File

@ -27,11 +27,11 @@
#include <vector> #include <vector>
namespace masto = mastodonpp; namespace masto = mastodonpp;
using std::cout;
using std::cerr; using std::cerr;
using std::cout;
using std::endl; using std::endl;
using std::to_string;
using std::string_view; using std::string_view;
using std::to_string;
using std::vector; using std::vector;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
@ -52,11 +52,9 @@ int main(int argc, char *argv[])
masto::Connection connection{instance}; masto::Connection connection{instance};
// Update the settings. // Update the settings.
const auto answer{connection.patch( const auto answer{
masto::API::v1::accounts_update_credentials, connection.patch(masto::API::v1::accounts_update_credentials,
{ {{"display_name", name}})};
{"display_name", name}
})};
if (answer) if (answer)
{ {
cout << "Successfully changed display name.\n"; cout << "Successfully changed display name.\n";

View File

@ -30,13 +30,13 @@
namespace masto = mastodonpp; namespace masto = mastodonpp;
using namespace std::chrono_literals; using namespace std::chrono_literals;
using std::cout;
using std::cerr; using std::cerr;
using std::cout;
using std::endl; using std::endl;
using std::to_string;
using std::string_view; using std::string_view;
using std::this_thread::sleep_for; using std::to_string;
using std::vector; using std::vector;
using std::this_thread::sleep_for;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {

View File

@ -28,14 +28,14 @@
#include <vector> #include <vector>
namespace masto = mastodonpp; namespace masto = mastodonpp;
using std::exit;
using std::cout;
using std::cerr; using std::cerr;
using std::endl;
using std::cin; using std::cin;
using std::cout;
using std::endl;
using std::exit;
using std::string; using std::string;
using std::to_string;
using std::string_view; using std::string_view;
using std::to_string;
using std::vector; using std::vector;
void handle_error(const masto::answer_type &answer); void handle_error(const masto::answer_type &answer);
@ -109,8 +109,8 @@ void handle_error(const masto::answer_type &answer)
else else
{ {
// Network errors like “Couldn't resolve host.”. // Network errors like “Couldn't resolve host.”.
cerr << "libcurl error " << to_string(answer.curl_error_code) cerr << "libcurl error " << to_string(answer.curl_error_code) << ": "
<< ": " << answer.error_message << endl; << answer.error_message << endl;
} }
exit(1); exit(1);

View File

@ -34,11 +34,11 @@
namespace masto = mastodonpp; namespace masto = mastodonpp;
using json = nlohmann::json; using json = nlohmann::json;
using std::exit;
using std::cout;
using std::cerr; using std::cerr;
using std::to_string; using std::cout;
using std::exit;
using std::string_view; using std::string_view;
using std::to_string;
using std::vector; using std::vector;
void handle_error(const masto::answer_type &answer); void handle_error(const masto::answer_type &answer);
@ -60,10 +60,7 @@ int main(int argc, char *argv[])
// Get the last 4 public statuses of the instance. // Get the last 4 public statuses of the instance.
auto answer{connection.get(masto::API::v1::timelines_public, auto answer{connection.get(masto::API::v1::timelines_public,
{ {{"limit", "4"}, {"local", "true"}})};
{"limit", "4"},
{"local", "true"}
})};
if (answer) if (answer)
{ {
// Parse JSON string. // Parse JSON string.
@ -129,8 +126,8 @@ void handle_error(const masto::answer_type &answer)
else else
{ {
// Network errors like “Couldn't resolve host.”. // Network errors like “Couldn't resolve host.”.
cerr << "libcurl error " << to_string(answer.curl_error_code) cerr << "libcurl error " << to_string(answer.curl_error_code) << ": "
<< ": " << answer.error_message << '\n'; << answer.error_message << '\n';
} }
exit(1); exit(1);