Implement ApiNap::fame_list()
This commit is contained in:
parent
571a92aa2e
commit
b768015b52
1 changed files with 20 additions and 0 deletions
|
@ -68,6 +68,19 @@ R get_or_default (const sj::simdjson_result<sjd::element>& elem, R def) {
|
||||||
const simdjson::error_code error = elem.get(retval);
|
const simdjson::error_code error = elem.get(retval);
|
||||||
return (not error ? static_cast<R>(retval) : def);
|
return (not error ? static_cast<R>(retval) : def);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void fill_creator_list (const sjd::element& elem, std::vector<Creator>& 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<unsigned int>(creator["char_id"].get_uint64());
|
||||||
|
new_entry.name = creator["name"];
|
||||||
|
new_entry.points = static_cast<unsigned int>(creator["points"].get_uint64());
|
||||||
|
out.push_back(std::move(new_entry));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} //unnamed namespace
|
} //unnamed namespace
|
||||||
|
@ -197,6 +210,13 @@ std::pair<Header, Shops> ApiNap::market_list() {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<Header, Creators> ApiNap::fame_list() {
|
std::pair<Header, Creators> ApiNap::fame_list() {
|
||||||
|
return fetch_and_parse<Creators>(
|
||||||
|
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 <typename T, typename F>
|
template <typename T, typename F>
|
||||||
|
|
Loading…
Reference in a new issue