#pragma once /* * Copyright (C) 2024 Dominik Meyer * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "Redmine/IssueStatus.hpp" #include "nlohmann/json_fwd.hpp" #include #include #include #include #include #include #include #include /** * @brief The main namespace of this library for Redmine related datatypes, classes, and functions * */ namespace Redmine { /** * @brief Client side implementation of the redmine API * * This implementation of the redmine API always uses the json rest api. * */ class API { private: /// the URL to the redmine server api std::string redmineApiURL_; /// the token to authenticate against the server in redmine called API Key std::string authToken_; /// cache for all issue stati std::vector issueStatusList_; nlohmann::json get(const std::string &path) const; void put(const std::string &path, const nlohmann::json &data) const; void post(const std::string &path, const nlohmann::json &data) const; void processGenericErrors_(httplib::Result &res) const; /** * @brief upload a file to the redmine server * * @param file - the file to upload * @param filename - the filename used inside redmine * @return std::string - the redmine internal token (reference) for the uploaded file */ std::string upload_(const std::filesystem::path &file, const std::string &filename) const; public: /** * @name Constructors */ /*@{*/ /** * @brief Only Constructor of the Readmine::API * * Only this constructor exists to ensure url and token are available * * @param serverURL - full server URL (e.g. https://redmine.de) * @param authToken - authToken taken from the redmine instance to access the API */ API(const std::string &serverURL, const std::string &authToken); /*@}*/ /** * @name General Methods independent of API */ /*@{*/ /** * @brief verify that the API is accessible with the provided URL and authToken * * @return true - everything is fine and API is accessible * @return false - something went wrong */ bool ready() const; /*@}*/ /** * @name MyAccount-API */ /*@{*/ /** * @brief Return the user information of the owner of the used auth token * * @return Redmine::User */ Redmine::User getMyAccount() const; /** * @brief Set the user information of the owner of the used auth token * * @param user - the used to set with all required information set */ void setMyAccount(const Redmine::User &user) const; /** * @brief Return a list of all available issue stati * */ std::vector getIssueStatusList(); /** * @brief Return a list of all available projects for the logged in user * * @return std::vector */ std::vector getProjects() const; void uploadFileToProject(const std::uint64_t projectId, const std::string &filePath, const std::string &fileName, const std::string &description, const std::uint32_t version) const; /*@}*/ }; }