Reformat examples.
This commit is contained in:
parent
3a93aec941
commit
c9211e621e
@ -16,7 +16,7 @@
|
|||||||
// Print information about an instance (/api/v1/instance).
|
// Print information about an instance (/api/v1/instance).
|
||||||
|
|
||||||
#if __has_include("mastodonpp.hpp")
|
#if __has_include("mastodonpp.hpp")
|
||||||
# include "mastodonpp.hpp" // We're building mastodonpp.
|
# include "mastodonpp.hpp" // We're building mastodonpp.
|
||||||
#else
|
#else
|
||||||
# include <mastodonpp/mastodonpp.hpp> // We're building outside mastodonpp.
|
# include <mastodonpp/mastodonpp.hpp> // We're building outside mastodonpp.
|
||||||
#endif
|
#endif
|
||||||
@ -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[])
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
// Print new public events (/api/v1/streaming/public).
|
// Print new public events (/api/v1/streaming/public).
|
||||||
|
|
||||||
#if __has_include("mastodonpp.hpp")
|
#if __has_include("mastodonpp.hpp")
|
||||||
# include "mastodonpp.hpp" // We're building mastodonpp.
|
# include "mastodonpp.hpp" // We're building mastodonpp.
|
||||||
#else
|
#else
|
||||||
# include <mastodonpp/mastodonpp.hpp> // We're building outside mastodonpp.
|
# include <mastodonpp/mastodonpp.hpp> // We're building outside mastodonpp.
|
||||||
#endif
|
#endif
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
// Post a status (/api/v1/status).
|
// Post a status (/api/v1/status).
|
||||||
|
|
||||||
#if __has_include("mastodonpp.hpp")
|
#if __has_include("mastodonpp.hpp")
|
||||||
# include "mastodonpp.hpp" // We're building mastodonpp.
|
# include "mastodonpp.hpp" // We're building mastodonpp.
|
||||||
#else
|
#else
|
||||||
# include <mastodonpp/mastodonpp.hpp> // We're building outside mastodonpp.
|
# include <mastodonpp/mastodonpp.hpp> // We're building outside mastodonpp.
|
||||||
#endif
|
#endif
|
||||||
@ -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)};
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
// Post a status (/api/v1/status) with an attachment (/api/v1/media).
|
// Post a status (/api/v1/status) with an attachment (/api/v1/media).
|
||||||
|
|
||||||
#if __has_include("mastodonpp.hpp")
|
#if __has_include("mastodonpp.hpp")
|
||||||
# include "mastodonpp.hpp" // We're building mastodonpp.
|
# include "mastodonpp.hpp" // We're building mastodonpp.
|
||||||
#else
|
#else
|
||||||
# include <mastodonpp/mastodonpp.hpp> // We're building outside mastodonpp.
|
# include <mastodonpp/mastodonpp.hpp> // We're building outside mastodonpp.
|
||||||
#endif
|
#endif
|
||||||
@ -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";
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
// Update notification settings (/api/pleroma/notification_settings).
|
// Update notification settings (/api/pleroma/notification_settings).
|
||||||
|
|
||||||
#if __has_include("mastodonpp.hpp")
|
#if __has_include("mastodonpp.hpp")
|
||||||
# include "mastodonpp.hpp" // We're building mastodonpp.
|
# include "mastodonpp.hpp" // We're building mastodonpp.
|
||||||
#else
|
#else
|
||||||
# include <mastodonpp/mastodonpp.hpp> // We're building outside mastodonpp.
|
# include <mastodonpp/mastodonpp.hpp> // We're building outside mastodonpp.
|
||||||
#endif
|
#endif
|
||||||
@ -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,14 +50,14 @@ 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"},
|
||||||
{"remote", "true"},
|
{"remote", "true"},
|
||||||
{"local", "true"},
|
{"local", "true"},
|
||||||
})};
|
})};
|
||||||
if (answer)
|
if (answer)
|
||||||
{
|
{
|
||||||
cout << answer << endl;
|
cout << answer << endl;
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
// Update account display name settings (/api/v1/accounts/update_credentials).
|
// Update account display name settings (/api/v1/accounts/update_credentials).
|
||||||
|
|
||||||
#if __has_include("mastodonpp.hpp")
|
#if __has_include("mastodonpp.hpp")
|
||||||
# include "mastodonpp.hpp" // We're building mastodonpp.
|
# include "mastodonpp.hpp" // We're building mastodonpp.
|
||||||
#else
|
#else
|
||||||
# include <mastodonpp/mastodonpp.hpp> // We're building outside mastodonpp.
|
# include <mastodonpp/mastodonpp.hpp> // We're building outside mastodonpp.
|
||||||
#endif
|
#endif
|
||||||
@ -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";
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
// Post a status (/api/v1/status), then delete it (/api/v1/statuses/:id).
|
// Post a status (/api/v1/status), then delete it (/api/v1/statuses/:id).
|
||||||
|
|
||||||
#if __has_include("mastodonpp.hpp")
|
#if __has_include("mastodonpp.hpp")
|
||||||
# include "mastodonpp.hpp" // We're building mastodonpp.
|
# include "mastodonpp.hpp" // We're building mastodonpp.
|
||||||
#else
|
#else
|
||||||
# include <mastodonpp/mastodonpp.hpp> // We're building outside mastodonpp.
|
# include <mastodonpp/mastodonpp.hpp> // We're building outside mastodonpp.
|
||||||
#endif
|
#endif
|
||||||
@ -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[])
|
||||||
{
|
{
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
// Obtain an access token and verify that it works.
|
// Obtain an access token and verify that it works.
|
||||||
|
|
||||||
#if __has_include("mastodonpp.hpp")
|
#if __has_include("mastodonpp.hpp")
|
||||||
# include "mastodonpp.hpp" // We're building mastodonpp.
|
# include "mastodonpp.hpp" // We're building mastodonpp.
|
||||||
#else
|
#else
|
||||||
# include <mastodonpp/mastodonpp.hpp> // We're building outside mastodonpp.
|
# include <mastodonpp/mastodonpp.hpp> // We're building outside mastodonpp.
|
||||||
#endif
|
#endif
|
||||||
@ -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);
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
// nlohmann-json. <https://github.com/nlohmann/json>
|
// nlohmann-json. <https://github.com/nlohmann/json>
|
||||||
|
|
||||||
#if __has_include("mastodonpp.hpp")
|
#if __has_include("mastodonpp.hpp")
|
||||||
# include "mastodonpp.hpp" // We're building mastodonpp.
|
# include "mastodonpp.hpp" // We're building mastodonpp.
|
||||||
#else
|
#else
|
||||||
# include <mastodonpp/mastodonpp.hpp> // We're building outside mastodonpp.
|
# include <mastodonpp/mastodonpp.hpp> // We're building outside mastodonpp.
|
||||||
#endif
|
#endif
|
||||||
@ -26,19 +26,19 @@
|
|||||||
#if __has_include(<nlohmann/json.hpp>)
|
#if __has_include(<nlohmann/json.hpp>)
|
||||||
# include <nlohmann/json.hpp>
|
# include <nlohmann/json.hpp>
|
||||||
|
|
||||||
#include <cstdlib>
|
# include <cstdlib>
|
||||||
#include <iostream>
|
# include <iostream>
|
||||||
#include <string>
|
# include <string>
|
||||||
#include <string_view>
|
# include <string_view>
|
||||||
#include <vector>
|
# include <vector>
|
||||||
|
|
||||||
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);
|
||||||
@ -138,11 +135,11 @@ void handle_error(const masto::answer_type &answer)
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#include <iostream>
|
# include <iostream>
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
std::cout << "Example could not be compiled "
|
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>)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user