summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortastytea2020-11-13 14:05:28 +0100
committertastytea2020-11-13 14:05:28 +0100
commitc9211e621ec04bb1ecd052b8af6ac465c68cf242 (patch)
treeffcc31517e931e264e818dc7c82dfe0cc2b5e889
parent3a93aec9410ff2f828bd9795241ab032a0cd0b10 (diff)
downloadmastodonpp-c9211e621ec04bb1ecd052b8af6ac465c68cf242.tar
mastodonpp-c9211e621ec04bb1ecd052b8af6ac465c68cf242.tar.gz
mastodonpp-c9211e621ec04bb1ecd052b8af6ac465c68cf242.zip
Reformat examples.
-rw-r--r--examples/example01_instance_info.cpp6
-rw-r--r--examples/example02_streaming.cpp14
-rw-r--r--examples/example03_post_status.cpp18
-rw-r--r--examples/example04_post_with_attachment.cpp20
-rw-r--r--examples/example05_update_notification_settings.cpp22
-rw-r--r--examples/example06_update_name.cpp14
-rw-r--r--examples/example07_delete_status.cpp8
-rw-r--r--examples/example08_obtain_token.cpp14
-rw-r--r--examples/example09_nlohmann_json.cpp33
9 files changed, 71 insertions, 78 deletions
diff --git a/examples/example01_instance_info.cpp b/examples/example01_instance_info.cpp
index aa32b28..45ca291 100644
--- a/examples/example01_instance_info.cpp
+++ b/examples/example01_instance_info.cpp
@@ -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[])
diff --git a/examples/example02_streaming.cpp b/examples/example02_streaming.cpp
index 748e5f8..07ac4bc 100644
--- a/examples/example02_streaming.cpp
+++ b/examples/example02_streaming.cpp
@@ -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;
}
}
diff --git a/examples/example03_post_status.cpp b/examples/example03_post_status.cpp
index bdf88dc..be7068d 100644
--- a/examples/example03_post_status.cpp
+++ b/examples/example03_post_status.cpp
@@ -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)};
diff --git a/examples/example04_post_with_attachment.cpp b/examples/example04_post_with_attachment.cpp
index 2f8b3db..6e3f5ea 100644
--- a/examples/example04_post_with_attachment.cpp
+++ b/examples/example04_post_with_attachment.cpp
@@ -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";
diff --git a/examples/example05_update_notification_settings.cpp b/examples/example05_update_notification_settings.cpp
index f4c1fca..08f5cf8 100644
--- a/examples/example05_update_notification_settings.cpp
+++ b/examples/example05_update_notification_settings.cpp
@@ -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;
diff --git a/examples/example06_update_name.cpp b/examples/example06_update_name.cpp
index 2db1a95..1378259 100644
--- a/examples/example06_update_name.cpp
+++ b/examples/example06_update_name.cpp
@@ -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";
diff --git a/examples/example07_delete_status.cpp b/examples/example07_delete_status.cpp
index 864ba9f..0c2c34b 100644
--- a/examples/example07_delete_status.cpp
+++ b/examples/example07_delete_status.cpp
@@ -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[])
{
diff --git a/examples/example08_obtain_token.cpp b/examples/example08_obtain_token.cpp
index 3f9cca0..c708b5e 100644
--- a/examples/example08_obtain_token.cpp
+++ b/examples/example08_obtain_token.cpp
@@ -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);
diff --git a/examples/example09_nlohmann_json.cpp b/examples/example09_nlohmann_json.cpp
index ad94fac..60840e7 100644
--- a/examples/example09_nlohmann_json.cpp
+++ b/examples/example09_nlohmann_json.cpp
@@ -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>)