// Copyright (C) 2024 Simon Quigley // // 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 . #ifndef LAUNCHPAD_H #define LAUNCHPAD_H #include #include #include #include // Include memory for shared_ptr #include #include "callablewrapper.h" // Forward declarations class distribution; class person; class archive; class source; class build; #ifndef LAUNCHPAD_API #ifdef BUILDING_LAUNCHPAD #define LAUNCHPAD_API __attribute__((visibility("default"))) #else #define LAUNCHPAD_API #endif #endif class LAUNCHPAD_API launchpad : public std::enable_shared_from_this { // Inherit from enable_shared_from_this public: launchpad(); launchpad(const std::string& consumer_key_, const std::string& consumer_secret_, const std::string& oauth_token_, const std::string& oauth_token_secret_, const std::string& service_root_, const std::string& api_version_); // Delete copy constructor and copy assignment to prevent copying launchpad(const launchpad&) = delete; launchpad& operator=(const launchpad&) = delete; // Allow move constructor and move assignment launchpad(launchpad&&) noexcept = default; launchpad& operator=(launchpad&&) noexcept = default; virtual ~launchpad(); static std::optional> login(); bool is_authenticated() const; // Callable Wrappers CallableWrapper distributions; CallableWrapper people; // API Methods std::optional get_archive(const std::string& distribution_name); std::optional api_get(const std::string& endpoint, const std::map& params = {}) const; std::optional api_post(const std::string& endpoint, const std::map& params, bool build_endpoint = true, const std::string& token_secret_override = ""); std::optional api_patch(const std::string& endpoint, const nlohmann::json& data); std::optional api_delete(const std::string& endpoint); std::string build_full_url(const std::string& endpoint) const; protected: std::string consumer_key; std::string consumer_secret; std::string oauth_token; std::string oauth_token_secret; std::string service_root; std::string api_version; bool authenticated; private: static std::optional static_http_post(const std::string& url, const std::map& params); static std::string url_encode(const std::string& value); std::optional get_distribution(const std::string& name_); std::optional get_person(const std::string& name_); friend class person; // so person can call api_* friend class distribution; // so distribution can call api_* friend class archive; // so archive can call api_* friend class source; // so source can call api_* friend class build; // so build can call api_* }; #endif // LAUNCHPAD_H