mirror of
https://github.com/davidallendj/gdpm.git
synced 2025-12-19 19:17:01 -07:00
More refactoring and bug fixes
- Added `libhttp` and `librest_api` targets to CMakeLists.txt - Added examples for `libhttp` and `librest_api` in examples directory - Added `cache` and `add` commands - Added documentation for `libhttp` and `librest_api` - Added all available HTTP response codes to REST API - Changed how `bin/compile.sh` works (must supply args to build)
This commit is contained in:
parent
5a73651ad1
commit
8b1f1374d8
23 changed files with 575 additions and 164 deletions
|
|
@ -12,8 +12,8 @@
|
|||
|
||||
namespace gdpm::cache {
|
||||
struct params {
|
||||
std::string cache_path = GDPM_PACKAGE_CACHE_PATH;
|
||||
std::string table_name = GDPM_PACKAGE_CACHE_TABLENAME;
|
||||
string cache_path = GDPM_PACKAGE_CACHE_PATH;
|
||||
string table_name = GDPM_PACKAGE_CACHE_TABLENAME;
|
||||
};
|
||||
|
||||
error create_package_database(bool overwrite = false, const params& = params());
|
||||
|
|
@ -22,11 +22,11 @@ namespace gdpm::cache {
|
|||
result_t<package::info_list> get_package_info_by_title(const package::title_list& package_titles, const params& params = cache::params());
|
||||
result_t<package::info_list> get_installed_packages(const params& = params());
|
||||
error update_package_info(const package::info_list& packages, const params& = params());
|
||||
error update_sync_info(const std::vector<std::string>& download_urls, const params& = params());
|
||||
error update_sync_info(const args_t& download_urls, const params& = params());
|
||||
error delete_packages(const package::title_list& package_titles, const params& = params());
|
||||
error delete_packages(const package::id_list& package_ids, const params& = params());
|
||||
error drop_package_database(const params& = params());
|
||||
|
||||
result_t<std::string> to_values(const package::info& package);
|
||||
result_t<std::string> to_values(const package::info_list& packages);
|
||||
result_t<string> to_values(const package::info& package);
|
||||
result_t<string> to_values(const package::info_list& packages);
|
||||
}
|
||||
6
include/concepts.hpp
Normal file
6
include/concepts.hpp
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#pragma once
|
||||
#include <string>
|
||||
|
||||
namespace gdpm::concepts{
|
||||
template <typename...Args> concept RequireMinArgs = requires (std::size_t min){ sizeof...(Args) > min; };
|
||||
}
|
||||
|
|
@ -28,7 +28,7 @@ namespace gdpm::config{
|
|||
string to_json(const context& params);
|
||||
error load(std::filesystem::path path, context& config, int verbose = 0);
|
||||
error save(std::filesystem::path path, const context& config, int verbose = 0);
|
||||
context make_context(const std::string& username = GDPM_CONFIG_USERNAME, const string& password = GDPM_CONFIG_PASSWORD, const string& path = GDPM_CONFIG_PATH, const string& token = GDPM_CONFIG_TOKEN, const string& godot_version = GDPM_CONFIG_GODOT_VERSION, const string& packages_dir = GDPM_CONFIG_LOCAL_PACKAGES_DIR, const string& tmp_dir = GDPM_CONFIG_LOCAL_TMP_DIR, const string_map& remote_sources = {GDPM_CONFIG_REMOTE_SOURCES}, size_t threads = GDPM_CONFIG_THREADS, size_t timeout = 0, bool enable_sync = GDPM_CONFIG_ENABLE_SYNC, bool enable_file_logging = GDPM_CONFIG_ENABLE_FILE_LOGGING, int verbose = GDPM_CONFIG_VERBOSE);
|
||||
context make_context(const string& username = GDPM_CONFIG_USERNAME, const string& password = GDPM_CONFIG_PASSWORD, const string& path = GDPM_CONFIG_PATH, const string& token = GDPM_CONFIG_TOKEN, const string& godot_version = GDPM_CONFIG_GODOT_VERSION, const string& packages_dir = GDPM_CONFIG_LOCAL_PACKAGES_DIR, const string& tmp_dir = GDPM_CONFIG_LOCAL_TMP_DIR, const string_map& remote_sources = {GDPM_CONFIG_REMOTE_SOURCES}, size_t threads = GDPM_CONFIG_THREADS, size_t timeout = 0, bool enable_sync = GDPM_CONFIG_ENABLE_SYNC, bool enable_file_logging = GDPM_CONFIG_ENABLE_FILE_LOGGING, int verbose = GDPM_CONFIG_VERBOSE);
|
||||
error validate(const rapidjson::Document& doc);
|
||||
|
||||
extern context config;
|
||||
|
|
|
|||
|
|
@ -78,9 +78,7 @@ namespace gdpm{
|
|||
string get_message() const { return m_message; }
|
||||
bool has_occurred() const { return m_code != 0; }
|
||||
|
||||
bool operator()(){
|
||||
return has_occurred();
|
||||
}
|
||||
bool operator()(){ return has_occurred(); }
|
||||
|
||||
private:
|
||||
int m_code;
|
||||
|
|
@ -89,14 +87,20 @@ namespace gdpm{
|
|||
|
||||
// Add logging function that can handle error objects
|
||||
namespace log {
|
||||
template <typename S, typename...Args>
|
||||
static constexpr void error(const gdpm::error& e){
|
||||
#if GDPM_LOG_LEVEL > 1
|
||||
#if GDPM_LOG_LEVEL > ERROR
|
||||
vlog(
|
||||
fmt::format(GDPM_COLOR_LOG_ERROR "[ERROR {}" GDPM_COLOR_LOG_RESET, e.get_message()),
|
||||
fmt::format(GDPM_COLOR_LOG_ERROR "[ERROR {}] {}\n" GDPM_COLOR_LOG_RESET, utils::timestamp(), e.get_message()),
|
||||
fmt::make_format_args("" /*e.get_message()*/)
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename S, typename...Args>
|
||||
static constexpr void error(const S& prefix, const gdpm::error& e){
|
||||
vlog(
|
||||
fmt::format(GDPM_COLOR_LOG_ERROR + prefix + GDPM_COLOR_LOG_RESET, e.get_message())
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,9 +6,73 @@
|
|||
|
||||
namespace gdpm::http{
|
||||
using headers_t = std::unordered_map<string, string>;
|
||||
|
||||
// REF: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
|
||||
enum response_code{
|
||||
OK = 200,
|
||||
NOT_FOUND = 400
|
||||
CONTINUE = 100,
|
||||
SWITCHING_PROTOCOLS = 101,
|
||||
PROCESSING = 102,
|
||||
EARLY_HINTS = 103,
|
||||
OK = 200,
|
||||
CREATED = 201,
|
||||
ACCEPTED = 202,
|
||||
NON_AUTHORITATIVE_INFORMATION = 203,
|
||||
NO_CONTENT = 204,
|
||||
RESET_CONTENT = 205,
|
||||
PARTIAL_CONTENT = 206,
|
||||
MULTI_STATUS = 207,
|
||||
ALREADY_REPORTED = 208,
|
||||
IM_USED = 226,
|
||||
MULTIPLE_CHOICES = 300,
|
||||
MOVED_PERMANENTLY = 301,
|
||||
FOUND = 302,
|
||||
SEE_OTHER = 303,
|
||||
NOT_MODIFIED = 304,
|
||||
USE_PROXY = 305,
|
||||
UNUSED = 306,
|
||||
TEMPORARY_REDIRECT = 307,
|
||||
PERMANENT_REDIRECT = 308,
|
||||
BAD_REQUEST = 400,
|
||||
UNAUTHORIZED = 401,
|
||||
PAYMENT_REQUIRED = 402,
|
||||
FORBIDDEN = 403,
|
||||
NOT_FOUND = 404,
|
||||
METHOD_NOT_ALLOWED = 405,
|
||||
NOT_ACCEPTABLE = 406,
|
||||
PROXY_AUTHENTICATION_REQUIRED = 407,
|
||||
REQUEST_TIMEOUT = 408,
|
||||
CONFLICT = 409,
|
||||
GONE = 410,
|
||||
LENGTH_REQUIRED = 411,
|
||||
PRECONDITION_FAILED = 412,
|
||||
PAYLOAD_TOO_LARGE = 413,
|
||||
URI_TOO_LONG = 414,
|
||||
UNSUPPORTED_MEDIA_TYPE = 415,
|
||||
RANGE_NOT_SATISFIABLE = 416,
|
||||
EXPECTATION_FAILED = 417,
|
||||
IM_A_TEAPOT = 418,
|
||||
MISDIRECTED_REQUEST = 421,
|
||||
UNPROCESSABLE_CONTENT = 422,
|
||||
LOCKED = 423,
|
||||
FAILED_DEPENDENCY = 424,
|
||||
TOO_EARLY = 425,
|
||||
UPGRADE_REQUIRED = 426,
|
||||
PRECONDITION_REQUIRED = 428,
|
||||
TOO_MANY_REQUESTS = 429,
|
||||
REQUEST_HEADER_FILEDS_TOO_LARGE = 431,
|
||||
UNAVAILABLE_FOR_LEGAL_REASONS = 451,
|
||||
INTERNAL_SERVER_ERROR = 500,
|
||||
NOT_IMPLEMENTED = 501,
|
||||
BAD_GATEWAY = 502,
|
||||
SERVICE_UNAVAILABLE = 503,
|
||||
GATEWAY_TIMEOUT = 504,
|
||||
HTTP_VERSION_NOT_SUPPORTED = 505,
|
||||
VARIANT_ALSO_NEGOTIATES = 506,
|
||||
INSUFFICIENT_STORAGE = 507,
|
||||
LOOP_DETECTED = 508,
|
||||
NOT_EXTENDED = 510,
|
||||
NETWORK_AUTHENTICATION_REQUIRED = 511
|
||||
|
||||
};
|
||||
struct response{
|
||||
long code = 0;
|
||||
|
|
@ -18,14 +82,15 @@ namespace gdpm::http{
|
|||
};
|
||||
|
||||
|
||||
struct params {
|
||||
struct request_params {
|
||||
headers_t headers = {};
|
||||
size_t timeout = GDPM_CONFIG_TIMEOUT_MS;
|
||||
int verbose = 0;
|
||||
};
|
||||
|
||||
string url_escape(const string& url);
|
||||
response request_get(const string& url, const http::params& params = http::params());
|
||||
response request_post(const string& url, const char *post_fields="", const http::params& params = http::params());
|
||||
response download_file(const string& url, const string& storage_path, const http::params& params = http::params());
|
||||
response request_get(const string& url, const http::request_params& params = http::request_params());
|
||||
response request_post(const string& url, const http::request_params& params = http::request_params());
|
||||
response download_file(const string& url, const string& storage_path, const http::request_params& params = http::request_params());
|
||||
|
||||
}
|
||||
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include "utils.hpp"
|
||||
#include "colors.hpp"
|
||||
#include "types.hpp"
|
||||
#include <format>
|
||||
// #include <fmt/core.h>
|
||||
|
||||
#if __cplusplus > 201703L
|
||||
|
|
@ -18,22 +20,21 @@ TODO: Write log information to file
|
|||
*/
|
||||
namespace gdpm::log
|
||||
{
|
||||
template <typename...Args> concept RequireMinArgs = requires (std::size_t min){ sizeof...(Args) > min; };
|
||||
|
||||
enum level{
|
||||
NONE,
|
||||
NONE = 0,
|
||||
INFO,
|
||||
WARNING,
|
||||
DEBUG,
|
||||
ERROR
|
||||
};
|
||||
|
||||
struct config {
|
||||
static int level;
|
||||
static std::string prefix;
|
||||
static std::string path;
|
||||
static bool print_to_stdout;
|
||||
static bool print_to_stderr;
|
||||
struct context {
|
||||
int level;
|
||||
string prefix;
|
||||
string path;
|
||||
bool print_to_stdout;
|
||||
bool print_to_stderr;
|
||||
};
|
||||
|
||||
static void vlog(fmt::string_view format, fmt::format_args args){
|
||||
|
|
@ -46,7 +47,7 @@ namespace gdpm::log
|
|||
|
||||
template <typename S, typename...Args>
|
||||
static constexpr void info(const S& format, Args&&...args){
|
||||
#if GDPM_LOG_LEVEL > 0
|
||||
#if GDPM_LOG_LEVEL > NONE
|
||||
vlog(
|
||||
fmt::format(GDPM_COLOR_LOG_INFO "[INFO {}] {}\n" GDPM_COLOR_LOG_RESET, utils::timestamp(), format),
|
||||
// fmt::make_format_args<Args...>(args...)
|
||||
|
|
@ -55,18 +56,40 @@ namespace gdpm::log
|
|||
#endif
|
||||
}
|
||||
|
||||
template <typename S, typename...Args>
|
||||
static constexpr void info(const S& prefix, const S& format, Args&&...args){
|
||||
#if GDPM_LOG_LEVEL > INFO
|
||||
vlog(
|
||||
fmt::format(GDPM_COLOR_LOG_INFO + prefix + GDPM_COLOR_LOG_RESET, format),
|
||||
fmt::make_format_args(args...)
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename S, typename...Args>
|
||||
static constexpr void info(const context& context, const S& format, Args&&...args){
|
||||
#if GDPM_LOG_LEVEL > INFO
|
||||
vlog(
|
||||
fmt::format(GDPM_COLOR_LOG_INFO + context.prefix + GDPM_COLOR_LOG_RESET, format),
|
||||
fmt::make_format_args(args...)
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename S, typename...Args>
|
||||
static constexpr void info_n(const S& format, Args&&...args){
|
||||
#if GDPM_LOG_LEVEL > INFO
|
||||
vlog(
|
||||
fmt::format(GDPM_COLOR_LOG_INFO "[INFO {}] {}" GDPM_COLOR_LOG_RESET, utils::timestamp(), format),
|
||||
// fmt::make_format_args<Args...>(args...)
|
||||
fmt::make_format_args(args...)
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename S, typename...Args>
|
||||
static constexpr void error(const S& format, Args&&...args){
|
||||
#if GDPM_LOG_LEVEL > 1
|
||||
#if GDPM_LOG_LEVEL > ERROR
|
||||
vlog(
|
||||
fmt::format(GDPM_COLOR_LOG_ERROR "[ERROR {}] {}\n" GDPM_COLOR_LOG_RESET, utils::timestamp(), format),
|
||||
// fmt::make_format_args<Args...>(args...)
|
||||
|
|
@ -75,9 +98,29 @@ namespace gdpm::log
|
|||
#endif
|
||||
}
|
||||
|
||||
template <typename S, typename...Args>
|
||||
static constexpr void error(const S& prefix, const S& format, Args&&...args){
|
||||
#if GDPM_LOG_LEVEL > ERROR
|
||||
vlog(
|
||||
fmt::format(GDPM_COLOR_LOG_ERROR + prefix + GDPM_COLOR_LOG_RESET, format),
|
||||
fmt::make_format_args(args...)
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename S, typename...Args>
|
||||
static constexpr void error(const context& context, const S& format, Args&&...args){
|
||||
#if GDPM_LOG_LEVEL > ERROR
|
||||
vlog(
|
||||
fmt::format(GDPM_COLOR_LOG_ERROR + context.prefix + GDPM_COLOR_LOG_RESET, format),
|
||||
fmt::make_format_args(args...)
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename S, typename...Args>
|
||||
static constexpr void debug(const S& format, Args&&...args){
|
||||
#if GDPM_LOG_LEVEL > 1
|
||||
#if GDPM_LOG_LEVEL > DEBUG
|
||||
vlog(
|
||||
fmt::format(GDPM_COLOR_LOG_DEBUG "[DEBUG {}] {}\n" GDPM_COLOR_LOG_RESET, utils::timestamp(), format),
|
||||
// fmt::make_format_args<Args...>(args...)
|
||||
|
|
@ -86,6 +129,26 @@ namespace gdpm::log
|
|||
#endif
|
||||
}
|
||||
|
||||
template <typename S, typename...Args>
|
||||
static constexpr void debug(const S& prefix, const S& format, Args&&...args){
|
||||
#if GDPM_LOG_LEVEL > DEBUG
|
||||
vlog(
|
||||
fmt::format(GDPM_COLOR_LOG_DEBUG + prefix + GDPM_COLOR_LOG_RESET, format),
|
||||
fmt::make_format_args(args...)
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename S, typename...Args>
|
||||
static constexpr void debug(const context& context, const S& format, Args&&...args){
|
||||
#if GDPM_LOG_LEVEL > DEBUG
|
||||
vlog(
|
||||
fmt::format(GDPM_COLOR_LOG_DEBUG + context.prefix + GDPM_COLOR_LOG_RESET, format),
|
||||
fmt::make_format_args(args...)
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename S, typename...Args>
|
||||
static constexpr void print(const S& format, Args&&...args){
|
||||
vlog(
|
||||
|
|
@ -95,7 +158,7 @@ namespace gdpm::log
|
|||
);
|
||||
}
|
||||
|
||||
template <typename S = std::string, typename...Args>
|
||||
template <typename S = string, typename...Args>
|
||||
static constexpr void println(const S& format, Args&&...args){
|
||||
vlog(
|
||||
fmt::format("{}\n", format),
|
||||
|
|
@ -105,7 +168,7 @@ namespace gdpm::log
|
|||
}
|
||||
|
||||
template <typename>
|
||||
static constexpr void println(const std::string& format = ""){
|
||||
static constexpr void println(const string& format = ""){
|
||||
println(format);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,18 +36,18 @@ namespace gdpm::package {
|
|||
std::vector<info> dependencies;
|
||||
};
|
||||
|
||||
enum install_method_e : int{
|
||||
GLOBAL_LINK_LOCAL = 0,
|
||||
GLOBAL_CLONE_LOCAL = 1,
|
||||
GLOBAL_ONLY = 2,
|
||||
LOCAL_ONLY = 3
|
||||
};
|
||||
struct params {
|
||||
enum install_method_e{
|
||||
GLOBAL_LINK_LOCAL,
|
||||
GLOBAL_CLONE_LOCAL,
|
||||
GLOBAL_ONLY,
|
||||
LOCAL_ONLY
|
||||
};
|
||||
bool parallel_jobs = 1;
|
||||
bool use_cache = true;
|
||||
bool use_remote = true;
|
||||
bool skip_prompt = false;
|
||||
std::string remote_source = "";
|
||||
int parallel_jobs = 1;
|
||||
bool enable_cache = true;
|
||||
bool enable_sync = true;
|
||||
bool skip_prompt = false;
|
||||
string remote_source = "";
|
||||
install_method_e install_method = GLOBAL_LINK_LOCAL;
|
||||
};
|
||||
|
||||
|
|
@ -87,7 +87,13 @@ namespace gdpm::package {
|
|||
|
||||
*/
|
||||
GDPM_DLL_EXPORT error install(const config::context& config, const title_list& package_titles, const params& params = package::params());
|
||||
|
||||
/*!
|
||||
@brief Adds package to project locally only.
|
||||
@param config
|
||||
@param package_titles
|
||||
@param params
|
||||
*/
|
||||
GDPM_DLL_EXPORT error add(const config::context& config, const title_list& package_titles, const params& params = package::params());
|
||||
/*!
|
||||
@brief Remove's package and contents from local database.
|
||||
*/
|
||||
|
|
@ -106,6 +112,7 @@ namespace gdpm::package {
|
|||
GDPM_DLL_EXPORT result_t<info_list> get_package_info(const opts_t& opts);
|
||||
GDPM_DLL_EXPORT result_t<title_list> get_package_titles(const info_list& packages);
|
||||
GDPM_DLL_EXPORT void clean_temporary(const config::context& config, const title_list& package_titles);
|
||||
GDPM_DLL_EXPORT params make_params(const var_args& args, const var_opts& opts);
|
||||
|
||||
/* Dependency Management API */
|
||||
GDPM_DLL_EXPORT result_t<info_list> synchronize_database(const config::context& config, const title_list& package_titles);
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
#include <curl/curl.h>
|
||||
|
||||
namespace gdpm::package_manager {
|
||||
extern remote::repository_map repo_sources;
|
||||
extern remote::repository_map remote_sources;
|
||||
extern CURL *curl;
|
||||
extern CURLcode res;
|
||||
extern config::context config;
|
||||
|
|
@ -27,12 +27,13 @@ namespace gdpm::package_manager {
|
|||
};
|
||||
|
||||
struct exec_args{
|
||||
args_t args;
|
||||
opts_t opts;
|
||||
var_args args;
|
||||
var_opts opts;
|
||||
};
|
||||
|
||||
enum class action_e{
|
||||
install,
|
||||
add,
|
||||
remove,
|
||||
update,
|
||||
search,
|
||||
|
|
@ -47,12 +48,12 @@ namespace gdpm::package_manager {
|
|||
none
|
||||
};
|
||||
|
||||
GDPM_DLL_EXPORT result_t<exec_args> initialize(int argc, char **argv);
|
||||
GDPM_DLL_EXPORT int execute(const args_t& args, const opts_t& opts);
|
||||
GDPM_DLL_EXPORT result_t<exec_args> initialize(int argc, char **argv);
|
||||
GDPM_DLL_EXPORT int execute(const exec_args& in);
|
||||
GDPM_DLL_EXPORT void finalize();
|
||||
|
||||
/* Auxiliary Functions */
|
||||
GDPM_DLL_EXPORT cxxargs _parse_arguments(int argc, char **argv);
|
||||
GDPM_DLL_EXPORT result_t<exec_args> _handle_arguments(const cxxargs& args);
|
||||
GDPM_DLL_EXPORT void run_command(action_e command, const package::title_list& package_titles, const opts_t& opts);
|
||||
GDPM_DLL_EXPORT void run_command(action_e command, const var_args& args, const var_opts& opts);
|
||||
}
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
|
||||
|
||||
#pragma once
|
||||
#include "types.hpp"
|
||||
#include <string>
|
||||
|
||||
namespace gdpm::plugin{
|
||||
struct info{
|
||||
std::string name;
|
||||
std::string description;
|
||||
std::string version;
|
||||
string name;
|
||||
string description;
|
||||
string version;
|
||||
};
|
||||
extern int init(int argc, char **argv);
|
||||
extern int set_name(const char *name);
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ namespace gdpm::rest_api{
|
|||
constexpr const char *POST_AssetEditId = "/asset/edit/{id}";
|
||||
}
|
||||
|
||||
bool register_account(const std::string& username, const std::string& password, const std::string& email);
|
||||
bool login(const std::string& username, const std::string& password);
|
||||
bool register_account(const string& username, const string& password, const string& email);
|
||||
bool login(const string& username, const string& password);
|
||||
bool logout();
|
||||
// bool change_password()
|
||||
|
||||
|
|
@ -38,9 +38,9 @@ namespace gdpm::rest_api{
|
|||
type_e type;
|
||||
int category;
|
||||
support_e support;
|
||||
std::string filter;
|
||||
std::string user;
|
||||
std::string godot_version;
|
||||
string filter;
|
||||
string user;
|
||||
string godot_version;
|
||||
int max_results;
|
||||
int page;
|
||||
sort_e sort;
|
||||
|
|
@ -51,21 +51,21 @@ namespace gdpm::rest_api{
|
|||
context make_from_config(const config::context& config);
|
||||
context make_context(type_e type = GDPM_DEFAULT_ASSET_TYPE, int category = GDPM_DEFAULT_ASSET_CATEGORY, support_e support = GDPM_DEFAULT_ASSET_SUPPORT, const std::string& filter = GDPM_DEFAULT_ASSET_FILTER, const std::string& user = GDPM_DEFAULT_ASSET_USER, const std::string& godot_version = GDPM_DEFAULT_ASSET_GODOT_VERSION, int max_results = GDPM_DEFAULT_ASSET_MAX_RESULTS, int page = GDPM_DEFAULT_ASSET_PAGE, sort_e sort = GDPM_DEFAULT_ASSET_SORT, bool reverse = GDPM_DEFAULT_ASSET_REVERSE, int verbose = GDPM_DEFAULT_ASSET_VERBOSE);
|
||||
|
||||
std::string to_string(type_e type);
|
||||
std::string to_string(support_e support);
|
||||
std::string to_string(sort_e sort);
|
||||
string to_string(type_e type);
|
||||
string to_string(support_e support);
|
||||
string to_string(sort_e sort);
|
||||
void _print_params(const context& params);
|
||||
rapidjson::Document _parse_json(const std::string& r, int verbose = 0);
|
||||
std::string _prepare_request(const std::string& url, const context& context);
|
||||
rapidjson::Document _parse_json(const string& r, int verbose = 0);
|
||||
string _prepare_request(const string& url, const context& context);
|
||||
|
||||
bool register_account(const std::string& username, const std::string& password, const std::string& email);
|
||||
bool login(const std::string& username, const std::string& password);
|
||||
bool register_account(const string& username, const string& password, const string& email);
|
||||
bool login(const string& username, const string& password);
|
||||
bool logout();
|
||||
|
||||
rapidjson::Document configure(const std::string& url = constants::HostUrl, type_e type = any, int verbose = 0);
|
||||
rapidjson::Document get_assets_list(const std::string& url = constants::HostUrl, type_e type = GDPM_DEFAULT_ASSET_TYPE, int category = GDPM_DEFAULT_ASSET_CATEGORY, support_e support = GDPM_DEFAULT_ASSET_SUPPORT, const std::string& filter = GDPM_DEFAULT_ASSET_FILTER, const std::string& user = GDPM_DEFAULT_ASSET_USER, const std::string& godot_version = GDPM_DEFAULT_ASSET_GODOT_VERSION, int max_results = GDPM_DEFAULT_ASSET_MAX_RESULTS, int page = GDPM_DEFAULT_ASSET_PAGE, sort_e sort = GDPM_DEFAULT_ASSET_SORT, bool reverse = GDPM_DEFAULT_ASSET_REVERSE, int verbose = GDPM_DEFAULT_ASSET_VERBOSE);
|
||||
rapidjson::Document get_assets_list(const std::string& url, const context& params = {});
|
||||
rapidjson::Document get_asset(const std::string& url, int asset_id, const context& params = {});
|
||||
rapidjson::Document configure(const string& url = constants::HostUrl, type_e type = any, int verbose = 0);
|
||||
rapidjson::Document get_assets_list(const string& url = constants::HostUrl, type_e type = GDPM_DEFAULT_ASSET_TYPE, int category = GDPM_DEFAULT_ASSET_CATEGORY, support_e support = GDPM_DEFAULT_ASSET_SUPPORT, const string& filter = GDPM_DEFAULT_ASSET_FILTER, const std::string& user = GDPM_DEFAULT_ASSET_USER, const std::string& godot_version = GDPM_DEFAULT_ASSET_GODOT_VERSION, int max_results = GDPM_DEFAULT_ASSET_MAX_RESULTS, int page = GDPM_DEFAULT_ASSET_PAGE, sort_e sort = GDPM_DEFAULT_ASSET_SORT, bool reverse = GDPM_DEFAULT_ASSET_REVERSE, int verbose = GDPM_DEFAULT_ASSET_VERBOSE);
|
||||
rapidjson::Document get_assets_list(const string& url, const context& params = {});
|
||||
rapidjson::Document get_asset(const string& url, int asset_id, const context& params = {});
|
||||
bool delete_asset(int asset_id); // ...for moderators
|
||||
bool undelete_asset(int asset_id); // ...for moderators
|
||||
bool set_support_level(int asset_id); // ...for moderators
|
||||
|
|
@ -81,11 +81,11 @@ namespace gdpm::rest_api{
|
|||
void get_asset_edit(int asset_id);
|
||||
|
||||
/* POST /asset/edit/{id}/review */
|
||||
std::string review_asset_edit(int asset_id);
|
||||
string review_asset_edit(int asset_id);
|
||||
|
||||
/* POST /asset/edit/{id}/accept */
|
||||
std::string accept_asset_edit(int asset_id); // ...for moderators
|
||||
string accept_asset_edit(int asset_id); // ...for moderators
|
||||
|
||||
/* POST /asset/edit/{id}/reject */
|
||||
std::string reject_asset_edit(int asset_id);
|
||||
string reject_asset_edit(int asset_id);
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@
|
|||
#include <type_traits>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
#include <future>
|
||||
|
||||
namespace gdpm{
|
||||
class error;
|
||||
|
|
@ -29,6 +30,16 @@ namespace gdpm{
|
|||
non_movable(non_movable&&) = delete;
|
||||
};
|
||||
|
||||
enum variant_type_index : int{
|
||||
INT = 0,
|
||||
FLOAT = 1,
|
||||
BOOL = 2,
|
||||
STRING = 3,
|
||||
STRING_LIST = 4,
|
||||
STRING_MAP = 5,
|
||||
SIZE_T = 6,
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
concept error_t = requires{ std::is_same<error, T>::value; };
|
||||
|
||||
|
|
@ -36,12 +47,58 @@ namespace gdpm{
|
|||
using string_list = std::vector<string>;
|
||||
using string_map = std::unordered_map<string, string>;
|
||||
using string_pair = std::pair<string, string>;
|
||||
using var = std::variant<int, bool, float, std::string>;
|
||||
using var = std::variant<int, float, bool, string, string_list, string_map, size_t>;
|
||||
template <typename T = var>
|
||||
using _args_t = std::vector<T>;
|
||||
using args_t = _args_t<string>;
|
||||
template <typename Key = std::string, class Value = _args_t<var>>
|
||||
using var_args = _args_t<var>;
|
||||
using var_list = std::vector<var>;
|
||||
using var_map = std::unordered_map<string, var>;
|
||||
template <typename Key = string, class Value = _args_t<var>>
|
||||
using _opts_t = std::unordered_map<Key, Value>;
|
||||
using opts_t = _opts_t<string, string_list>;
|
||||
using opt = std::pair<string, string_list>;
|
||||
using var_opt = std::pair<string, var>;
|
||||
using var_opts = _opts_t<string, var>;
|
||||
template <typename T = error>
|
||||
using _task_list = std::vector<std::future<T>>;
|
||||
using task_list = _task_list<error>;
|
||||
|
||||
inline string_list unwrap(const var_args& args){
|
||||
string_list sl;
|
||||
std::for_each(args.begin(), args.end(), [&sl](const var& v){
|
||||
if(v.index() == STRING){
|
||||
sl.emplace_back(std::get<string>(v));
|
||||
}
|
||||
});
|
||||
return sl;
|
||||
}
|
||||
|
||||
inline opts_t unwrap(const var_opts& opts){
|
||||
opts_t o;
|
||||
std::for_each(opts.begin(), opts.end(), [&o](const var_opt& opt){
|
||||
if(opt.second.index() == STRING){
|
||||
string_list sl;
|
||||
string arg(std::get<string>(opt.second)); // must make copy for const&
|
||||
sl.emplace_back(arg);
|
||||
o.insert(std::pair(opt.first, sl));
|
||||
}
|
||||
});
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
constexpr void get(const var& v, T& target){
|
||||
switch(v.index()){
|
||||
case INT: /*return*/ target = std::get<int>(v);
|
||||
case FLOAT: /*return*/ target = std::get<float>(v);
|
||||
case BOOL: /*return*/ target = std::get<bool>(v);
|
||||
case STRING: /*return*/ target = std::get<string>(v);
|
||||
case STRING_LIST: /*return*/ target = std::get<string_list>(v);
|
||||
case STRING_MAP: /*return*/ target = std::get<string_map>(v);
|
||||
case SIZE_T: /*return*/ target = std::get<size_t>(v);
|
||||
default: /*return*/ target = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue