From b768015b526034749ac56797341230c6a5941abd Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Fri, 4 Sep 2020 00:57:14 +0100 Subject: [PATCH] Implement ApiNap::fame_list() --- src/oro/api_nap.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/oro/api_nap.cpp b/src/oro/api_nap.cpp index f257d05..6a740c1 100644 --- a/src/oro/api_nap.cpp +++ b/src/oro/api_nap.cpp @@ -68,6 +68,19 @@ R get_or_default (const sj::simdjson_result& elem, R def) { const simdjson::error_code error = elem.get(retval); return (not error ? static_cast(retval) : def); } + +void fill_creator_list (const sjd::element& elem, std::vector& out) { + if (elem.is_array()) { + auto creators = elem.get_array(); + out.reserve(creators.size()); + for (auto creator : creators) { + Creator new_entry; + new_entry.char_id = static_cast(creator["char_id"].get_uint64()); + new_entry.name = creator["name"]; + new_entry.points = static_cast(creator["points"].get_uint64()); + out.push_back(std::move(new_entry)); + } + } } } //unnamed namespace @@ -197,6 +210,13 @@ std::pair ApiNap::market_list() { } std::pair ApiNap::fame_list() { + return fetch_and_parse( + g_endpoint_fame_list, + [](const simdjson::dom::element& doc, Creators& out) { + fill_creator_list(doc["brewers"], out.brewers); + fill_creator_list(doc["forgers"], out.brewers); + } + ); } template