actual functions */
| 40 | |
| 41 | /* actual functions */ |
| 42 | void getTips(std::function<void(int, int, const std::string&, const std::string&)> onFetch) |
| 43 | { |
| 44 | httplib::Client cli(WebAPI::URL.c_str()); |
| 45 | auto res = cli.Get("/tips.xml"); |
| 46 | |
| 47 | if (res && res->status == 200) { |
| 48 | pugi::xml_document doc; |
| 49 | pugi::xml_parse_result result = doc.load_string(res->body.c_str()); |
| 50 | if (!result) { |
| 51 | Logger::Get().Log("Failed to parse tips.xml", true); |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | auto tips = doc.child("tips"); |
| 56 | int tipCount = std::distance(tips.children("tip").begin(), tips.children("tip").end()); |
| 57 | |
| 58 | int index = threadSafeRandom(0, tipCount - 1); |
| 59 | |
| 60 | pugi::xml_node tip; |
| 61 | int curInd = 0; |
| 62 | |
| 63 | for (auto cTip : tips.children("tip")) { |
| 64 | if (curInd == index) { |
| 65 | tip = cTip; |
| 66 | break; |
| 67 | } |
| 68 | |
| 69 | curInd++; |
| 70 | } |
| 71 | |
| 72 | std::string tipTitle(tip.child("title").text().as_string()); |
| 73 | std::string tipText(tip.child("text").text().as_string()); |
| 74 | onFetch(tipCount, index, tipTitle, tipText); |
| 75 | } |
| 76 | } |
| 77 | void getChangelog(std::function<void(const std::string&)> onFetch) |
| 78 | { |
| 79 | httplib::Client cli(WebAPI::URL.c_str()); |
nothing calls this directly
no test coverage detected