Reformat examples.
This commit is contained in:
parent
3a93aec941
commit
c9211e621e
@ -27,11 +27,11 @@
|
||||
#include <vector>
|
||||
|
||||
namespace masto = mastodonpp;
|
||||
using std::cout;
|
||||
using std::cerr;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::to_string;
|
||||
using std::string_view;
|
||||
using std::to_string;
|
||||
using std::vector;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
@ -30,14 +30,14 @@
|
||||
|
||||
namespace masto = mastodonpp;
|
||||
using namespace std::chrono_literals;
|
||||
using std::cout;
|
||||
using std::cerr;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::to_string;
|
||||
using std::string_view;
|
||||
using std::thread;
|
||||
using std::this_thread::sleep_for;
|
||||
using std::to_string;
|
||||
using std::vector;
|
||||
using std::this_thread::sleep_for;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
@ -61,8 +61,10 @@ int main(int argc, char *argv[])
|
||||
if (answer && answer.body == "OK")
|
||||
{
|
||||
// Make a thread, get all public events.
|
||||
// clang-format off
|
||||
thread stream_thread{[&]
|
||||
{
|
||||
// clang-format on
|
||||
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())
|
||||
{
|
||||
// Print type of event and the beginning of the data.
|
||||
cout << event.type << ": "
|
||||
<< event.data.substr(0, 70) << " …" << endl;
|
||||
cout << event.type << ": " << event.data.substr(0, 70)
|
||||
<< " …" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,11 +27,11 @@
|
||||
#include <vector>
|
||||
|
||||
namespace masto = mastodonpp;
|
||||
using std::cout;
|
||||
using std::cerr;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::to_string;
|
||||
using std::string_view;
|
||||
using std::to_string;
|
||||
using std::vector;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@ -51,12 +51,12 @@ int main(int argc, char *argv[])
|
||||
|
||||
// Set up the parameters.
|
||||
constexpr auto poll_seconds{60 * 60 * 24 * 2}; // 2 days.
|
||||
const masto::parametermap parameters
|
||||
{
|
||||
{"status", "How is the weather?"},
|
||||
{"poll[options]", vector<string_view>{"Nice", "not nice"}},
|
||||
{"poll[expires_in]", to_string(poll_seconds)}
|
||||
};
|
||||
const masto::parametermap parameters{{"status", "How is the weather?"},
|
||||
{"poll[options]",
|
||||
vector<string_view>{"Nice",
|
||||
"not nice"}},
|
||||
{"poll[expires_in]",
|
||||
to_string(poll_seconds)}};
|
||||
|
||||
// Post the status.
|
||||
auto answer{connection.post(masto::API::v1::statuses, parameters)};
|
||||
|
@ -27,12 +27,12 @@
|
||||
#include <vector>
|
||||
|
||||
namespace masto = mastodonpp;
|
||||
using std::cout;
|
||||
using std::cerr;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::string;
|
||||
using std::to_string;
|
||||
using std::string_view;
|
||||
using std::to_string;
|
||||
using std::vector;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@ -54,10 +54,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
// Create attachment.
|
||||
auto answer{connection.post(masto::API::v1::media,
|
||||
{
|
||||
{"file", string("@file:") += filename},
|
||||
{"description", "Test."}
|
||||
})};
|
||||
{{"file", string("@file:") += filename},
|
||||
{"description", "Test."}})};
|
||||
|
||||
// Get the ID of the attachment.
|
||||
// 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.
|
||||
answer = connection.post(masto::API::v1::statuses,
|
||||
{
|
||||
{"status", "Attachment test."},
|
||||
{{"status", "Attachment test."},
|
||||
{"media_ids",
|
||||
vector<string_view>{media_id}}
|
||||
});
|
||||
vector<string_view>{media_id}}});
|
||||
if (answer)
|
||||
{
|
||||
cout << "Successfully posted " << filename << ".\n";
|
||||
|
@ -27,11 +27,11 @@
|
||||
#include <vector>
|
||||
|
||||
namespace masto = mastodonpp;
|
||||
using std::cout;
|
||||
using std::cerr;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::to_string;
|
||||
using std::string_view;
|
||||
using std::to_string;
|
||||
using std::vector;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@ -50,8 +50,8 @@ int main(int argc, char *argv[])
|
||||
masto::Connection connection{instance};
|
||||
|
||||
// Update the settings.
|
||||
const auto answer{connection.put(
|
||||
masto::API::pleroma::notification_settings,
|
||||
const auto answer{
|
||||
connection.put(masto::API::pleroma::notification_settings,
|
||||
{
|
||||
{"followers", "true"},
|
||||
{"follows", "true"},
|
||||
|
@ -27,11 +27,11 @@
|
||||
#include <vector>
|
||||
|
||||
namespace masto = mastodonpp;
|
||||
using std::cout;
|
||||
using std::cerr;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::to_string;
|
||||
using std::string_view;
|
||||
using std::to_string;
|
||||
using std::vector;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@ -52,11 +52,9 @@ int main(int argc, char *argv[])
|
||||
masto::Connection connection{instance};
|
||||
|
||||
// Update the settings.
|
||||
const auto answer{connection.patch(
|
||||
masto::API::v1::accounts_update_credentials,
|
||||
{
|
||||
{"display_name", name}
|
||||
})};
|
||||
const auto answer{
|
||||
connection.patch(masto::API::v1::accounts_update_credentials,
|
||||
{{"display_name", name}})};
|
||||
if (answer)
|
||||
{
|
||||
cout << "Successfully changed display name.\n";
|
||||
|
@ -30,13 +30,13 @@
|
||||
|
||||
namespace masto = mastodonpp;
|
||||
using namespace std::chrono_literals;
|
||||
using std::cout;
|
||||
using std::cerr;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::to_string;
|
||||
using std::string_view;
|
||||
using std::this_thread::sleep_for;
|
||||
using std::to_string;
|
||||
using std::vector;
|
||||
using std::this_thread::sleep_for;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
@ -28,14 +28,14 @@
|
||||
#include <vector>
|
||||
|
||||
namespace masto = mastodonpp;
|
||||
using std::exit;
|
||||
using std::cout;
|
||||
using std::cerr;
|
||||
using std::endl;
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::exit;
|
||||
using std::string;
|
||||
using std::to_string;
|
||||
using std::string_view;
|
||||
using std::to_string;
|
||||
using std::vector;
|
||||
|
||||
void handle_error(const masto::answer_type &answer);
|
||||
@ -109,8 +109,8 @@ void handle_error(const masto::answer_type &answer)
|
||||
else
|
||||
{
|
||||
// Network errors like “Couldn't resolve host.”.
|
||||
cerr << "libcurl error " << to_string(answer.curl_error_code)
|
||||
<< ": " << answer.error_message << endl;
|
||||
cerr << "libcurl error " << to_string(answer.curl_error_code) << ": "
|
||||
<< answer.error_message << endl;
|
||||
}
|
||||
|
||||
exit(1);
|
||||
|
@ -26,19 +26,19 @@
|
||||
#if __has_include(<nlohmann/json.hpp>)
|
||||
# include <nlohmann/json.hpp>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
# include <cstdlib>
|
||||
# include <iostream>
|
||||
# include <string>
|
||||
# include <string_view>
|
||||
# include <vector>
|
||||
|
||||
namespace masto = mastodonpp;
|
||||
using json = nlohmann::json;
|
||||
using std::exit;
|
||||
using std::cout;
|
||||
using std::cerr;
|
||||
using std::to_string;
|
||||
using std::cout;
|
||||
using std::exit;
|
||||
using std::string_view;
|
||||
using std::to_string;
|
||||
using std::vector;
|
||||
|
||||
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.
|
||||
auto answer{connection.get(masto::API::v1::timelines_public,
|
||||
{
|
||||
{"limit", "4"},
|
||||
{"local", "true"}
|
||||
})};
|
||||
{{"limit", "4"}, {"local", "true"}})};
|
||||
if (answer)
|
||||
{
|
||||
// Parse JSON string.
|
||||
@ -129,8 +126,8 @@ void handle_error(const masto::answer_type &answer)
|
||||
else
|
||||
{
|
||||
// Network errors like “Couldn't resolve host.”.
|
||||
cerr << "libcurl error " << to_string(answer.curl_error_code)
|
||||
<< ": " << answer.error_message << '\n';
|
||||
cerr << "libcurl error " << to_string(answer.curl_error_code) << ": "
|
||||
<< answer.error_message << '\n';
|
||||
}
|
||||
|
||||
exit(1);
|
||||
@ -138,7 +135,7 @@ void handle_error(const masto::answer_type &answer)
|
||||
|
||||
#else
|
||||
|
||||
#include <iostream>
|
||||
# include <iostream>
|
||||
int main()
|
||||
{
|
||||
std::cout << "Example could not be compiled "
|
||||
|
Loading…
x
Reference in New Issue
Block a user