178 lines
4.7 KiB
C++
178 lines
4.7 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 "account_mastodon.hpp"
|
|
#include "config.hpp"
|
|
#include "version.hpp"
|
|
|
|
#include <optional>
|
|
#include <string>
|
|
#include <string_view>
|
|
|
|
namespace FediPotato
|
|
{
|
|
|
|
using std::string;
|
|
using std::string_view;
|
|
|
|
/*!
|
|
* @brief High-level interface to fediverse accounts and their data.
|
|
*
|
|
* For possible exceptions see Directories, Config and MastodonAPI.
|
|
*
|
|
* @since 0.1.0
|
|
*
|
|
* @headerfile fedipotato.hpp FediPotato/fedipotato.hpp
|
|
*/
|
|
class FediPotato
|
|
{
|
|
public:
|
|
/*!
|
|
* @brief Construct a FediPotato object.
|
|
*
|
|
* @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"}
|
|
{
|
|
MastodonAPI test{account_mastodon("test")};
|
|
test.start_stream(MastodonAPI::stream_type::home_tl, std::nullopt);
|
|
test.stop_stream(MastodonAPI::stream_type::home_tl, std::nullopt);
|
|
}
|
|
|
|
//! 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);
|
|
}
|
|
|
|
/*!
|
|
* @brief Connect to an account using the Mastodon API.
|
|
*
|
|
* @param account_name Identifier for the account.
|
|
*
|
|
* @since 0.1.0
|
|
*/
|
|
[[nodiscard]]
|
|
MastodonAPI account_mastodon(const string_view account_name) const
|
|
{
|
|
return MastodonAPI(_application_name, account_name, _config);
|
|
}
|
|
|
|
private:
|
|
const string _application_name;
|
|
Config _config;
|
|
};
|
|
|
|
} // namespace FediPotato
|
|
|
|
#endif // FEDIPOTATO_HPP
|
|
|
|
/*!
|
|
* @mainpage FediPotato Reference
|
|
*
|
|
* @section using Using the library
|
|
*
|
|
* Include fedipotato.hpp, which then includes all other headers.
|
|
*
|
|
* @code
|
|
* #include <FediPotato/fedipotato.hpp>
|
|
* @endcode
|
|
*
|
|
* Use it in your CMake project like this:
|
|
*
|
|
* @code
|
|
* find_package(FediPotato REQUIRED CONFIG)
|
|
* target_link_libraries(MyProject PRIVATE FediPotato::FediPotato)
|
|
* @endcode
|
|
*
|
|
* Or compile your code with `g++ $(pkg-config --cflags --libs FediPotato)`.
|
|
*
|
|
* Since we use C++17 features in the headers of this library, your program
|
|
* needs to be compiled as C++17 or higher too.
|
|
*
|
|
* @subsection example Example
|
|
*
|
|
* @code
|
|
* #include <FediPotato/fedipotato.hpp>
|
|
*
|
|
* int main()
|
|
* {
|
|
* }
|
|
* @endcode
|
|
*
|
|
* @section exceptions Exceptions
|
|
*
|
|
* We throw exceptions. Consult the class descriptions for more information.
|
|
*
|
|
* @section thread_safety Thread safety
|
|
*
|
|
* The first time you construct a MastodonAPI, [curl_global_init(3)]
|
|
* (https://curl.haxx.se/libcurl/c/curl_global_init.html) is called. When the
|
|
* last MastodonAPI is destroyed, [curl_global_cleanup(3)]
|
|
* (https://curl.haxx.se/libcurl/c/curl_global_cleanup.html) is called. Both
|
|
* are not thread safe.
|
|
*
|
|
* If you are using libcurl with OpenSSL before 1.1.0, please read
|
|
* [libcurl-thread(3)](https://curl.haxx.se/libcurl/c/threadsafe.html).
|
|
*/
|