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

@ -16,7 +16,7 @@
// Print information about an instance (/api/v1/instance).
#if __has_include("mastodonpp.hpp")
# include "mastodonpp.hpp" // We're building mastodonpp.
# include "mastodonpp.hpp" // We're building mastodonpp.
#else
# include <mastodonpp/mastodonpp.hpp> // We're building outside mastodonpp.
#endif
@ -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[])

View File

@ -16,7 +16,7 @@
// Print new public events (/api/v1/streaming/public).
#if __has_include("mastodonpp.hpp")
# include "mastodonpp.hpp" // We're building mastodonpp.
# include "mastodonpp.hpp" // We're building mastodonpp.
#else
# include <mastodonpp/mastodonpp.hpp> // We're building outside mastodonpp.
#endif
@ -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;
}
}

View File

@ -16,7 +16,7 @@
// Post a status (/api/v1/status).
#if __has_include("mastodonpp.hpp")
# include "mastodonpp.hpp" // We're building mastodonpp.
# include "mastodonpp.hpp" // We're building mastodonpp.
#else
# include <mastodonpp/mastodonpp.hpp> // We're building outside mastodonpp.
#endif
@ -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)};

View File

@ -16,7 +16,7 @@
// Post a status (/api/v1/status) with an attachment (/api/v1/media).
#if __has_include("mastodonpp.hpp")
# include "mastodonpp.hpp" // We're building mastodonpp.
# include "mastodonpp.hpp" // We're building mastodonpp.
#else
# include <mastodonpp/mastodonpp.hpp> // We're building outside mastodonpp.
#endif
@ -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."},
{"media_ids",
vector<string_view>{media_id}}
});
{{"status", "Attachment test."},
{"media_ids",
vector<string_view>{media_id}}});
if (answer)
{
cout << "Successfully posted " << filename << ".\n";

View File

@ -16,7 +16,7 @@
// Update notification settings (/api/pleroma/notification_settings).
#if __has_include("mastodonpp.hpp")
# include "mastodonpp.hpp" // We're building mastodonpp.
# include "mastodonpp.hpp" // We're building mastodonpp.
#else
# include <mastodonpp/mastodonpp.hpp> // We're building outside mastodonpp.
#endif
@ -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,14 +50,14 @@ int main(int argc, char *argv[])
masto::Connection connection{instance};
// Update the settings.
const auto answer{connection.put(
masto::API::pleroma::notification_settings,
{
{"followers", "true"},
{"follows", "true"},
{"remote", "true"},
{"local", "true"},
})};
const auto answer{
connection.put(masto::API::pleroma::notification_settings,
{
{"followers", "true"},
{"follows", "true"},
{"remote", "true"},
{"local", "true"},
})};
if (answer)
{
cout << answer << endl;

View File

@ -16,7 +16,7 @@
// Update account display name settings (/api/v1/accounts/update_credentials).
#if __has_include("mastodonpp.hpp")
# include "mastodonpp.hpp" // We're building mastodonpp.
# include "mastodonpp.hpp" // We're building mastodonpp.
#else
# include <mastodonpp/mastodonpp.hpp> // We're building outside mastodonpp.
#endif
@ -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";

View File

@ -16,7 +16,7 @@
// Post a status (/api/v1/status), then delete it (/api/v1/statuses/:id).
#if __has_include("mastodonpp.hpp")
# include "mastodonpp.hpp" // We're building mastodonpp.
# include "mastodonpp.hpp" // We're building mastodonpp.
#else
# include <mastodonpp/mastodonpp.hpp> // We're building outside mastodonpp.
#endif
@ -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[])
{

View File

@ -16,7 +16,7 @@
// Obtain an access token and verify that it works.
#if __has_include("mastodonpp.hpp")
# include "mastodonpp.hpp" // We're building mastodonpp.
# include "mastodonpp.hpp" // We're building mastodonpp.
#else
# include <mastodonpp/mastodonpp.hpp> // We're building outside mastodonpp.
#endif
@ -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);

View File

@ -17,7 +17,7 @@
// nlohmann-json. <https://github.com/nlohmann/json>
#if __has_include("mastodonpp.hpp")
# include "mastodonpp.hpp" // We're building mastodonpp.
# include "mastodonpp.hpp" // We're building mastodonpp.
#else
# include <mastodonpp/mastodonpp.hpp> // We're building outside mastodonpp.
#endif
@ -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,11 +135,11 @@ void handle_error(const masto::answer_type &answer)
#else
#include <iostream>
# include <iostream>
int main()
{
std::cout << "Example could not be compiled "
"because nlohmann-json was not found.\n";
"because nlohmann-json was not found.\n";
}
#endif // __has_include(<nlohmann/json.hpp>)
#endif // __has_include(<nlohmann/json.hpp>)