summaryrefslogtreecommitdiffstats
path: root/src/instance.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/instance.cpp')
-rw-r--r--src/instance.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/instance.cpp b/src/instance.cpp
index b7f88cd..1c7491c 100644
--- a/src/instance.cpp
+++ b/src/instance.cpp
@@ -18,13 +18,17 @@
#include "instance.hpp"
#include "log.hpp"
+#include <algorithm>
#include <exception>
+#include <vector>
namespace mastodonpp
{
+using std::sort;
using std::stoull;
using std::exception;
+using std::vector;
Instance::Instance(const string_view hostname, const string_view access_token)
: _hostname{hostname}
@@ -77,4 +81,31 @@ uint64_t Instance::get_max_chars()
return _max_chars;
}
+answer_type Instance::get_nodeinfo()
+{
+ debuglog << "Finding location of NodeInfo on " << _hostname << "…\n";
+ auto answer{make_request(http_method::GET,
+ _baseuri + "/.well-known/nodeinfo", {})};
+ if (!answer)
+ {
+ debuglog << "NodeInfo not found.\n";
+ return answer;
+ }
+
+ size_t pos{0};
+ vector<string> hrefs;
+ constexpr string_view searchstring{R"("href":")"};
+ while ((pos = answer.body.find(searchstring, pos)) != string::npos)
+ {
+ pos += searchstring.size();
+ auto endpos{answer.body.find('"', pos)};
+ hrefs.push_back(answer.body.substr(pos, endpos - pos));
+ debuglog << "Found href: " << hrefs.back() << '\n';
+ }
+ sort(hrefs.begin(), hrefs.end()); // We assume they are sortable strings.
+ debuglog << "Selecting href: " << hrefs.back() << '\n';
+
+ return make_request(http_method::GET, hrefs.back(), {});
+}
+
} // namespace mastodonpp