From e547684f45a11a1e5b8593b58b5ba9d112cca72c Mon Sep 17 00:00:00 2001 From: Simon Quigley Date: Sun, 15 Dec 2024 02:51:08 -0600 Subject: [PATCH] Remove many getter functions --- src/archive.cpp | 224 ------------------------------------------- src/archive.h | 50 +--------- src/distribution.cpp | 12 --- src/distribution.h | 5 - src/person.cpp | 18 +--- src/person.h | 6 -- 6 files changed, 4 insertions(+), 311 deletions(-) diff --git a/src/archive.cpp b/src/archive.cpp index c8f0222..9fb71b6 100644 --- a/src/archive.cpp +++ b/src/archive.cpp @@ -127,234 +127,10 @@ void archive::parse_json(const std::string& json_data) { } } -std::optional archive::getAuthorizedSize() const { - return authorized_size; -} - -std::optional archive::getBuildDebugSymbols() const { - return build_debug_symbols; -} - -std::optional archive::getDescription() const { - return description.empty()?std::nullopt:std::optional(description); -} - -std::optional archive::getDisplayName() const { - return displayname.empty()?std::nullopt:std::optional(displayname); -} - -std::optional archive::getDistributionLink() const { - return distribution_link.empty()?std::nullopt:std::optional(distribution_link); -} - -std::optional archive::getExternalDependencies() const { - return external_dependencies.empty()?std::nullopt:std::optional(external_dependencies); -} - -std::optional archive::getMetadataOverrides() const { - return metadata_overrides.empty()?std::nullopt:std::optional(metadata_overrides); -} - -std::optional archive::getName() const { - return name.empty()?std::nullopt:std::optional(name); -} - -std::optional archive::getOwnerLink() const { - return owner_link.empty()?std::nullopt:std::optional(owner_link); -} - -std::optional archive::getPermitObsoleteSeriesUploads() const { - return permit_obsolete_series_uploads; -} - -std::optional archive::getPrivate() const { - return is_private; -} - -std::optional archive::getPublish() const { - return publish; -} - -std::optional archive::getPublishDebugSymbols() const { - return publish_debug_symbols; -} - -std::optional archive::getPublishingMethod() const { - return publishing_method.empty()?std::nullopt:std::optional(publishing_method); -} - -std::optional archive::getRelativeBuildScore() const { - return relative_build_score; -} - -std::optional archive::getRepositoryFormat() const { - return repository_format.empty()?std::nullopt:std::optional(repository_format); -} - -std::optional archive::getRequireVirtualized() const { - return require_virtualized; -} - -std::optional archive::getSigningKeyFingerprint() const { - return signing_key_fingerprint.empty()?std::nullopt:std::optional(signing_key_fingerprint); -} - -std::optional archive::getSuppressSubscriptionNotifications() const { - return suppress_subscription_notifications; -} - -std::optional archive::getArchiveInfo() const { - return std::nullopt; -} - -bool archive::setAuthorizedSize(int size) { - nlohmann::json update; - update["authorized_size"] = size; - return patchArchive(update); -} - -bool archive::setBuildDebugSymbols(bool build) { - nlohmann::json update; - update["build_debug_symbols"] = build; - return patchArchive(update); -} - -bool archive::setDescription(const std::string& desc) { - nlohmann::json update; - update["description"] = desc; - return patchArchive(update); -} - -bool archive::setDisplayName(const std::string& name_) { - nlohmann::json update; - update["displayname"] = name_; - return patchArchive(update); -} - -bool archive::setDistributionLink(const std::string& link) { - nlohmann::json update; - update["distribution_link"] = link; - return patchArchive(update); -} - -bool archive::setExternalDependencies(const std::string& deps) { - nlohmann::json update; - update["external_dependencies"] = deps; - return patchArchive(update); -} - -bool archive::setMetadataOverrides(const nlohmann::json& overrides) { - nlohmann::json update; - update["metadata_overrides"] = overrides; - return patchArchive(update); -} - -bool archive::setName(const std::string& name_) { - nlohmann::json update; - update["name"] = name_; - return patchArchive(update); -} - -bool archive::setOwnerLink(const std::string& link) { - nlohmann::json update; - update["owner_link"] = link; - return patchArchive(update); -} - -bool archive::setPermitObsoleteSeriesUploads(bool permit) { - nlohmann::json update; - update["permit_obsolete_series_uploads"] = permit; - return patchArchive(update); -} - -bool archive::setPrivate(bool is_private_) { - nlohmann::json update; - update["private"] = is_private_; - return patchArchive(update); -} - -bool archive::setPublish(bool publish_) { - nlohmann::json update; - update["publish"] = publish_; - return patchArchive(update); -} - -bool archive::setPublishDebugSymbols(bool publish_debug_) { - nlohmann::json update; - update["publish_debug_symbols"] = publish_debug_; - return patchArchive(update); -} - -bool archive::setPublishingMethod(const std::string& method) { - nlohmann::json update; - update["publishing_method"] = method; - return patchArchive(update); -} - -bool archive::setRelativeBuildScore(int score) { - nlohmann::json update; - update["relative_build_score"] = score; - return patchArchive(update); -} - -bool archive::setRepositoryFormat(const std::string& format) { - nlohmann::json update; - update["repository_format"] = format; - return patchArchive(update); -} - -bool archive::setRequireVirtualized(bool require_) { - nlohmann::json update; - update["require_virtualized"] = require_; - return patchArchive(update); -} - -bool archive::setSigningKeyFingerprint(const std::string& fingerprint) { - nlohmann::json update; - update["signing_key_fingerprint"] = fingerprint; - return patchArchive(update); -} - -bool archive::setSuppressSubscriptionNotifications(bool suppress) { - nlohmann::json update; - update["suppress_subscription_notifications"] = suppress; - return patchArchive(update); -} - std::string archive::build_archive_endpoint() const { return "~" + url_encode(owner_name) + "/" + url_encode(ppa_name); } -bool archive::patchArchive(const nlohmann::json& update_fields) { - if (!lp) { - std::cerr << "LP not set in archive::patchArchive.\n"; - return false; - } - std::string endpoint = build_archive_endpoint(); - auto response = lp->api_patch(endpoint, update_fields); - return response.has_value(); -} - -bool archive::putArchive(const nlohmann::json& new_representation) { - if (!lp) { - std::cerr << "LP not set in archive::putArchive.\n"; - return false; - } - std::string endpoint = build_archive_endpoint(); - auto response = lp->api_patch(endpoint, new_representation); - return response.has_value(); -} - -bool archive::deleteArchive() { - if (!lp) { - std::cerr << "LP not set in archive::deleteArchive.\n"; - return false; - } - std::string endpoint = build_archive_endpoint(); - auto response = lp->api_delete(endpoint); - return response.has_value(); -} - std::generator archive::getPublishedSources(const std::string& status) const { std::map params; params["ws.op"] = "getPublishedSources"; diff --git a/src/archive.h b/src/archive.h index 939afca..2388e88 100644 --- a/src/archive.h +++ b/src/archive.h @@ -40,53 +40,6 @@ public: static std::optional parse(const std::string& json_data); void parse_json(const std::string& json_data); - - std::optional getAuthorizedSize() const; - std::optional getBuildDebugSymbols() const; - std::optional getDescription() const; - std::optional getDisplayName() const; - std::optional getDistributionLink() const; - std::optional getExternalDependencies() const; - std::optional getMetadataOverrides() const; - std::optional getName() const; - std::optional getOwnerLink() const; - std::optional getPermitObsoleteSeriesUploads() const; - std::optional getPrivate() const; - std::optional getPublish() const; - std::optional getPublishDebugSymbols() const; - std::optional getPublishingMethod() const; - std::optional getRelativeBuildScore() const; - std::optional getRepositoryFormat() const; - std::optional getRequireVirtualized() const; - std::optional getSigningKeyFingerprint() const; - std::optional getSuppressSubscriptionNotifications() const; - std::optional getArchiveInfo() const; - std::generator getPublishedSources(const std::string& status) const; - - bool setAuthorizedSize(int size); - bool setBuildDebugSymbols(bool build); - bool setDescription(const std::string& desc); - bool setDisplayName(const std::string& name_); - bool setDistributionLink(const std::string& link); - bool setExternalDependencies(const std::string& deps); - bool setMetadataOverrides(const nlohmann::json& overrides); - bool setName(const std::string& name_); - bool setOwnerLink(const std::string& link); - bool setPermitObsoleteSeriesUploads(bool permit); - bool setPrivate(bool is_private_); - bool setPublish(bool publish_); - bool setPublishDebugSymbols(bool publish_debug_); - bool setPublishingMethod(const std::string& method); - bool setRelativeBuildScore(int score); - bool setRepositoryFormat(const std::string& format); - bool setRequireVirtualized(bool require_); - bool setSigningKeyFingerprint(const std::string& fingerprint); - bool setSuppressSubscriptionNotifications(bool suppress); - - bool patchArchive(const nlohmann::json& update_fields); - bool putArchive(const nlohmann::json& new_representation); - bool deleteArchive(); - void set_lp(launchpad* lp_ptr); // New public member variables @@ -123,6 +76,9 @@ public: std::string status; std::string web_link; + // Public functions + std::generator getPublishedSources(const std::string& status) const; + launchpad* lp; private: diff --git a/src/distribution.cpp b/src/distribution.cpp index 342ecd2..83efc4f 100644 --- a/src/distribution.cpp +++ b/src/distribution.cpp @@ -64,18 +64,6 @@ void distribution::parse_json(const std::string& json_data) { } } -std::optional distribution::getName() const { - return name.empty() ? std::nullopt : std::optional(name); -} - -std::optional distribution::getDescription() const { - return description.empty() ? std::nullopt : std::optional(description); -} - -std::optional distribution::getDisplayName() const { - return displayname.empty() ? std::nullopt : std::optional(displayname); -} - void distribution::set_lp(launchpad* lp_ptr) { lp = lp_ptr; } diff --git a/src/distribution.h b/src/distribution.h index 18c9946..9272564 100644 --- a/src/distribution.h +++ b/src/distribution.h @@ -38,11 +38,6 @@ public: // Static method to parse JSON data static std::optional parse(const std::string& json_data); - // Getter methods for optional fields - std::optional getName() const; - std::optional getDescription() const; - std::optional getDisplayName() const; - // Public member variables std::string name; std::string description; diff --git a/src/person.cpp b/src/person.cpp index 062db1c..03d94ef 100644 --- a/src/person.cpp +++ b/src/person.cpp @@ -67,24 +67,8 @@ void person::parse_json(const std::string& json_data) { } } -std::optional person::getName() const { - return name.empty() ? std::nullopt : std::optional(name); -} - -std::optional person::getRealName() const { - return realname.empty() ? std::nullopt : std::optional(realname); -} - -std::optional person::getWebLink() const { - return web_link.empty() ? std::nullopt : std::optional(web_link); -} - -std::optional person::getEmail() const { - return email.empty() ? std::nullopt : std::optional(email); -} - std::optional person::getPPAByName(distribution& distro, const std::string& name) { - std::string owner = getName().value(); + std::string owner = name; std::string endpoint = "~" + lp->url_encode(owner); std::map params = { {"distribution", distro.self_link}, diff --git a/src/person.h b/src/person.h index efe31f7..7fa84a9 100644 --- a/src/person.h +++ b/src/person.h @@ -40,12 +40,6 @@ public: // Static parse method static std::optional parse(const std::string& json_data); - // Getter methods for optional fields - std::optional getName() const; - std::optional getRealName() const; - std::optional getWebLink() const; - std::optional getEmail() const; - // Get a PPA by name std::optional getPPAByName(distribution& distribution, const std::string& name);