This repository has been archived on 2020-04-18. You can view files and clone it, but cannot push or open issues or pull requests.
FediPotato/lib/include/fedipotato.hpp

115 lines
3.0 KiB
C++

/* This file is part of FediPotato.
* Copyright © 2020 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FEDIPOTATO_HPP
#define FEDIPOTATO_HPP
#include "config.hpp"
#include "version.hpp"
#include <string>
#include <string_view>
namespace FediPotato
{
using std::string;
using std::string_view;
/*!
* @brief High-level interface to fediverse accounts and their data.
*
* @since 0.1.0
*
* @headerfile fedipotato.hpp FediPotato/fedipotato.hpp
*/
class FediPotato
{
public:
/*!
* @brief Construct a FediPotato object.
*
* These exception could occur:
* * `std::runtime_error` (Directory not found)
* * `std::filesystem::filesystem_error` (Could not create directory)
* * `std::ifstream::failure` (Could not read from file)
* * `nlohmann::detail::parse_error` (Could not parse file)
*
* @param application_name The name of your application. Influences the
* file paths for all the data that is stored.
*
* @since 0.1.0
*/
explicit FediPotato(const string_view application_name)
: _application_name{application_name}
, _config{application_name, "general.json"}
{
}
//! Copy constructor
FediPotato(const FediPotato &other) = default;
//! Move constructor
FediPotato(FediPotato &&other) noexcept = default;
//! Destructor
virtual ~FediPotato() noexcept = default;
//! Copy assignment operator
FediPotato& operator=(const FediPotato &other) = delete;
//! Move assignment operator
FediPotato& operator=(FediPotato &&other) noexcept = delete;
public:
/*!
* @brief Return the version of the library.
*
* @since 0.1.0
*/
inline static constexpr string_view get_version()
{
return version;
}
/*!
* @brief Set the proxy server.
*
* Example:
* @code
* FediPotato account("example");
* account.set_proxy("socks4a://user:password@localhost:9050");
* @endcode
*
* @param proxy curl-compatible proxy string. See [CURLOPT_PROXY(3)]
* (https://curl.haxx.se/libcurl/c/CURLOPT_PROXY.html).
*
* @since 0.1.0
*/
void set_proxy(const string_view proxy)
{
_config.set("proxy", proxy);
}
private:
const string _application_name;
Config _config;
};
} // namespace FediPotato
#endif // FEDIPOTATO_HPP