Add items_icons() to Api.

This commit is contained in:
King_DuckZ 2020-06-22 22:29:14 +02:00
parent fd147c4f2a
commit fd5c29ca54
4 changed files with 43 additions and 4 deletions

View file

@ -29,10 +29,12 @@ int main(int argc, char* argv[]) {
{
auto items = oro_api.items_list();
for (const auto& item : items.second.items) {
std::cout << "Item ID " << item.item_id << ' ' << item.name << '\n';
}
std::cout << "Total items in DB: " << items.second.items.size() << '\n';
}
{
auto icons = oro_api.items_icons();
std::cout << "Total icons in DB: " << icons.second.icons.size() << '\n';
}
return 0;
}

View file

@ -39,11 +39,26 @@ BOOST_FUSION_ADAPT_STRUCT(
(std::vector<oro::Item>, items)
)
BOOST_FUSION_ADAPT_STRUCT(
oro::Icon,
(unsigned int, item_id)
(std::string, icon)
)
BOOST_FUSION_ADAPT_STRUCT(
oro::Icons,
(oro::Timestamp, generation_timestamp)
(int, version)
(std::vector<oro::Icon>, icons)
)
namespace oro {
namespace {
constexpr const std::int64_t g_max_json_mem = 1024 * 1024 * 20;
constexpr const char g_endpoint_ping[] = "api/v1/ping";
constexpr const char g_endpoint_whoami[] = "api/v1/whoami";
constexpr const char g_endpoint_items_list[] = "api/v1/items/list";
constexpr const char g_endpoint_items_icons[] = "api/v1/items/icons";
template <typename T>
std::pair<Header, T> call_rest_api (
@ -82,7 +97,7 @@ namespace {
}
T retval;
rc::SerializeFromJson(retval, std::move(reply));
rc::SerializeFromJson(retval, std::move(reply), nullptr, g_max_json_mem);
return std::make_pair(std::move(h), std::move(retval));
}).get();
@ -119,4 +134,8 @@ std::pair<Header, Items> Api::items_list() {
return call_rest_api<oro::Items>(*m_client, m_prefix + g_endpoint_items_list, m_api_key, m_client_name, m_client_purpose);
}
std::pair<Header, Icons> Api::items_icons() {
return call_rest_api<oro::Icons>(*m_client, m_prefix + g_endpoint_items_icons, m_api_key, m_client_name, m_client_purpose);
}
} //namespace oro

View file

@ -3,6 +3,7 @@
#include "ping.hpp"
#include "whoami.hpp"
#include "items.hpp"
#include "icons.hpp"
#include <string>
#include <utility>
#include <memory>
@ -58,6 +59,7 @@ public:
std::pair<Header, Ping> ping();
std::pair<Header, WhoAmI> who_am_i();
std::pair<Header, Items> items_list();
std::pair<Header, Icons> items_icons();
private:
std::string m_prefix;

16
src/oro/icons.hpp Normal file
View file

@ -0,0 +1,16 @@
#pragma once
#include "datatypes.hpp"
#include <vector>
#include <string>
namespace oro {
struct Icon {
unsigned int item_id;
std::string icon;
};
struct Icons : BaseJsonReply {
std::vector<Icon> icons;
};
} //namespace oro