|
| 1 | +// Copyright 2023 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#include "google/cloud/bigquery/v2/minimal/internal/project_request.h" |
| 16 | +#include "google/cloud/bigquery/v2/minimal/internal/rest_stub_utils.h" |
| 17 | +#include "google/cloud/common_options.h" |
| 18 | +#include "google/cloud/internal/absl_str_cat_quiet.h" |
| 19 | +#include "google/cloud/internal/debug_string.h" |
| 20 | +#include "google/cloud/internal/format_time_point.h" |
| 21 | +#include "google/cloud/internal/make_status.h" |
| 22 | +#include "google/cloud/status.h" |
| 23 | +#include "absl/strings/match.h" |
| 24 | + |
| 25 | +namespace google { |
| 26 | +namespace cloud { |
| 27 | +namespace bigquery_v2_minimal_internal { |
| 28 | +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN |
| 29 | + |
| 30 | +std::string ListProjectsRequest::DebugString(absl::string_view name, |
| 31 | + TracingOptions const& options, |
| 32 | + int indent) const { |
| 33 | + return internal::DebugFormatter(name, options, indent) |
| 34 | + .Field("max_results", max_results_) |
| 35 | + .StringField("page_token", page_token_) |
| 36 | + .Build(); |
| 37 | +} |
| 38 | + |
| 39 | +StatusOr<rest_internal::RestRequest> BuildRestRequest( |
| 40 | + ListProjectsRequest const& r) { |
| 41 | + rest_internal::RestRequest request; |
| 42 | + auto const& opts = internal::CurrentOptions(); |
| 43 | + |
| 44 | + std::string endpoint = GetBaseEndpoint(opts); |
| 45 | + |
| 46 | + std::string path = absl::StrCat(endpoint, "/projects"); |
| 47 | + request.SetPath(std::move(path)); |
| 48 | + |
| 49 | + // Add query params. |
| 50 | + if (r.max_results() > 0) { |
| 51 | + request.AddQueryParameter("maxResults", std::to_string(r.max_results())); |
| 52 | + } |
| 53 | + |
| 54 | + auto if_not_empty_add = [&](char const* key, auto const& v) { |
| 55 | + if (v.empty()) return; |
| 56 | + request.AddQueryParameter(key, v); |
| 57 | + }; |
| 58 | + if_not_empty_add("pageToken", r.page_token()); |
| 59 | + |
| 60 | + return request; |
| 61 | +} |
| 62 | + |
| 63 | +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END |
| 64 | +} // namespace bigquery_v2_minimal_internal |
| 65 | +} // namespace cloud |
| 66 | +} // namespace google |
0 commit comments