mmcs-quotes-bridge/vk.h

45 lines
1.3 KiB
C++

#pragma once
#include "http.h"
#include "spdlog/logger.h"
#include "uv.h"
#include <chrono>
#include <memory>
#include <optional>
#include <ratio>
#include <string>
#include <variant>
namespace vk {
using namespace http;
struct Post {
inline Post(long id, long date, long editDate, long fromId, std::string postType, std::string text)
: id(id), date(date), editDate(editDate), fromId(fromId), postType(postType), text(text)
{}
long id, date, editDate, fromId;
std::string postType, text;
};
struct WallChunk {
int count;
std::vector<Post> posts;
};
class VKClient {
public:
VKClient(uv_loop_t *eventLoop);
VKClient(VKClient&) = delete;
VKClient(uv_loop_t *eventLoop, std::string serviceKey);
void set_service_api_key(std::string key);
void get_posts(std::variant<long, std::string> wall, int offset, int count, std::function<void(std::optional<WallChunk>, int)> callback);
void get_posts_now(std::variant<long, std::string> wall, int offset, int count, std::function<void(std::optional<WallChunk>, int)> callback);
private:
uv_loop_t *m_eventLoop;
HttpClient m_httpClient;
std::optional<std::string> m_serviceApiKey;
std::shared_ptr<spdlog::logger> m_logger;
std::chrono::steady_clock::time_point m_lastCallTime;
};
}