2023-04-04 17:01:50 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
2023-04-08 07:41:34 +00:00
|
|
|
#include "pixivmodels.h"
|
2023-04-04 17:01:50 +00:00
|
|
|
#include <httplib/httplib.h>
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
|
|
|
|
class PixivClient {
|
|
|
|
public:
|
|
|
|
PixivClient();
|
|
|
|
|
|
|
|
User get_user(uint64_t user_id);
|
2023-04-08 16:27:45 +00:00
|
|
|
Illusts get_illusts(uint64_t user_id, size_t page);
|
2023-04-08 16:06:56 +00:00
|
|
|
Illust get_illust(uint64_t illust_id);
|
2023-04-04 17:01:50 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
nlohmann::json _handle_result(httplib::Result res);
|
|
|
|
httplib::Client _www_pixiv_net_client{"https://www.pixiv.net"};
|
|
|
|
};
|
|
|
|
|
|
|
|
class HTTPLibException : public std::exception {
|
|
|
|
public:
|
|
|
|
HTTPLibException(httplib::Error error) {
|
|
|
|
this->_message = httplib::to_string(error);
|
|
|
|
}
|
|
|
|
|
2023-04-10 14:24:11 +00:00
|
|
|
inline const char* what() const noexcept {
|
2023-04-04 17:01:50 +00:00
|
|
|
return this->_message.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string _message;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PixivException : public std::exception {
|
|
|
|
public:
|
|
|
|
PixivException(int status_, std::string message) : status(status_), _message(std::move(message)) {}
|
|
|
|
|
2023-04-10 14:24:11 +00:00
|
|
|
inline const char* what() const noexcept {
|
2023-04-04 17:01:50 +00:00
|
|
|
return this->_message.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
int status;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string _message;
|
|
|
|
};
|