Interface.h (2499B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 #pragma once 4 #include "Rest/Schema/IRestClient.h" 5 #include <winget/HttpClientHelper.h> 6 7 namespace AppInstaller::Repository::Rest::Schema::V1_0 8 { 9 // Interface to this schema version exposed through IRestClient. 10 struct Interface : public IRestClient 11 { 12 Interface(const std::string& restApi, const Http::HttpClientHelper& helper); 13 14 Interface(const Interface&) = delete; 15 Interface& operator=(const Interface&) = delete; 16 17 Interface(Interface&&) = default; 18 Interface& operator=(Interface&&) = default; 19 20 Utility::Version GetVersion() const override; 21 IRestClient::Information GetSourceInformation() const override; 22 IRestClient::SearchResult Search(const SearchRequest& request) const override; 23 std::optional<Manifest::Manifest> GetManifestByVersion(const std::string& packageId, const std::string& version, const std::string& channel) const override; 24 std::vector<Manifest::Manifest> GetManifests(const std::string& packageId, const std::map<std::string_view, std::string>& params = {}) const override; 25 26 protected: 27 bool MeetsOptimizedSearchCriteria(const SearchRequest& request) const; 28 IRestClient::SearchResult OptimizedSearch(const SearchRequest& request) const; 29 IRestClient::SearchResult SearchInternal(const SearchRequest& request) const; 30 31 // Check query params against source information and update if necessary. 32 virtual std::map<std::string_view, std::string> GetValidatedQueryParams(const std::map<std::string_view, std::string>& params) const; 33 34 // Check search request against source information and get json search body. 35 virtual web::json::value GetValidatedSearchBody(const SearchRequest& searchRequest) const; 36 37 virtual SearchResult GetSearchResult(const web::json::value& searchResponseObject) const; 38 virtual std::vector<Manifest::Manifest> GetParsedManifests(const web::json::value& manifestsResponseObject) const; 39 40 // Gets auth headers if source requires authentication for access. 41 virtual Http::HttpClientHelper::HttpRequestHeaders GetAuthHeaders() const; 42 43 Http::HttpClientHelper::HttpRequestHeaders m_requiredRestApiHeaders; 44 45 private: 46 std::string m_restApiUri; 47 utility::string_t m_searchEndpoint; 48 Http::HttpClientHelper m_httpClientHelper; 49 }; 50 }