olp-cpp-sdk  1.22.0
CatalogRequest.h
1 /*
2  * Copyright (C) 2019-2020 HERE Europe B.V.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * SPDX-License-Identifier: Apache-2.0
17  * License-Filename: LICENSE
18  */
19 
20 #pragma once
21 
22 #include <sstream>
23 #include <string>
24 #include <utility>
25 
26 #include <olp/dataservice/read/DataServiceReadApi.h>
27 #include <olp/dataservice/read/FetchOptions.h>
28 #include <boost/optional.hpp>
29 
30 namespace olp {
31 namespace dataservice {
32 namespace read {
33 
37 class DATASERVICE_READ_API CatalogRequest final {
38  public:
49  inline const boost::optional<std::string>& GetBillingTag() const {
50  return billing_tag_;
51  }
52 
62  inline CatalogRequest& WithBillingTag(boost::optional<std::string> tag) {
63  billing_tag_ = std::move(tag);
64  return *this;
65  }
66 
77  inline CatalogRequest& WithBillingTag(std::string&& tag) {
78  billing_tag_ = std::move(tag);
79  return *this;
80  }
81 
90  inline FetchOptions GetFetchOption() const { return fetch_option_; }
91 
102  inline CatalogRequest& WithFetchOption(FetchOptions fetch_option) {
103  fetch_option_ = fetch_option;
104  return *this;
105  }
106 
112  inline std::string CreateKey() const {
113  std::stringstream out;
114  if (GetBillingTag()) {
115  out << "$" << GetBillingTag().get();
116  }
117  out << "^" << GetFetchOption();
118  return out.str();
119  }
120 
121  private:
122  boost::optional<std::string> billing_tag_;
123  FetchOptions fetch_option_{OnlineIfNotFound};
124 };
125 
126 } // namespace read
127 } // namespace dataservice
128 } // namespace olp
Encapsulates the fields required to request catalog configuration.
Definition: CatalogRequest.h:37
CatalogRequest & WithBillingTag(std::string &&tag)
Sets the billing tag for the request.
Definition: CatalogRequest.h:77
FetchOptions GetFetchOption() const
Gets the fetch option that controls how requests are handled.
Definition: CatalogRequest.h:90
CatalogRequest & WithFetchOption(FetchOptions fetch_option)
Sets the fetch option that you can use to set the source from which data should be fetched.
Definition: CatalogRequest.h:102
const boost::optional< std::string > & GetBillingTag() const
Gets the billing tag to group billing records together.
Definition: CatalogRequest.h:49
CatalogRequest & WithBillingTag(boost::optional< std::string > tag)
Sets the billing tag for the request.
Definition: CatalogRequest.h:62
std::string CreateKey() const
Creates a readable format of the request.
Definition: CatalogRequest.h:112
Rules all the other namespaces.
Definition: AppleSignInProperties.h:24