107 lines
3.1 KiB
C++
107 lines
3.1 KiB
C++
|
#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 <https://www.gnu.org/licenses/>.
|
||
|
*/
|
||
|
|
||
|
#include "nlohmann/json_fwd.hpp"
|
||
|
#include <httplib.h>
|
||
|
#include <memory>
|
||
|
#include <string>
|
||
|
#include <nlohmann/json.hpp>
|
||
|
#include <Redmine/User.hpp>
|
||
|
|
||
|
/**
|
||
|
* @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_;
|
||
|
|
||
|
|
||
|
nlohmann::json get(const std::string &path) const;
|
||
|
void put(const std::string &path, const nlohmann::json &data) const;
|
||
|
|
||
|
public:
|
||
|
|
||
|
/**
|
||
|
* @name Constructors
|
||
|
*/
|
||
|
/*@{*/
|
||
|
/**
|
||
|
* @brief Only Constructor of the Readmine::API t
|
||
|
*
|
||
|
* 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;
|
||
|
|
||
|
|
||
|
/*@}*/
|
||
|
};
|
||
|
|
||
|
|
||
|
}
|