You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
4.0 KiB
106 lines
4.0 KiB
// Copyright (C) 2024 Simon Quigley <tsimonq2@ubuntu.com>
|
|
//
|
|
// 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/>.
|
|
|
|
#ifndef LAUNCHPAD_H
|
|
#define LAUNCHPAD_H
|
|
|
|
#include <string>
|
|
#include <map>
|
|
#include <optional>
|
|
#include <memory> // Include memory for shared_ptr
|
|
#include <nlohmann/json.hpp>
|
|
#include "callablewrapper.h"
|
|
|
|
// Forward declarations
|
|
class distribution;
|
|
class person;
|
|
class archive;
|
|
class source_package_publishing_history;
|
|
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<launchpad> { // 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<std::shared_ptr<launchpad>> login();
|
|
|
|
bool is_authenticated() const;
|
|
|
|
// Callable Wrappers
|
|
CallableWrapper<distribution> distributions;
|
|
CallableWrapper<person> people;
|
|
|
|
// API Methods
|
|
std::optional<archive> get_archive(const std::string& distribution_name);
|
|
|
|
std::optional<std::string> api_get(const std::string& endpoint, const std::map<std::string, std::string>& params = {}) const;
|
|
std::optional<std::string> api_post(const std::string& endpoint,
|
|
const std::map<std::string, std::string>& params,
|
|
bool build_endpoint = true,
|
|
const std::string& token_secret_override = "");
|
|
std::optional<std::string> api_patch(const std::string& endpoint, const nlohmann::json& data);
|
|
std::optional<std::string> 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<std::string> static_http_post(const std::string& url,
|
|
const std::map<std::string,std::string>& params);
|
|
static std::string url_encode(const std::string& value);
|
|
std::optional<distribution> get_distribution(const std::string& name_);
|
|
std::optional<person> 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_package_publishing_history; // so source can call api_*
|
|
friend class build; // so build can call api_*
|
|
};
|
|
|
|
#endif // LAUNCHPAD_H
|