winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

RestClient.h (2642B)


      1 // Copyright (c) Microsoft Corporation.
      2 // Licensed under the MIT License.
      3 #pragma once
      4 #include <set>
      5 #include "Rest/Schema/IRestClient.h"
      6 #include "ISource.h"
      7 #include <winget/HttpClientHelper.h>
      8 
      9 namespace AppInstaller::Repository::Rest
     10 {
     11     struct RestClient
     12     {
     13         RestClient(const RestClient&) = delete;
     14         RestClient& operator=(const RestClient&) = delete;
     15 
     16         RestClient(RestClient&&) = default;
     17         RestClient& operator=(RestClient&&) = default;
     18 
     19         // Performs a search based on the given criteria.
     20         Schema::IRestClient::SearchResult Search(const SearchRequest& request) const;
     21 
     22         std::optional<Manifest::Manifest> GetManifestByVersion(const std::string& packageId, const std::string& version, const std::string& channel) const;
     23 
     24         std::string GetSourceIdentifier() const;
     25 
     26         Schema::IRestClient::Information GetSourceInformation() const;
     27 
     28         static std::optional<AppInstaller::Utility::Version> GetLatestCommonVersion(const std::vector<std::string>& serverSupportedVersions, const std::set<AppInstaller::Utility::Version>& wingetSupportedVersions);
     29 
     30         // Responsible for getting the source information contracts with minimal validation. Does not try to create a rest interface out of it.
     31         static Schema::IRestClient::Information GetInformation(const std::string& restApi, const std::optional<std::string>& customHeader, std::string_view caller, const Http::HttpClientHelper& helper);
     32 
     33         static std::unique_ptr<Schema::IRestClient> GetSupportedInterface(
     34             const std::string& restApi,
     35             const Http::HttpClientHelper::HttpRequestHeaders& additionalHeaders,
     36             const Schema::IRestClient::Information& information,
     37             const Authentication::AuthenticationArguments& authArgs,
     38             const AppInstaller::Utility::Version& version,
     39             const Http::HttpClientHelper& helper);
     40 
     41         // Creates the rest client. Full validation performed (just as opening the source)
     42         static RestClient Create(
     43             const std::string& restApi,
     44             const std::optional<std::string>& customHeader,
     45             std::string_view caller,
     46             const Http::HttpClientHelper& helper,
     47             const Schema::IRestClient::Information& information,
     48             const Authentication::AuthenticationArguments& authArgs = {});
     49     private:
     50         RestClient(std::unique_ptr<Schema::IRestClient> supportedInterface, std::string sourceIdentifier);
     51 
     52         std::unique_ptr<Schema::IRestClient> m_interface;
     53         std::string m_sourceIdentifier;
     54     };
     55 }